starter game 5

Here’s another starter game. The idea for this one was because of @JakAttak and his Ladder Man. That reminded me of a game I played on my Apple II probably 30+ years ago. That was Lode Runner. This starter game just has one level, but more levels can be easily added. I didn’t spend a lot of time on this, so it doesn’t do a lot of what the original game does. The object is to move the player to collect the gold while avoiding the flys. Once all the gold is collected, the last ladder to the next level will appear. Once you reach the top of that ladder, the current level is complete. If you want more levels, it’s up to you to add the code. You can keep playing the level I have since the flys move in random directions. To move the player, just swipe in the direction you want him to move.

EDIT: Original code changed. The code now has 3 levels and more levels can be added.


displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
rectMode(CENTER)

function setup()
    offset=60
    lastLevel=1
    
    floor={}    -- start x, end x, y position (y position can’t be 30)
    floor[1]={vec3(2,16,4),vec3(6,15,9),vec3(8,20,14),vec3(2,10,19),vec3(5,20,24),vec3(10,24,29)}
    floor[2]={vec3(2,16,4),vec3(8,20,14),vec3(2,10,19),vec3(10,24,29)}
    floor[3]={vec3(8,24,1),vec3(3,6,4),vec3(8,12,14),vec3(14,23,14),vec3(2,10,19),vec3(10,24,29)}
    
    -- last ladder position is hidden until all gold is taken
    -- last ladder position must end at 30
    ladder={}   -- x position, start y, end y
    ladder[1]={vec3(3,4,19),vec3(8,4,14),vec3(10,14,19),vec3(15,4,14),
        vec3(20,14,24),vec3(12,24,29),vec3(5,24,30)}
    ladder[2]={vec3(3,4,19),vec3(8,4,14),vec3(10,14,19),vec3(15,4,14),
        vec3(20,14,29),vec3(6,19,30)}   
    ladder[3]={vec3(3,4,19),vec3(8,1,14),vec3(10,14,19),vec3(15,1,14),
        vec3(20,14,29),vec3(6,19,30)}        

    gold={}    -- x,y position, 1=gold not taken yet
    gold[1]={vec3(8,19,1),vec3(16,14,1),vec3(23,29,1),vec3(16,4,1)}
    gold[2]={vec3(2,19,1),vec3(16,14,1),vec3(23,29,1),vec3(16,4,1)}
    gold[3]={vec3(24,1,1),vec3(16,14,1),vec3(23,29,1),vec3(2,19,1)}
    
    -- player start position by level
    pl={{6,4},{6,4},{6,4}}
    -- flys start position by level
    fl1={{20,24},{20,24},{20,24}}
    fl2={{10,19},{10,19},{10,19}}
        
    w=24    -- width, height of play area
    h=30
    setup1()
end

function setup1()
    gameOver=false
    nextLevel=false
    
    level=lastLevel
    
    -- player
    player=movers("player","Platformer Art:Guy Standing")
    -- flys
    fly1=movers("fly1","Platformer Art:Battor Flap 1")
    fly2=movers("fly2","Platformer Art:Battor Flap 1")
    
    -- player
    player.x=pl[level][1]
    player.y=pl[level][2]
    -- flys
    fly1.x=fl1[level][1]
    fly1.y=fl1[level][2]
    fly2.x=fl2[level][1]
    fly2.y=fl2[level][2]
    
    size=#ladder[level]-1  -- dont show last position yet
    
    for z=1,#gold[level] do -- reset gold for current level
        gold[level][z].z=1
    end
end

function draw()
    background(93, 129, 150, 255)
    -- draw floor, ladder, gold
    for x=1,w do
        for y=1,h do
            v=0
            fill(92, 70, 31, 255)
            for z=1,#floor[level] do
                if x>=floor[level][z].x and x<=floor[level][z].y and 
                        y==floor[level][z].z then
                    rect(x*40,y*20+offset,40,20)
                end
            end
            fill(255)
            for z=1,size do
                if x==ladder[level][z].x and y>=ladder[level][z].y and
                        y<=ladder[level][z].z then
                    rect(x*40,y*20+offset,40,4)
                end
            end
            for z=1,#gold[level] do
                if x==gold[level][z].x and y==gold[level][z].y then
                    if gold[level][z].z==1 then
                        sprite("Platformer Art:Coin",x*40,y*20+30+offset,20)
                    end
                end
            end
        end
    end
    -- draw player and flys
    player:draw()
    fly1:draw()
    fly2:draw()
    if not nextLevel and not gameOver then
        player:move()
        fly1:move()
        fly1:rand()
        fly2:move()
        fly2:rand()
    end
    -- player and one of the flys overlap
    if player.x==fly1.x and player.y==fly1.y or 
            player.x==fly2.x and player.y==fly2.y then
        gameOver=true
    end
    if gameOver then
        text("Game Over, double tap screen to restart",800,HEIGHT-50)
    end
    -- player reached top of next level ladder
    if player.y==30 then
        nextLevel=true
    end
    if nextLevel then
        text("Double tap screen for next level",800,HEIGHT-50)
    end
    text("LEVEL  "..level,400,HEIGHT-50)
    text("Swipe up / down / left / right to move player",WIDTH/2,40)
end

function touched(t)
    player:touched(t)
    if t.state==BEGAN and t.tapCount==2 then
        if gameOver then
            setup1()
        end
        if nextLevel then
            lastLevel=lastLevel+1  
            setup1()
        end
    end
end

movers = class()

function movers:init(t,sp)
    self.x=0
    self.y=0
    self.dx=0
    self.dy=0
    self.info=t
    self.count=0
    self.rCount=200
    self.sp=sp
    self.dir=0
end

function movers:draw()
    sprite(self.sp,self.x*40,self.y*20+30+offset,30)
end

function movers:move()
    -- move player and flys every 1/3 secons
    if self.count>20 then
        self.x=self.x+self.dx
        self.y=self.y+self.dy
        self.count=0
    end
    self.count=self.count+1
    
    -- check if player overlaps gold
    gCount=0
    for z=1,#gold[level] do
        if self.info=="player" and self.x==gold[level][z].x and self.y==gold[level][z].y then
            gold[level][z].z=0
        end
        gCount=gCount+gold[level][z].z
    end
    if gCount==0 then   -- all gold taken, show last ladder
        size=#ladder[level]
    end
    -- keep movers within bounds of floor and ladder
    bounds=0
    for z=1,#floor[level] do
        if self.x>floor[level][z].x and self.x<floor[level][z].y and self.y==floor[level][z].z then
            bounds=1
        end
    end
    for z=1,size do
        if self.x==ladder[level][z].x and self.y>ladder[level][z].y and self.y<ladder[level][z].z then
            bounds=1
        end
    end
    if bounds==0 then
        self.dx=0
        self.dy=0
    end
    
    -- move player and flys based on direction
    if self.dir==1 then -- move up
        for z=1,size do
            if self.x==ladder[level][z].x and 
                    self.y>=ladder[level][z].y and self.y<ladder[level][z].z then
                self.dx=0
                self.dy=1
                break
            else
                self.dy=0
            end        
        end
    end
    if self.dir==2 then -- move right
        for z=1,#floor[level] do
            if self.x>=floor[level][z].x and self.x<floor[level][z].y and 
                    self.y==floor[level][z].z then
                self.dx=1
                self.dy=0
                break
            else
                self.dx=0
            end
        end
    end
    if self.dir==3 then -- move down
        for z=1,size do
            if self.x==ladder[level][z].x and 
                    self.y>ladder[level][z].y and self.y<=ladder[level][z].z then
                self.dx=0
                self.dy=-1
                break
            else
                self.dy=0
            end
        end
    end
    if self.dir==4 then -- move left
        for z=1,#floor[level] do
            if self.x>floor[level][z].x and self.x<=floor[level][z].y and 
                    self.y==floor[level][z].z then
                self.dx=-1
                self.dy=0
                break
            else
                self.dx=0
            end
        end
    end
end

function movers:rand()
    -- random direction of flys
    self.rCount=self.rCount+1
    if self.rCount>60 then
        self.dir=math.random(1,4)
        self.rCount=0
    end
end

function movers:touched(t)
    -- check direction of swipe
    if t.state==MOVING then
        dx1=t.deltaX
        dy1=t.deltaY
        if math.abs(dx1)>math.abs(dy1) then
            self.dir=2
            if dx1<0 then
                self.dir=4            
            end            
        else
            self.dir=1
            if dy1<0 then
                self.dir=3
            end
        end
    end
end

very cool! So compact, and yet a fully functional game!
It did remind me of Lode Runner, so full marks for sentimental value too :slight_smile:

@juce I don’t play games anymore other than to see what they look like when someone posts it. Sometimes I’ll be coding one thing and see a spinoff for a game starter or someone will post something that will remind me of a game and try coding it. The above is only coded for one level, but I added to the code I have to do 2 levels. That also means that 3 or more levels can be added just by adding values to the tables. I’ll probably post that once it’s cleaned up.

@The original code above has been changed. It now has 3 levels and more levels can be added by adding data to the tables.

The user and all related content has been deleted.

The user and all related content has been deleted.

@NatTheCoder didn’t you say you were a kid?

The user and all related content has been deleted.

The user and all related content has been deleted.

@NatTheCoder Oh, I thought you said that, I didn’t realize you were quoting him

@NatTheCoder If you want the objects to move faster, make the 20 in function movers:move a smaller value. Try 15 and see how that works. This game has 3 levels, and cancels going to the 4th level, but more levels can be added. As for how old I am, I’m retired, 65+.

The user and all related content has been deleted.

@NatTheCoder He’s a retired programmer with a 300-foot driveway, what did you expect? :stuck_out_tongue:

The user and all related content has been deleted.

@NatTheCoder, it’s a joke from a fairly old discussion.

The user and all related content has been deleted.

Search for driveway

Here: http://codea.io/talk/discussion/4440/newbie-slot-machine-project/p4 look don’t touch