Player Movement help needed

Blitz3D Forums/Blitz3D Beginners Area/Player Movement help needed

GameCoder(Posted 2003) [#1]
Hi. I have been using bb now for about 2 days. Im plodding on ok. I need help with this code. If its a mess im sorry. iv'e only just started. The problem Im having is with player movement. I want the player to be able to move left and right and have a different anim for each direction. this is wot I have come up with so far. Can anyone give any suggestions on a better way to accomplish this.

heres my code.

Graphics 640,480

SetBuffer BackBuffer()

px = 200
py = 200
pspeed = 1
pframe = 0

time = MilliSecs()

;load the player image

p = LoadAnimImage("image1.bmp",32,32,0,3)

While Not KeyHit(1)

Cls



If MilliSecs()> time + 100
time = MilliSecs()

pframe = (pframe + 1) Mod 3


EndIf

If pframe = 2
pframe = 0
End If

If KeyDown(205)

DrawImage p,px,py,pframe

px = px + 1

Else If KeyDown(203)

px = px -1


DrawImage p,px,py,2
pframe = 2 +1
If pframe = 3
pframe = 3
EndIf


Else

DrawImage p,px,py

End If



Flip

Wend

End


Ross C(Posted 2003) [#2]
well firstly create an animation strip with the left and right animation in it. say 3 frames from moving right and 3 frames for moving left.

move left frames: 0-2
move right frames:3-5

then have a direction variable

dir=0; character is moving left

dir=1; character is moving right

then have a variable to keep track of the frames

frame=0


Graphics 800,600 
SetBuffer BackBuffer() 

player=LoadAnimImage("player.png",24,24,0,6) 

dir=0; direction the player is going 
frame=0; what frame of animation the player is on 
speed=1; the walking speed of the player 

While Not KeyHit(1) 
	Cls
	
	If KeyDown(203) Then 
		If dir=3 Then; if player was moving right then change his direction 
			frame=0; set the frame back to zero 
			dir=0; set direction to left 
		Else 
			frame=frame+1 
			If frame=3 Then frame=0;if frame goes past 2 then reset to 0 
			x=x-speed 
		End If 
	ElseIf KeyDown(205) Then 
		If dir=0 Then; if player was moving left then change his direction 
			frame=0; set the frame back to zero 
			dir=3; set direction to right 
		Else 
			frame=frame+1 
			If frame=3 Then frame=0;if frame goes past 2 then reset to 0 
			x=x+speed 
		End If 
	Else 
		If dir=0 Then frame=0 
		If dir=3 Then frame=0 
	End If 
	
	DrawImage player,x,y,dir+frame 
	Delay 200
	
	Flip

Wend
End


the dir variable is used as a marker for which frame is in use and to determine which way the man is player is facing

hope this helps some. there's alot better ppl out there that could prob explain this better but i hope it helps none the less. if u wanna run this mind you need a png image with 6 frames, each at 24x24
:D