Impossible Game 3.0!

Just a little something I had been working on. It is a very hard game, my own spin on the flappy bird craze. I would love to see what you think about it, so feedback would be great. The code is horribly inefficient, I know, but I made this when I had no idea how to make new classes or use tables. Also, the second option in the store is not currently operational. I am also open to any ideas to how I could improve it!

-- Falling guy 3.0
--Completely rewritten
--By TheSolderKing
function setup()
    stage=1
    score=0
    parameter.watch('score')
    parameter.watch('highscore')
    supportedOrientations(LANDSCAPE_RIGHT)
    displayMode(FULLSCREEN)
    player={x=WIDTH/2, y=HEIGHT-200}
    print("Hello World!")
    pipes={}
    frame=0
    speed=5
    pipesy={-100}
    prev=1
    clouds={}
    for a=1, math.random(1,20) do
        clouds[a]={math.random(0,WIDTH), math.random(0,WIDTH),math.random(1,2)}
    end
    sun=400
    
end


function draw()
    if stage==1 then
        background(255)
        fill(92, 91, 91, 255)
        Player(stage)
        text("Falling Guy Version 3.0, Tap Smiley to Play", WIDTH/2, HEIGHT-100)
        if button(50, 50, player.x, player.y)==true then stage=2 end
    end
    if stage==2 then
        
    background(0, 175, 255, 255)
        fill(255, 237, 0, 255)
    ellipse(0, HEIGHT, 300, 300)
        fill(255, 255, 0, 100)
        ellipse(0, HEIGHT, sun, sun)
        sun=sun+math.random(-2, 2)
    for c, d in pairs(clouds) do
        drawClouds(d[1], d[2], d[3])
            d[2]=d[2]+0.4
            if d[2]>HEIGHT+100 then
                table.remove(d, 1)
                table.remove(d,2)
                table.remove(d, 3)
                d[1]=math.random(0, WIDTH)
                d[2]=-50
                d[3]=math.random(1, 2)
            end
    end
    
if frame%90==0 then
        table.insert(pipes, math.random(200, WIDTH-200))
        table.insert(pipesy, -100)
    end
    for i,v in pairs(pipes) do
        fill(255, 0, 4, 255)
        rect(0, pipesy[i], v-100, 40)
        rect(v+100, pipesy[i], WIDTH-(v+100), 40) 
        pipesy[i] = pipesy[i] + speed
        prev=i-1
        collisionDetect(v, pipesy[i])
        if pipesy[i]>HEIGHT+10 then
            table.remove(pipesy, i)
            table.remove(pipes, i)
        end
    end
    
    
Player(stage)
    moveY()
    strokeWidth(0)
    noSmooth()
    frame = frame + 1
        
        end
    
end



function drawClouds(x,y, scal)
    fill(255, 255, 255, 255)
    ellipse(x, y, 40*scal, 40*scal)
    ellipse(x-20*scal, y, 50*scal, 50*scal)
    ellipse(x-40*scal, y, 40*scal, 40*scal)
    
end

function Player(a)
    fill(255, 255, 0, 255)
    rect(player.x, player.y, 50, 50)
    fill(0)
    ellipse(player.x+15,player.y+15, 5, 5 )
    ellipse(player.x+35, player.y+15, 5, 5)
    rect(player.x+10, player.y+5, 30, 5)
    if a==2 then
    player.x = player.x + Gravity.x*10
    end
end
function collisionDetect(v, y)
    if player.x>0 and player.x<v-100 and player.y>y and player.y<y+40 then 
        player.y=y+40
    elseif player.y+50>y and player.y<y+40 and player.x<v-100 then player.x=v-100
        elseif player.x+50>v+100 and player.x+50<WIDTH and player.y>y and player.y<y+40 then player.y=y+40
        elseif player.y+50>y and player.y<y+40 and player.x+50>v+100 then player.x=v+50
         
    end
    if player.x<0 then player.x=0
        elseif player.x+50>WIDTH then player.x=WIDTH-50
        end
end
function moveY()
    if player.y<=HEIGHT and player.y>HEIGHT/2 then player.y = player.y - 0.5
    end
    if player.y>HEIGHT then 
        restart()
    end
end
function button(width, height, x, y)
    if CurrentTouch.state~=ENDED and CurrentTouch.x>x and CurrentTouch.x<x+width and CurrentTouch.y>y and CurrentTouch.y<y+HEIGHT then return true 
        else return false
    end
end

@TheSolderKing - just looking at the code, I strongly recommend you get the indenting right, otherwise as it gets more complex, you will find debugging much harder

For example, this

function draw()
    if stage==1 then
    title()
    end
  if stage==2 then  
drawinit()
drawdude()
createplatforms()
collisionDetection()
score()
end       

Should look like this

function draw()
    if stage==1 then
        title()
    end
    if stage==2 then  
        drawinit()
        drawdude()
        createplatforms()
        collisionDetection()
        score()
    end       

Great game, portrait mode might make it easier

Sorry @Ignatz, I never really payed attention to indenting because all my projects are small! I will have that fixed right up. @Coder, I will implement that now, although I do think that makes it a little too easy :slight_smile:

@TheSolderKing yeah maybe it’s just me being bad at it.

Update:3.0
Completely rewritten! All new code! Anyone know about the table.remove flickering? Why does that happen? Does anyone have a solution?

If i have understand your problem, this is a solution.

local toRemove = {}
    for i,v in pairs(pipes) do
        fill(255, 0, 4, 255)
        rect(0, pipesy[i], v-100, 40)
        rect(v+100, pipesy[i], WIDTH-(v+100), 40) 
        pipesy[i] = pipesy[i] + speed
        prev=i-1
        collisionDetect(v, pipesy[i])
        if pipesy[i]>HEIGHT+10 then
                toRemove[#toRemove+1] = i
        end
    end
    for _,i in pairs(toRemove) do
            table.remove(pipesy, i) -- or pipesy[i] = nil
            table.remove(pipes, i)
    end

PS: Nice little game :wink:

For the pipe flickering, what the game is doing is adding a pipe, drawing the pipes, then deciding if it needs to remove the pipes. A simple fix is to remove the pipes before you draw them.

`
for i,v in pairs(pipes) do

    if pipesy[i]>HEIGHT+10 then
        table.remove(pipesy, i)
        table.remove(pipes, i)
    end
    fill(255, 0, 4, 255)
    rect(0, pipesy[i], v-100, 40)
    rect(v+100, pipesy[i], WIDTH-(v+100), 40) 
    pipesy[i] = pipesy[i] + speed
    prev=i-1
    collisionDetect(v, pipesy[i])
end

`

Never mind that last comment… I didn’t realize that that solution just makes another graphical bug appear. :(( :(( :((