help me with inertia !!!
BlitzMax Forums/BlitzMax Beginners Area/help me with inertia !!!
| ||
Hi ! For my classic vertical shoot'em up, how to add some inertia to... my ship ??? Thanks ! Graphics 800,600 Global Player_x# = GraphicsWidth() / 2 Global Player_y# = GraphicsHeight() / 2 While Not KeyDown(KEY_ESCAPE) If KeyDown(KEY_LEFT) Then Player_x# = Player_x# - 1.0 End If If KeyDown(KEY_RIGHT) Then Player_x# = Player_x# + 1.0 End If If KeyDown(KEY_UP) Then Player_y# = Player_y# - 1.0 End If If KeyDown(KEY_DOWN) Then Player_y# = Player_y# + 1.0 End If Cls ' my ship ;-) DrawOval Player_x#, Player_y#, 10,10 Flip Wend |
| ||
A very basic implementation could be:Type TPlayer Field X:Float Field Y:Float Field X_Speed:Float Field Y_Speed:Float Const Friction:Float = 0.90 Method Draw() DrawOval X, Y, 10,10 EndMethod Method Update() X_Speed:*Friction Y_Speed:*Friction X:+X_Speed Y:+Y_Speed Self.Draw() EndMethod EndType Graphics 800,600 Const Offset:Float = 1.0 Local Player:TPlayer = New TPlayer Player.X = GraphicsWidth() / 2 Player.Y = GraphicsHeight() / 2 While Not KeyDown(KEY_ESCAPE) If KeyDown(KEY_LEFT) Then Player.X_Speed:-Offset End If If KeyDown(KEY_RIGHT) Then Player.X_Speed:+Offset End If If KeyDown(KEY_UP) Then Player.Y_Speed:-Offset End If If KeyDown(KEY_DOWN) Then Player.Y_Speed:+Offset End If Cls ' my ship ;-) Player.Update() Flip Wend |
| ||
Many thanks for your code. How to combine this with acceleration when the ship start to move ? |
| ||
If I understand you correct you can simply "adjust" the acceleration by not using the Constant "Offset", but use different Values (small Values for a slow accel, high Values for a speedy ship) |