Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

starter game 19

dave1707dave1707 Mod
in Code Sharing Posts: 10,053

Here's another starter game for anyone who wants to expand on it. The object is to reach the 26th level by moving the player to one of the portals. To move the player, tap the left, right, top, or bottom of the screen. Once the player reaches a portal, he'll be moved to a level that was assigned to that portal. There is only one portal that will take you to the next level, the other portals will leave you at the current level or take you to a previous levels. Levels are randomly assigned to each portal when the game starts, so each game is different. There's a parameter you can change that will show you the current level on the output pane, but that's the only hint you get. You'll have to keep track of which portal by level that takes you to the next level. Is your memory good enough, or will you use a pencil and paper. There's no scoring or time limit, you can add that if you want. You can also change the sprites I use or add other ones to complicate things more. This is just a starter game, so things are simple, it's up to you to add everything else.

displayMode(FULLSCREEN)

function setup()
    fontSize(50)
    fill(255)
    parameter.boolean("showLevel",false)
    rectMode(CENTER)
    xSize,ySize=10,14
    if WIDTH>HEIGHT then
        xSize,ySize=14,10
    end
    maxLevel=25
    portals=15
    level=1
    tx,ty=0,0
    player=vec2(1,1)
    dir=vec2(0,0)
    tab={}
    for z=1,maxLevel do
        tab[z]={}
        for x=1,xSize do
            tab[z][x]={}
            for y=1,ySize do
                tab[z][x][y]=vec2(0,0)
            end
        end  
        cnt=0
        while cnt<portals do
            xx=math.random(2,xSize-1)
            yy=math.random(2,ySize-1)
            if tab[z][xx][yy].x==0 then
                cnt=cnt+1
                if cnt==7 then
                    tab[z][xx][yy]=vec2(1,z+1)   
                else
                    tab[z][xx][yy]=vec2(1,math.random(z)) 
                end  
            end
        end
    end
end

function draw()
    background(40, 40, 50)
    if gameOver then
        sprite("Platformer Art:Coin",WIDTH/2,HEIGHT/2+200,200)
        text("You won!",WIDTH/2,HEIGHT/2-200)
        return
    end
    for x=1,xSize do
        for y=1,ySize do 
            if tab[level][x][y].x==1 then
                sprite("Platformer Art:Block Special",x*70,y*70)  
            else
                sprite("Platformer Art:Block Brick",x*70,y*70) 
            end         
        end
    end
    sprite("Platformer Art:Guy Standing",player.x*70,player.y*70,40)
end

function touched(t)
    if t.state==BEGAN then
        if gameOver then
            if t.tapCount==2 then
                restart()
            end
            return
        end
        dir=vec2(0,0)
        if t.x<100 then
            dir=vec2(-1,0)
        elseif t.x>WIDTH-100 then
            dir=vec2(1,0)
        elseif t.y<100 then
            dir=vec2(0,-1)
        elseif t.y>HEIGHT-100 then
            dir=vec2(0,1) 
        end
        temp=player+dir
        if temp.x>=1 and temp.x<=xSize and temp.y>=1 and temp.y<=ySize then
            player=temp     
            if tab[level][player.x][player.y].x==1 then
                level=tab[level][player.x][player.y].y
                if level>maxLevel then
                    gameOver=true
                end
            end
        end
        output.clear()
        if showLevel then
            print("Current level "..level)
        end
    end
end
Sign In or Register to comment.