I been having a problem with my code were when I try to make the floor move to simulate movement the floor just keeps going even when I am no longer pressing the key.
I think it may have something to do with the type I am using to hold the coordinates for the floor pieces, but I am not sure if that is it.
Well is most of the code.
;Main Progam
While Not KeyDown (KEY_ESCAPE)
;Check_input ()
Updat_floors ()
Cls
Draw_all ()
Flip
Wend
End
;Type and Functions
;Types
;This type holds floor stats
Type FloorT
Field x
Field y
End Type
;This type holds the players stats
Type PlayerT
Field X
Field Y
End Type
;Functions
;Checks player input
Function Check_input ()
If KeyDown (KEY_LEFT) Then
player\x =player\x -5
EndIf
If KeyDown (KEY_RIGHT) Then
player\x =player\x +5
EndIf
If KeyDown (KEY_UP) Then
player\Y =player\y +5
EndIf
If KeyDown (KEY_DOWN) Then
player\Y =player\y -5
EndIf
End Function
Function Check_collision (checkx1,checky1,checkx2,checky2,width1,height1,width2,height2 )
If checkx1 = width2 >= checkx2 - width1 And checkx1 - width2 <= checkx1 + width1 Then
temp = 1
EndIf
If checky1 = height2 >= checky2 - height1 And checky1 - height2 <= checky1 + height1 Then
temp = 1
EndIf
Return temp
End Function
;Draws averything
Function Draw_all ()
Draw_floor ()
Draw_player ()
End Function
;Draws the floor
Function Draw_floor ()
For floors.FloorT = Each FloorT
DrawImage FloorImg,floors\x,floors\y
Next
End Function
;Draws the player on the screen
Function Draw_player ()
DrawImage PlayerImg, 320,240
End Function
;Generates the floor
Function Generate_floor ()
For temp = 0 To 10
floors.FloorT = New FloorT
floors\x = floorgen (0,temp)
floors\y = floorgen (1,temp)
Next
End Function
;this function updats the floor pois to to creat the players movement
Function Updat_floors ()
;transfers the number from the player type temp variables
If KeyDown (KEY_LEFT) Then
player\x =player\x -5
EndIf
If KeyDown (KEY_RIGHT) Then
player\x =player\x +5
EndIf
If KeyDown (KEY_UP) Then
player\Y =player\y +5
EndIf
If KeyDown (KEY_DOWN) Then
player\Y =player\y -5
EndIf
tempx =0
tempy =0
tempx = player\x ;remove?
tempy = player\y
;updats the floors type
For floors.FloorT = Each FloorT
floors\x = floors\x + tempx
floors\y = floors\y + tempy
Next
End Function
If you need to see more of the code just let me know.
Thanks for looking at this, and I hope I was clear. :3
|