360 degree movement?

BlitzPlus Forums/BlitzPlus Programming/360 degree movement?

elseano(Posted 2004) [#1]
Ok, I understand simple movement in BlitzPlus, that is up down left right, but how would I make a game in whiich the character can go in 360 directions. I know it's something to do with sin cos and tan, but how do I impliment this? Sorry the questions so vague but I son't really know how to put it :/


CS_TBL(Posted 2004) [#2]
Don't mind the fact that it looks ugly :) it's well beyond bedtime already.. *yawn* .. but this should be all the info you need:

use 4 vars:

playerX#
playerY#
playerSpeed#
playerAngle

the rest is obvious..

~enjoy~

app=CreateWindow("",8,8,640,480,0,0)
canvas=CreateCanvas(0,0,640,480,app)

Global arrow=CreateImage(32,32),arrowtemp=CreateImage(32,32)
MidHandle arrow

SetBuffer ImageBuffer(arrow)
	Line 0,31,16,0
	Line 17,0,31,31
	Line 0,31,31,31
	Line 2,27,29,27


SetBuffer CanvasBuffer(canvas)

timer=CreateTimer(40)

Global playerX#=320,playerY#=240
Global playerSpeed#=1,playerAngle=0


Repeat
	WaitEvent()
	If EventID()=$803 quit=True

	If EventID()=$4001
		Controls()
	EndIf
	
	Text 0,0,"alt F4 = quit"

	FlipCanvas canvas:Cls
	
Until quit
End

Function Controls()

	If KeyDown(200) ; up
		playerSpeed#=playerSpeed#+.1
		If playerSpeed#>4 playerSpeed#=4
	EndIf
	
	If KeyDown(208) ; down
		playerSpeed#=playerSpeed#-.1
		If playerSpeed#<0 playerSpeed#=0
	EndIf
	
	If KeyDown(203) ; L
		PlayerAngle=(PlayerAngle+350) Mod 360
	EndIf
	
	If KeyDown(205) ; R
		PlayerAngle=(PlayerAngle+10) Mod 360
	EndIf
	
	UpdatePlayer()
	DrawPlayer()
	
End Function

Function DrawPlayer()

	Plot playerX#,playerY#

	arrowtemp=CopyImage(arrow)
	
	RotateImage arrowtemp,playerAngle
	DrawImage arrowtemp,playerX#,playerY#

End Function

Function UpdatePlayer()

	playerX#=playerX#+Sin(playerAngle)*playerSpeed#
	playerY#=playerY#-Cos(playerAngle)*playerSpeed#

End Function



elseano(Posted 2004) [#3]
Ok thanks. I'm actually using blitz3d, so I don't know about all this "CreateWindow(..)" stuff...


Wiebo(Posted 2004) [#4]
Then why did you post this in the blitzplus forum?


CS_TBL(Posted 2004) [#5]
Well, the formula are the same for blitz2d/3d .. the only thing you need to change are the canvasbuffers etc.