Works fine here.
I've just added a fuel guage that changes colour as you get lower on fuel, and when it's out, that's it. No more thrusting for you!
I've also added a blue button on the screen that you can click to randomise the terrain, reposition the lander and refill the fuel tank.
SetVirtualResolution(480, 640)
AddVirtualJoystick (1, 85, 560, 150)
// new code by Bursar
AddVirtualButton(1, 400, 560, 50)
SetVirtualButtonColor(1, 32, 32, 255)
//
for star = 1 to 100
starSize = Random(1,3)
tempSpr = CreateSprite(0)
SetSpriteSize(tempSpr, starSize, starSize)
SetSpritePosition(tempSpr, Random(0, 480), Random(0, 480))
SetSpriteDepth(tempSpr, 15)
next star
groundSpr = CreateSprite(0)
SetSpriteColor(groundSpr, 155, 155, 155, 255)
SetSpriteSize(groundSpr, 480, 250)
SetSpritePosition(groundSpr, 0, 480)
SetSpriteShape(groundSpr, 2)
SetSpritePhysicsOn(groundSpr, 1)
SetSpritePhysicsMass(groundSpr, 100000)
hillSpr1 = CreateSprite(0)
SetSpriteColor(hillSpr1, 125, 125, 125, 255)
SetSpriteSize(hillSpr1, 320, 240)
SetSpritePosition(hillSpr1, 260, 400 + Random(0, 50))
SetSpriteDepth(hillSpr1, 12)
SetSpriteAngle(hillSpr1, 35.0 + Random(0, 20.0))
SetSpriteShape(hillSpr1, 2)
SetSpritePhysicsOn(hillSpr1, 1)
hillSpr2 = CreateSprite(0)
SetSpriteColor(hillSpr2, 125, 125, 125, 255)
SetSpriteSize(hillSpr2, 320, 240)
SetSpritePosition(hillSpr2, -180, 400 + Random(0, 50))
SetSpriteDepth(hillSpr2, 12)
SetSpriteAngle(hillSpr2, -35.0 + Random(0, 20.0))
SetSpriteShape(hillSpr2, 2)
SetSpritePhysicsOn(hillSpr2, 1)
landerSpr = CreateSprite(0)
SetSpriteSize(landerSpr, 32, 32)
SetSpriteOffset(landerSpr, GetSpriteWidth(landerSpr)/2, GetSpriteHeight(landerSpr)/2)
SetSpritePosition(landerSpr, 320, 0)
SetSpriteShape(landerSpr, 2)
SetSpritePhysicsOn(landerSpr, 2)
SetSpritePhysicsCanRotate(landerSpr, 0)
SetSpritePhysicsRestitution(landerSpr, 0.5)
leftLeg = CloneSprite(landerSpr)
SetSpriteSize(leftLeg, 18, 8)
SetSpritePosition(leftLeg, 308, 32)
SetSpriteShape(leftLeg, 2)
SetSpritePhysicsOn(leftLeg, 2)
SetSpritePhysicsCanRotate(leftLeg, 0)
SetSpritePhysicsRestitution(leftLeg, 0.5)
leftJoint = CreateRevoluteJoint(landerSpr, leftLeg, 0, 0, 0)
rightLeg = CloneSprite(leftLeg)
SetSpritePosition(rightLeg, 346, 32)
SetSpriteShape(rightLeg, 2)
SetSpritePhysicsOn(rightLeg, 2)
SetSpritePhysicsCanRotate(rightLeg, 0)
SetSpritePhysicsRestitution(rightLeg, 0.5)
rightJoint = CreateRevoluteJoint(landerSpr, rightLeg, 0, 0, 0)
SetSpritePhysicsMass(landerSpr, 40.0)
SetSpritePositionByOffset(landerSpr, 223.0, 0.0)
SetTextDefaultFontImage(LoadImage("Arial.png"))
altitudeTxt = CreateText("")
altitudeShadowTxt = CreateText("")
SetTextSize(altitudeTxt, 30)
SetTextSize(altitudeShadowTxt, 30)
SetTextPosition(altitudeTxt, 180, 530)
SetTextPosition(altitudeShadowTxt, 182, 532)
SetTextDepth(altitudeTxt, 0)
SetTextDepth(altitudeShadowTxt, 1)
SetTextColor(altitudeTxt, 255, 255, 255, 255)
SetTextColor(altitudeShadowTxt, 0, 0, 0, 255)
forceAdded = 5000.0
// Additions By Bursar //
maxFuel = 200
currentFuel = maxFuel
fuelOutLineBox = CreateSprite(0)
SetSpriteSize(fuelOutLineBox, 204, 27)
SetSpriteDepth(fuelOutLineBox, 100)
SetSpritePositionByOffset (fuelOutLineBox, (GetDeviceWidth()/2), (GetSpriteWidth(fuelOutLineBox)/6))
fuelGuage = CreateSprite(0)
SetSpriteSize(fuelGuage, currentFuel*2, 25)
SetSpriteDepth(fuelGuage, 99)
SetSpriteColor(fuelGuage, 0, 255, 0, 255)
SetSpritePositionByOffset (fuelGuage, (GetDeviceWidth()/2), (GetSpriteWidth(fuelOutLineBox)/6))
do
x# = GetVirtualJoystickX(1)
y# = GetVirtualJoystickY(1)
SetTextString(altitudeTxt, "Altitude: " + (str(abs(GetSpriteYByOffset(landerSpr) - 455.9), 1)))
SetTextString(altitudeShadowTxt, "Altitude: " + (str(abs(GetSpriteYByOffset(landerSpr) - 455.9), 1)))
if GetParticlesExists(jetPrt)
SetParticlesPosition(jetPrt, GetSpriteXByOffset(landerSpr), GetSpriteYByOffset(landerSpr) + 16)
endif
if GetParticlesExists(rightJetPrt)
SetParticlesPosition(rightJetPrt, GetSpriteXByOffset(landerSpr) + 16, GetSpriteYByOffset(landerSpr))
endif
if GetParticlesExists(leftJetPrt)
SetParticlesPosition(leftJetPrt, GetSpriteXByOffset(landerSpr) - 16, GetSpriteYByOffset(landerSpr))
endif
if x# < -0.3
If currentFuel > 0
SetSpritePhysicsForce(landerSpr, GetSpriteXByOffset(landerSpr), GetSpriteYByOffset(landerSpr), -1.0 * forceAdded, 0)
// new code by Bursar
currentFuel=currentFuel - 1
//
if rightJetFlag = 0 and currentFuel > 0
rightJetPrt = CreateParticles(GetSpriteXByOffset(landerSpr) + 16, GetSpriteYByOffset(landerSpr))
SetParticlesSize(rightJetPrt, 6)
SetParticlesAngle(rightJetPrt, 25.0)
SetParticlesDirection(rightJetPrt, 100.0, 0)
SetParticlesFrequency(rightJetPrt, 60.0)
SetParticlesLife(rightJetPrt, 0.2)
SetParticlesDepth(rightJetPrt, 11)
AddParticlesColorKeyFrame(rightJetPrt, 0.0, 255, 255, 255, 155)
AddParticlesColorKeyFrame(rightJetPrt, 0.2, 255, 255, 255, 0)
SetParticlesColorInterpolation(rightJetPrt, 1)
rightJetFlag = 1
endif
EndIf
else
DeleteParticles(rightJetPrt)
rightJetFlag = 0
endif
if x# > 0.3
If currentFuel > 0
SetSpritePhysicsForce(landerSpr, GetSpriteXByOffset(landerSpr), GetSpriteYByOffset(landerSpr), forceAdded, 0)
// new code by Bursar
currentFuel=currentFuel - 1
//
if leftJetFlag = 0
leftJetPrt = CreateParticles(GetSpriteXByOffset(landerSpr) - 16, GetSpriteYByOffset(landerSpr))
SetParticlesSize(leftJetPrt, 6)
SetParticlesAngle(leftJetPrt, 25.0)
SetParticlesDirection(leftJetPrt, -100.0, 0)
SetParticlesFrequency(leftJetPrt, 60.0)
SetParticlesLife(leftJetPrt, 0.2)
SetParticlesDepth(leftJetPrt, 11)
AddParticlesColorKeyFrame(leftJetPrt, 0.0, 255, 255, 255, 155)
AddParticlesColorKeyFrame(leftJetPrt, 0.2, 255, 255, 255, 0)
SetParticlesColorInterpolation(leftJetPrt, 1)
leftJetFlag = 1
endif
EndIf
else
DeleteParticles(leftJetPrt)
leftJetFlag = 0
endif
if y# < -0.3
If currentFuel > 0
SetSpritePhysicsForce(landerSpr, GetSpriteXByOffset(landerSpr), GetSpriteYByOffset(landerSpr), 0, -1.0 * forceAdded)
// new code by Bursar
currentFuel=currentFuel - 1
//
if jetFlag = 0
jetPrt = CreateParticles(GetSpriteXByOffset(landerSpr), GetSpriteYByOffset(landerSpr) + 18)
SetParticlesSize(jetPrt, 6)
SetParticlesAngle(jetPrt, 25.0)
SetParticlesDirection(jetPrt, 0.0, 100.0)
SetParticlesFrequency(jetPrt, 160.0)
SetParticlesLife(jetPrt, 0.5)
SetParticlesDepth(jetPrt, 11)
AddParticlesColorKeyFrame(jetPrt, 0.0, 255, 0, 0, 255)
AddParticlesColorKeyFrame(jetPrt, 0.3, 255, 255, 0, 50)
AddParticlesColorKeyFrame(jetPrt, 0.5, 255, 255, 0, 0)
SetParticlesColorInterpolation(jetPrt, 1)
jetFlag = 1
endif
EndIf
else
DeleteParticles(jetPrt)
jetFlag = 0
endif
// new code by Bursar
If GetVirtualButtonPressed(1) = 1
SetSpritePosition(hillSpr1, 260, 400 + Random(0, 50))
SetSpriteAngle(hillSpr1, 35.0 + Random(0, 20.0))
SetSpritePosition(hillSpr2, -180, 400 + Random(0, 50))
SetSpriteAngle(hillSpr2, -35.0 + Random(0, 20.0))
SetSpritePositionByOffset(landerSpr, GetDeviceWidth()/2, 0)
currentFuel = maxFuel
SetSpriteColor(fuelGuage, 0, 255, 0, 255)
EndIf
SetSpriteSize(fuelGuage, currentFuel, 25)
SetSpritePosition(fuelGuage, 140, 21.5)
If currentFuel <= maxFuel/2 Then SetSpriteColor(fuelGuage, 255, 106, 0, 255)
If currentFuel <= maxFuel/4 Then SetSpriteColor(fuelGuage, 255, 0, 0, 255)
//
Sync()
loop
It's not perfect, as if you're thrusting when you run out of fuel, then the particles are still created. Also, the code could be split up into functions to make it more reusable, but it was a 5 minute hack job when the boss wasn't looking