im using this code for my asteroids,
but my asteroids dont go in straight lines they curve about the screen making it impossible to avoid them.
EDIT - I just realized its because I am rotating the asteroids, but I dont get why their rotation affects their direction, when they are 2 seperate attributes.
Type rock Global bigrock:timage=LoadImage("incbin::bigrock.png") Global smallrock:timage=LoadImage("incbin::medrock.png") Global medrock:timage=LoadImage("incbin::smallrock.png") Field rotation,x#,y#,health,direction,image:timage,speed Field xspeed#,yspeed# Global list:TList Function Create() Local r:rock r:rock=New rock r.x=Rand(1,640) r.y=Rand(1,480) r.health=Rand(1,30) r.rotation=Rand(1,360) r.direction=Rand(1,360) r.speed=Rand(1,3) r.image=bigrock r.xspeed:+ Cos(r.direction)*r.speed r.yspeed:+ Sin(r.direction)*r.speed ListAddLast(rock.list,r) End Function Function update_all() Local r:rock For r:rock=EachIn rock.list r.update Next End Function Method update() Self.x=Self.x+Self.xspeed Self.y=Self.y+Self.yspeed SetRotation Self.rotation If Self.x < 0 Self.x = GraphicsWidth() EndIf If Self.x > GraphicsWidth() Self.x = 0 EndIf If Self.y < 0 Self.y = GraphicsHeight() EndIf If Self.y > GraphicsHeight() Self.y = 0 EndIf Self.rotation=Self.rotation+1 SetBlend(alphablend) DrawImage Self.image,Self.x,Self.y DrawText Self.direction,Self.x,Self.y End Method End Type
but my asteroids dont go in straight lines they curve about the screen making it impossible to avoid them.
EDIT - I just realized its because I am rotating the asteroids, but I dont get why their rotation affects their direction, when they are 2 seperate attributes.