Moving square at a specified angle

BlitzMax Forums/BlitzMax Beginners Area/Moving square at a specified angle

767pilot(Posted 2008) [#1]
If I draw a square

eg DrawRect(0,0,100,100)

and I want to move this square at a certain angle ie 120 degrees until it hits the edge of the screen how would I do it please?


EOF(Posted 2008) [#2]
Quick example here

SuperStrict
Framework BRL.GLMax2D

' Setup & initialise variables
Const SW% = 640, SH% = 400
              
' display settings
AppTitle="Move at angle"
SetGraphicsDriver GLMax2DDriver()
Graphics sw,sh,0,40


Global ang#=120.0
Global speed#=1.5

Global x#=20,y#=30

While Not KeyHit(KEY_ESCAPE)
	Cls
	DrawText "Angle="+String(ang),10,10
	x:+Sin(ang)*speed ; y:-Cos(ang)*speed
	DrawRect x,y,20,20
	Flip
Wend


The angle directions (in degrees) are as follows:




767pilot(Posted 2008) [#3]
Excellent, thankyou!


MGE(Posted 2008) [#4]
Or you can do this which will match up to blitzmax's rotation value:

x:+Cos(ang)*speed ; y:+Sin(ang)*speed