Resetting rotation

I’m working on a lunar lander type game, and I want it so that the lander doesn’t rotate based on tilt when you land on the ground, which is flat for the moment. How would you do this?

The user and all related content has been deleted.

I have all the code, @NatTheCoder, it’s just about resetting the rotation. Everything else is there

The user and all related content has been deleted.

@Mr_Ninja - are you saying that you only want the lander to move up/down/left/right in the air, but not tilt at all?

Or do you want the lander to tilt on the way down, but have any tilt disappear when the lander reaches the ground?

Sure

I have its so it tilts, it’s just i want it to stay straight if its on the ground @Ignatz

@Ignatz, sorry, dint understand your question at first; i want it to tilt on the way down, as I have it to do as it is now, but to stop tilting and stay straight once it touches the ground

Here’s the code:


--# Main
-- Lunar lander

-- Use this function to perform your initial setup
function setup()
   displayMode (FULLSCREEN)
    supportedOrientations (LANDSCAPE_ANY)
     lander = Lander()
    game =  Game()
end


function draw()
game:draw()
end

function touched(touch)
lander:touched(touch)
    end
--# Game
Game = class()

function Game:init()
lander = Lander()
    ground = Ground()
    target = Target()
    self.setlandspeed = true
end

function Game:draw()
    
     self.groundloc = ground.y1
 background(0, 0, 0, 255)
    lander:draw()
    ground:draw()
    ground.y1 = ground.y1 + lander.speed.y
    ground.y2 = ground.y2 + lander.speed.y  
    if self.groundloc > 362 then
   self.setlandspeed = false
         lander.stop = true 
        ground.y1 = 361
         ground.y2 = 361
        lander.speed.y = 0
        lander.speed.x = 0
        else
        lander.stop = false
        self.setlandspeed = true
    end
    if self.setlandspeed ==  true then
    self.landspeed = math.ceil (self.groundloc * -1) +361 
        else
        self.landspeed = 0
        end
        
        --test code
    font("CourierNewPS-BoldMT")
    fill(255, 255, 255, 255)
    fontSize (20)
    text ("Altitude " ..(self.landspeed), WIDTH -80, HEIGHT -54)
    text ("Fuel "..math.ceil(lander.fuel), WIDTH -80, HEIGHT -10)
    if lander.speed.y > 3 then
        fill(255, 0, 0, 255)
        else
        fill(38, 255, 0, 255)
    end
    text ("Speed "..math.ceil(lander.speed.y *-1), WIDTH -80, HEIGHT -32)
    --end test
end


function Game:touched(touch)

end

--# Lander
Lander = class()

function Lander:init()
    self.speed = vec2 (0,2)
    self.burn = false
    self.stop = false
    self.tilt = 0
    self.fuel = 750
    self.calx = Gravity.x
    self.locx = WIDTH/2
end

function Lander:draw()
    self.gravx = Gravity.x - self.calx
   if self.burn == true and self.fuel > 0 then
     self.speed.x = self.speed.x + self.gravx
        end
       self.locx = self.locx + self.speed.x
    if self.stop == false then
    self.tilt = self.gravx * -50
        end
     pushMatrix()
    translate (self.locx, HEIGHT/2)
    rotate(self.tilt)
     person = sprite("Documents:Lander", 0, 0)
    popMatrix()

   if self.burn == true then
       if self.fuel > 0 then
            pushMatrix()
            translate (self.locx, HEIGHT/2)
            rotate (self.tilt)
            sprite("Documents:Flame", 0, -15)
            popMatrix()
        self.speed.y = self.speed.y - 0.05 
        self.fuel = self.fuel - 1
            end
        
            else
        if self.stop == false then
          self.speed.y = self.speed.y + 0.05
            else
            self.speed.y = 0
        
    end
    
    end
      
    if self.locx > WIDTH - 10 then
    self.locx = 10
        elseif self.locx < 10 then
        self.locx = WIDTH - 10
end
    end


function Lander:touched(touch)
  if touch.state == BEGAN then
        self.burn = true
        elseif touch.state == ENDED then
        self.burn = false
        else
    end
end

--# Ground
Ground = class()

function Ground:init(x)
self.y1 = 1
    self.y2 = 1
end

function Ground:draw()
stroke(255, 255, 255, 255)
    strokeWidth(10)
    line(0, self.y1, WIDTH, self.y2)
end

function Ground:touched(touch)
    -- Codea does not automatically call this method
end

--# Target
Target = class()

function Target:init()
    self.length = 1
    self.x1 = 0  
    self.x2 = self.x1 + self.length
    self.y1 = 1
    self.y2 = 1
    
end

function Target:draw()
    fill(106, 206, 41, 255)
    lineCapMode (SQUARE)
    strokeWidth (15)
    line (self.x1, self.y1, self.x2, self.y2)
end

function Target:touched(touch)
    -- Codea does not automatically call this method
end

The user and all related content has been deleted.

The user and all related content has been deleted.

Thanks @NatTheCoder

@NatTheCoder - actually, the code doesn’t work!

@firewolf - when I run the code, all I get is a horizontal line that moves up and down.

But assuming self.tilt contains the amount of tilt, just set it equal to 0 when the lander reaches the ground.

It’s not quite done yet, as you can see

Thats because i use my own sprites, sorry

@Mr_Ninja - no need to apologise, I should have thought of that

Thanks @Ignatz, should have seen that earlier. For some reason i was thinking that Rotate() was rotating by self.tilt, not setting the rotation to self.tilt. Thanks