starter game 4

Here’s another game starter for anyone who wants it. The object is to collect all the stars, there’s a star count in the upper left. You can stay on the grass, you can’t go thru the rocks, and you fall thru the blank areas. Use the arrows to move the character to collect the stars. You can also use your finger to move the whole area around to find the stars. I didn’t spend a lot of time on this, so if something doesn’t work right, fix it. What else you want to add to this is up to you. I didn’t add any comments, so you’re on your own unless you ask.


displayMode(FULLSCREEN)

function setup()
    fontSize(40)
    stars=0
    nbr=20
    dx,dy=0,0
    tab={}
    for x=-nbr,nbr do
        tab[x]={}
        for y=-nbr,nbr do
            n=math.random(100)
            v=0
            if n>=20 and n<=40 then
                v=1
            end
            if n>=40 and n<=90 then
                v=2
            end
            if n>90 then
                v=3 
                stars=stars+1
            end
            tab[x][y]=v   
        end
    end
    px=4
    py=5
end

function draw()
    background(40, 40, 50)
    for x=-nbr,nbr do
        for y=-nbr,nbr do
            v=tab[x][y]
            if v==1 then
                sprite("Planet Cute:Ramp South",x*101+dx,y*120+dy)
            end
            if v==2 then
                sprite("Planet Cute:Grass Block",x*101+dx,y*120+dy)
            end    
            if v==3 then
                sprite("Planet Cute:Star",x*101+dx,y*120+dy)
            end            
        end
    end
    sprite("Platformer Art:Guy Standing",px*101+dx,py*120+dy)
    if tab[px][py]==0 and (tab[px][py-1]==0 or tab[px][py-1]==3) then
        py=py-1
    end
    if tab[px][py]==3 then
        tab[px][py]=0
        stars=stars-1
    end
    sprite("Cargo Bot:Command Left",50,HEIGHT/2)
    sprite("Cargo Bot:Command Right",WIDTH-50,HEIGHT/2)
    sprite("Cargo Bot:Command Grab",WIDTH/2,50)
    sprite("Cargo Bot:Command Grab",WIDTH/2,HEIGHT-50,-50)
    fill(255,0,0)
    text(stars,100,HEIGHT-50)
end

function touched(t)
    if t.state==BEGAN and t.x<100 then
        if px-1>=-nbr and tab[px-1][py]~=1 then
            px=px-1
        end
        return
    end
    if t.state==BEGAN and t.x>WIDTH-100 then
        if px+1<=nbr and tab[px+1][py]~=1 then
            px=px+1
        end
        return
    end
    if t.state==BEGAN and t.y<100 then
        if py-1>=-nbr and tab[px][py-1]~=1 then
            py=py-1
        end
        return
    end
    if t.state==BEGAN and t.y>HEIGHT-100 then
        if py+1<=nbr and tab[px][py+1]~=1 then
            py=py+1
        end
        return
    end
    if t.state==MOVING then
        dx=dx+t.deltaX
        dy=dy+t.deltaY
    end
end

@dave1707 - be sure to link it somewhere, eg the wiki, so it doesn’t get lost,

The user and all related content has been deleted.

@NatTheCoder This code is for anyone who wants it, so you are free to use it however you want. The whole purpose of the starter games I post is to give new coders a head start on some game ideas. Do a search for “starter game” to see other examples.

nice one @dave1707