100 Lines of Code Challenge!

Hey everyone!

Everyone has probably seen the 50 lines of code challenge, which had some interesting games made in it. Most of the games were really limited by the 50 line requirement and didn’t have start menus or anything like that. I was thinking that maybe we should do a 100 line challenge, but it has to be a complete game with start menu, try again screen, music(), sound(), score/high score, etc.

I think it would be a good learning experience to see how people do different aspects of making a game.

The only rules is the game must be under 100 lines of neat code (no multiple codes in a single line), and must use Codea assets.

I will be working on my submission.

Look forward to seeing what you guys come up with!

Edit: I’m going to add one leeway, you can add multiple end commands on one line.

nice. maybe: 1/ make positions non-integer? 2/ press right/left to move the paddle?

Here is my entry.



Warnings: Difficult (I might make it easier), and there’s a glitch where you might get 0.02 or 0.03, just try again.




Touch to move the player, don’t let the player touch the enemy balls or the sides!



Code:

-- 100 Line Challenge
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function setup()
    physics.continuous=true
    fsm="menu"
    eBalls={}
    physics.gravity(0,0)
    edges={physics.body(EDGE, vec2(0,0), vec2(WIDTH, 0)), physics.body(EDGE, vec2(0,0), vec2(0, HEIGHT)), physics.body(EDGE, vec2(0, HEIGHT), vec2(WIDTH, HEIGHT)), physics.body(EDGE, vec2(WIDTH, HEIGHT), vec2(WIDTH, 0))}
    player=physics.body(CIRCLE, 20)
    player.info="the player"
    player.position=vec2(WIDTH/2, HEIGHT/2)
    font("HelveticaNeue-UltraLight")
    fontSize(80)
    textAlign(CENTER)
    aToucher=false
end
function draw()
    background(0, 0, 0, 255)
    fill(255, 255, 255, 255)
    if fsm=="menu" then
        text("100 Line Game: Death Balls", WIDTH/2, HEIGHT/4*3)
        text("START", WIDTH/2, HEIGHT/2-100)
        fill(255, 50)
        ellipse(WIDTH/2, HEIGHT/2-100, 400)
    end
    if fsm=="setup" then
        scoreTimer=0
        for i=1,#eBalls do
            eBalls[i].p:destroy()
            eBalls[i]=nil
        end
        for i=1,50 do
            table.insert(eBalls, Ball(10, math.random(10, HEIGHT-10)))
        end
        fsm="playing"
    end
    if fsm=="playing" then
        scoreTimer = scoreTimer + DeltaTime
        for a,b in pairs(eBalls) do         
            b:draw()
        end
        fill(0, 0, 255, 255)
        ellipse(player.x, player.y, 40)
        player.position=vec2(CurrentTouch.x, CurrentTouch.y)
    end
    if fsm=="dead" then
        text("You lasted:\
"..string.format("%.2f", scoreTimer).." seconds", WIDTH/2, HEIGHT/3*2)
        text("AGAIN", WIDTH/2, HEIGHT/3)
        fill(255, 50)
        ellipse(WIDTH/2, HEIGHT/3, 300)
    end
end
function touched(t)
    if fsm=="menu" and t.state==ENDED and t.x>WIDTH/2-200 and t.x<WIDTH/2+200 and t.y<HEIGHT/2+200 and t.y>HEIGHT/2-200 then
        fsm="setup"
    end
    if fsm=="dead" then
        if t.state==BEGAN and aToucher==false then
            aToucher=true
        end
        if t.state==ENDED and aToucher and t.x>WIDTH/2-150 and t.x<WIDTH/2+150 and t.y<HEIGHT/3+150 and t.y>HEIGHT/3-150 then
            fsm="setup"
        end
    end
end
function collide(c)
    if fsm=="playing" then
        if c.bodyA.info~=nil or c.bodyB.info~=nil then
            fsm="dead"
        end
    end
end
Ball = class()
function Ball:init(x, y)
    self.p=physics.body(CIRCLE, 10)
    self.p.friction=0
    self.p.restitution=1
    self.p.position=vec2(x, y)
    self.p.bullet=true
    self.p.linearVelocity=vec2(math.random(-500, 500), math.random(-500, 500))
end
function Ball:draw()
    fill(255, 255, 255, 255)
    ellipse(self.p.x, self.p.y, 20)
end

My Submission: The Falling Spectrum. Dodge the rain. (Portrait)

May have bunched a few single line if statements together, or a couple pushStyle/popStyles sharing lines, but I did spend 3 hours on this do please don’t be too critical about that. Let me know what you guys thing ^.^ I may develop it a tad further into the App Store.

function setup()
    displayMode(FULLSCREEN)
    supportedOrientations(PORTRAIT_ANY)
    mode = Classic()
    score = 0
    hs = readLocalData("highscore") or 0
    time = os.clock()
    fontSize(80)  
    song = music("Game Music One:Smoothie", true)  
end
function draw()
    background(255, 255, 255, 255)
    mode:draw()
end
function touched(t)
    if mode ~= nil then mode:touched(t) end
end
function collide(c)
    if c.bodyA.id == mode.ball.id or c.bodyB.id== mode.ball.id then
        mode.gameOver = true
        physics.pause()
        if score > hs then hs = score
        saveLocalData("highscore", hs)  end
    end
end
Classic = class()
function Classic:init()
    self.ball = physics.body(CIRCLE, 50)
    self.ball.x,self.ball.y = WIDTH/5 * 2 + WIDTH/10,350
    self.ball.gravityScale = 0
    self.ball.color = color(127,127,127)
    self.ball.id = 69
    self.drops = {}
    self.fade = 255
    self.gameOver = false
end
function Classic:draw()
    makeRain()
    text(score, WIDTH/2, HEIGHT*.5)
    pushStyle()
    for a,b in pairs(self.drops) do
        if b.y < WIDTH/5 + b.radius*2 + 10 then fill(b.color) else fill(127,127,127) end
        ellipse(b.x,b.y,b.radius * 2)
    end   
    fill(self.ball.color)
    ellipse(self.ball.x, self.ball.y, self.ball.radius * 2)
    popStyle()
    for a = 1, 7 do
        rect((a-1) * WIDTH/5, HEIGHT/5, WIDTH/5, WIDTH/10)
    end
    if not self.gameOver and self.fade > 0 then
        pushStyle() 
        fill(255, 255, 255, self.fade)
        rect(0,0, WIDTH, HEIGHT) 
        popStyle()
        self.fade = self.fade - 2
    end
    if self.gameOver then
        pushStyle()
            fill(255, 255, 255, self.fade)
            rect(0,0,WIDTH, HEIGHT)
            self.fade = self.fade + 1.5
        popStyle()
        fill(127, 127, 127, self.fade)
        if self.fade > 255 then fill(127) end
        fontSize(50)
        text("High Score: "..hs, WIDTH/2, HEIGHT * .75)
        text("".."And So The \
Story Ended", WIDTH/2, HEIGHT*.5)
        ellipse(WIDTH/2, HEIGHT/5, HEIGHT/5)
        fill(255, 255, 255, 255)
        text("AGAIN",WIDTH/2, HEIGHT/5)
    end
    pushStyle()   fontSize(50)
    text("By Kirk Zimmer", WIDTH* .75, HEIGHT *.05)
    popStyle()
end
function Classic:touched(t)
    self.ball.x = math.floor((t.x) /(WIDTH/5)) *WIDTH/5 + WIDTH/10
    if self.gameOver and vec2(t.x,t.y):dist(vec2(WIDTH/2, HEIGHT/5)) < HEIGHT/10 then restart() end
end
function makeRain()
    for a = 1, #mode.drops do
        if mode.drops[a].y < -100 then
            mode.ball.color = color(mode.drops[a].color.r, mode.drops[a].color.g, mode.drops[a].color.b, 20):blend(mode.ball.color)
            mode.drops[a]:destroy()
            mode.drops[a] = nil
            table.remove(mode.drops, a)
            score = score + 1
            break
        end
    end
    if #mode.drops < 40 and #mode.drops <= (score* 2) and math.random(100) <= (1 + score/10) and os.clock() - time > .05 then
        local drop = physics.body(CIRCLE, math.random(20,WIDTH/30))
        drop.x,drop.y = WIDTH/5 * (math.random(5)-1)+ WIDTH/10,HEIGHT* 1.2
        drop.gravityScale = .09 + score*.006
        drop.color = color(math.random(100,230), math.random(80,255), math.random(100,230), 255)
        table.insert(mode.drops, drop)
        time = os.clock()
    end
end

Those are a little iffy, especially the second two…

In neat code the first one would be more like:


If t == true then
    x = x - 1
end

I would think that the first one would be allowed

Like is this not allowed?

1.) If t == true then X = X - 1 end

Or is this isn’t allowed?

2.)X = 20 Y = 500 If t == true X = X - 1 end ellipse(X,Y,60)

And would this not be allowed

3.)If n == 1 then (do something) else if n == 2 then (do something) end end

What does it mean that you can’t have multiple codes In one line?

Then sign me up

@Progrmr235 I don’t think it’s too late to enter.

I’m almost done with mine (I have too much free time) there’s a lot of bugs though I have fix.

Nah there isn’t really a time limit. The thread got kind of derailed, hopefully a mod can clean it up…

I’m still working on my 100 line game, been busy last 2 days

Uh, I’m interesting in this challenge. Is it too late to enter?

@Crumble Sorry, I misunderstood what you were saying. I guess I was taking your comment, “seeing how different people tackle the same challenges” too literally. I was looking at it as a specific challenge, where your challenge was the 100 lines. I guess I’ve been programming so long that I actually think in code. When someone says something, the code is already written in my head, I just need to type it out.

@dave1707 I definitely think that specific challenges like that would be an awesome thing. It’s just way over my head right now. I wouldn’t mind seeing you pros do something like that, I’m sure I would learn a lot from it.

@Crumble I’m not really looking for challenges, I had too many years of that already. I’m just here to help.

@Crumble If you want to see how people tackle the same challenges, why not pick a subject and have people write code to do it. For instance, shuffle a deck of cards, move a sprite around the screen in a specific pattern, create an exploding ship with multiple parts, show menu pages, etc. In other words, things that people might need when they create a game or other type program. That way they see different programming styles and how one way might be a better option than another and why.

EDIT: There doesn’t have to be a line limit for that.

I think what is happening is that the experienced coders that have no problem writing a program with 1,000+ lines of code don’t feel challenged by something like this, or feel extremely limited.

However there are a lot newbies like myself, where writing a 100 line game is an accomplishment.

I wouldn’t even know where to start on a card shuffling program, etc. that stuff is way over my head.

I guess this challenge is focused toward beginners like myself…

The menus make it more polished, and allow you to have a final score, high score, game title, etc. I guess it will just show the potential of codea when you could make a complete game in under 100 lines.

Also I think a lot of people (myself included) start projects, but don’t actually complete them… maybe this will push people to complete their projects.

The main reason I wanted to start a new x lines of code challenge is because in the 50 lines challenge a lot of people were adding multiple codes per line, which kind of ruined the idea of only 50 lines.

I guess I see it as a learning experience, seeing how different people tackle the same challenges.

You don’t have to participate if you don’t want to. :-*

I feel like these “x lines of code challenges” are a bit repetitive. 50 lines was a good amount, enough to make a project, but little so you must work to make it fit. I feel like it would be a bit hard to come up with a project of 100 lines, it seems either all or nothing.

I also don’t like the restrictions of it having to be a game with menus, why not a paint program, or a simple game without a menu (if you have no options or anything, what’s the point of a menu with only one button?)