Hi guys, Im trying to make a game where there is a little space ship that has boosters and when the boosters are on, it flies up, but when you stop boosting it starts to slow down and eventually starts falling...
But the gravity is very linear... and messing with the scale of the physics just makes the ship unable to break the gravity barrier...
// Project: 2D fly the triangle
// Created: 2018-02-13
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "2D fly the triangle" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
CreateSprite ( LoadImage ( "space1.jpg" ) )
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//Accelerometer gravity
spr = CreateSprite ( LoadImage ( "spaceship2.png" ) )
SetSpriteSize (spr,80,80)
SetPhysicsGravity(0 ,100 )
SetPhysicsScale (.01)
SetSpritePosition (spr,160,200)
SetJoystickScreenPosition ( 50, 300, 64 )
SetSpritePhysicsOn(spr,2)
SetSpriteDepth(spr,0)
SetSpritePhysicsCanRotate (spr,0)
SetSpritePhysicsMass (spr,60)
setspritephysicsisbullet(spr,1)
SetSpritePhysicsFriction(spr,0.1)
SetSpritePhysicsRestitution(spr,0.25)
SetSpritePhysicsDamping(spr,0.25)
do
Print ( "Flippityflop" )
x# = GetJoystickX ( )
y# = GetJoystickY ( )
Print ( x# )
Print ( y# )
SetSpritePosition ( spr, GetSpriteX ( spr ) + x#, GetSpriteY ( spr ) + y# )
if ( GetSpriteX ( spr ) < 30 )
SetSpriteX ( spr, 30 )
endif
if ( GetSpriteX ( spr ) > 768 )
SetSpriteX ( spr, 768 )
endif
if ( GetSpriteY ( spr ) < 30 )
SetSpriteY ( spr, 30 )
endif
if ( GetSpriteY ( spr ) > 1024 )
SetSpriteY ( spr, 1024 )
endif
Sync()
loop