Asteroids type movement
Blitz3D Forums/Blitz3D Programming/Asteroids type movement
| ||
Hey guys, I think I've coded this like 5 times now and I forget every single time. How to I code asteroids style ship movement? The vehicle need to drift after I let up on the directions keys. |
| ||
Iv'e seen stuff like this before, but have never actually coded it. How about like (psuedocode)while loop is going on If the space key is hit then speed=5 end if rotate ship, speed if speed is 0, skip this next part. speed=speed-1 End if hopefully you got that? |
| ||
Like this?Graphics3D 800, 600, 0, 2 SetBuffer BackBuffer() Type tPlayer Field entity$ Field speed# End Type Global Player.tPlayer = New tPlayer Player\entity = CreateCone() Player\speed = 0 RotateEntity Player\entity, 90, 0, 0 Global Cam = CreateCamera() MoveEntity Cam, 0, 30, 0 RotateEntity Cam, 90, 0, 0 While Not KeyHit(1) If KeyDown(200) Player\speed = Player\speed + .01 ;Acceleration Else Player\speed = Player\speed - .006 ;When it's not pressed, drain the speed EndIf ;Limit the max and min speed If Player\speed < 0 Then Player\speed = 0 If Player\speed > 1 Then Player\speed = 1 ;Turning If KeyDown(203) Then TurnEntity Player\entity, 0, 3, 0, 1 If KeyDown(205) Then TurnEntity Player\entity, 0, -3, 0, 1 ;Move the ship with speed variable MoveEntity Player\entity, 0, Player\speed, 0 UpdateWorld RenderWorld Flip Wend EndGraphics End |
| ||
Graphics3D 640,480,16,1 Const Upkey = 200 Const DownKey = 208 Const LeftKey = 203 Const Rightkey = 205 Global Camera = CreateCamera() PositionEntity Camera,0,0,-150 Type Player Field Model Field SpeedX# Field SpeedY# Field TurnSpeed# Field TurnDrag# Field TurnAcceleration# Field MoveDrag# Field MoveAcceleration# Field MoveDeceleration# End Type Global ME.player = PLAYERcreate() ;main program While Not KeyDown(1) PLAYERmove( ME ) RenderWorld() Flip Wend ;=============================================== ;=============================================== ;=============================================== Function PLAYERcreate.Player() p.player = New Player p\SpeedX# = 0 p\SpeedY# = 0 p\TurnSpeed# = 0 p\TurnAcceleration# = 0.03 p\TurnDrag# = .99 p\MoveAcceleration# = 0.05 p\MoveDeceleration# = 0.05 p\MoveDrag = .99 ;MaxSpeed = .03 / ( 1.0 -.99 ) = 3 ;MaxTurnSpeed = .05 / ( 1.0 - .99 ) = 5 p\Model = CreateCone() ScaleEntity p\Model, 10, 10,10 Return p End Function ;=============================================== ;=============================================== ;=============================================== Function PLAYERmove( p.Player ) ;turning Turn# = KeyDown (LeftKey) - KeyDown(RightKey) p\TurnSpeed# = p\TurnSpeed# *p\TurnDrag + Turn * p\TurnAcceleration TurnEntity p\Model , 0,0, p\TurnSpeed ;moving Direction# = KeyDown(UpKey) - KeyDown(DownKey) TFormNormal 0,1,0, p\Model, 0 Thrust# = ( Direction = 1 ) * p\MoveAcceleration - ( Direction = -1 ) * p\MoveDeceleration p\SpeedX = p\SpeedX * p\MoveDrag + Thrust * TFormedX() p\SpeedY = p\SpeedY * p\MoveDrag + Thrust * TFormedY() TranslateEntity p\Model, p\SpeedX , p\SpeedY , 0 End Function |
| ||
YAY now I don't have to give real code :) |