game starter

Here’s a game starter for anyone who wants to use it. It’s like lunar lander, but just minimal code. To fire the rockets, slide your finger up the screen. To move right or left, slide your finger towards the right or left. Try to land on the landing pads, but you have to be going really slow or you blow up. If it’s too hard to land, change the -60 in collide() to -75 or -100. I’m not sure what you can do with this, but some new coders might have ideas they want to try.

EDIT:Added comments and corrected an error.


displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)

function setup()
    -- lunar lander
    b=physics.body(CIRCLE,15)
    b.x=WIDTH/2-100
    b.y=HEIGHT-50
    -- landing pads
    e1=physics.body(EDGE,vec2(WIDTH/2-20,200),vec2(WIDTH/2+20,200))
    e1.type=STATIC
    e2=physics.body(EDGE,vec2(150,400),vec2(190,400))
    e2.type=STATIC    
    crashed=false   -- lander crashed
    replay=100  -- crash count to restart
end

function draw()
    background(40, 40, 50)
    -- show lander or explosion
    if crashed then
        sprite("Tyrian Remastered:Explosion Huge",b.x,b.y,replay)
    else
        sprite("Tyrian Remastered:Part H",b.x,b.y)
    end
    if flame then   -- show lander flame
        sprite("Tyrian Remastered:Flame 1",b.x,b.y-20,15,-30)
    end
    -- draw landing pads
    stroke(255)
    strokeWidth(2)
    line(WIDTH/2-20,200,WIDTH/2+20,200)
    line(150,400,190,400)
    -- get lunar velocity
    lv=b.linearVelocity
    -- if lander crashed, countdown to restart
    if crashed then
        replay=replay-2
        if replay<0 then
            restart()
        end
    end
end

function touched(t) -- change landers velocity
    flame=false -- turn flame off
    if t.state==MOVING and not crashed and lv~=nil then
        b.linearVelocity=lv+vec2(t.deltaX,t.deltaY)
        flame=true  -- turn flame on
    end
end

function collide(c) -- check landing velocity
    if c.state==BEGAN then 
        if lv.y<-60 then
            crashed=true    -- landed to fast
        end
    end
end


Way cool. Reminds me of space taxi on the old c64

@MrScience101 I don’t know about space taxi, but I still have a c64. A game I do remember was Beam Rider.