TGC Codebase Backup



Moving a 2D object by converting an angle to X & Y step values by OSX Using Happy Dude

9th May 2004 9:56
Summary

Given an angle, this routine converts a 360degree angle into the relevant X & Y step values.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    load image "C:\Documents and Settings\Nicholas Kingsley\My Documents\My Pictures\craft.bmp",1,1

`Main Source File
angle#=0
x#=100.0
y#=100.0
do
	text 0,0,str$(angle#)
	sprite 1,x#,y#,1:offset sprite 1,sprite width(1)/2,sprite height(1)/2
	rotate sprite 1,angle#
	
	if leftkey()
		angle#=wrapvalue(angle#-1.0)
	else
		if rightkey()
			angle#=wrapvalue(angle#+1.0)
		endif
	endif
	
	if spacekey()
		a#=wrapvalue((360.0-angle#)+180.0)
		inc x#,sin(a#)*1.0
		inc y#,cos(a#)*1.0
	endif	
	sync
loop