My New Apple Eating Game

Blobby Blue code:


--# Main
-- This program was made by Adam9812. It is Public Domain.

-- Blobby Blue 2.1.1

function setup()
    
    apple = readImage("Dropbox:Apple")
    tnt = readImage("Dropbox:TNT")
    rareApple = readImage("Dropbox:RareApple")
    tree = readImage("Dropbox:Tree")
    
    appleNumber = 0
    saveAppleNumber = 0
    tntNumber = 0
    saveTNTNumber = 0
    
    music("Game Music One:Zero")
    
    print("Functiontime: The amount of time a spawn cycle lasts in seconds.")
    print("Score: A measure of how well you're doing. Eating an apple raises it based off how long your functiontime is, while eating TNT subtracts 10 points.")
    print("Totalscore: The total score from all your Blobby Blue Sessions.")
    print("Totalapplenumber: All apples you've eaten in all sessions.")
    print("TotalTNTnumber: All TNT you've eaten in your sessions.")
    
    parameter.number("functionTime",0.5,7,4)
    
    saveTreeEncounters = 0
    
    score = 0
    saveScore = 0
    musicTime = 324
    treeTrue = false
    totalScore = readLocalData("totalScore",0)
    highScore = readLocalData("highScore", 0)
    totalAppleNumber = readLocalData("totalAppleNumber",0)
    totalTNTNumber = readLocalData("totalTNTNumber",0)
    totalTreeEncounters = readLocalData("totalTreeEncounters",0)
    callAmount = functionTime
    
    parameter.watch("score")
    parameter.action("Save",save)
    parameter.watch("totalScore")
    parameter.watch("totalAppleNumber")
    parameter.watch("totalTNTNumber")
    parameter.watch("totalTreeEncounters")
    
    appleX = math.random(50,WIDTH - 50)
    appleY = math.random(50,HEIGHT - 50)
    
    rareappleX = math.random(50,WIDTH - 50)
    rareappleY = math.random(50,HEIGHT - 50)
    
    tntX = math.random(50,WIDTH - 50)
    tntY = math.random(50,HEIGHT - 50)
    
    treeX = math.random(50,WIDTH - 50)
    treeY = math.random(50,HEIGHT - 50)
    
end

function zero()
    
    musicTime = musicTime + 324
    music("Game Music One:Zero")
    
end

function draw()
    
    background(25, 28, 29, 255)
    
    sprite("Dropbox:Blobby_Blue",CurrentTouch.x,CurrentTouch.y)
    
    if appleGone == false then
        
        sprite(apple,appleX,appleY)
        eat()
        
    end
    
    if treeTrue == true then
        
        sprite(tree,treeX,treeY)
        
        chop()
        
    end
    
    if ElapsedTime > callAmount then
        
        spawn()
        
    end
    
    if ElapsedTime > musicTime then
        
        zero()
        
    end
    
    if tntSpawn == 1 then
        
        sprite(tnt,tntX,tntY)
        boom()
        
    end
    
    if appleSpawn == 1 then
        
        sprite(rareApple,rareappleX,rareappleY)
        eat()
        
    end
    
end

function spawn()
    
    appleGone = false
    
    appleX = math.random(50,WIDTH - 50)
    appleY = math.random(0,HEIGHT - 50)
    
    callAmount = callAmount + functionTime
    
    tntSpawn = math.random(1,5)
    
    if treeTrue == true then
        
        appleSpawn = 1
        
        rareappleX = math.random(50,WIDTH - 50)
        rareappleY = math.random(50,HEIGHT - 50)
        
        else
        
        appleSpawn = math.random(1,8)
        
        if appleSpawn == 1 then
            
            rareappleX = math.random(50,WIDTH - 50)
            rareappleY = math.random(50,HEIGHT - 50)
            
        end
        
    end
    
    if tntSpawn == 1 then
        
        tntX = math.random(50,WIDTH - 50)
        tntY = math.random(50,HEIGHT - 50)
        
    end
    
    if treeTrue == false then
        
        treeRoll = math.random(1,25)
        
        treeX = math.random(50,WIDTH - 50)
        treeY = math.random(50,HEIGHT - 50)
        
        if treeRoll == 1 then
            
            treeTrue = true
            print("A tree has spawned!")
            saveTreeEncounters = saveTreeEncounters + 1 
            
        end
        
    end
    
end

function save()
    
    if score > highScore then
        
        highScore = score
        saveLocalData("highScore",highScore)
        print("Sucess! Your new High score is: "..highScore.."!")
        
        else
        
        print("You didn't beat your High Score yet! It is "..highScore..".")
        
    end
    
    if saveScore > 0 then
        
        totalScore = totalScore + saveScore
        saveScore = 0
        saveLocalData("totalScore",totalScore)
        
    end
    
    totalAppleNumber = totalAppleNumber + saveAppleNumber
    saveAppleNumber = 0
    saveLocalData("totalAppleNumber",totalAppleNumber)
    
    totalTreeEncounters = totalTreeEncounters + saveTreeEncounters
    saveTreeEncounters = 0
    saveLocalData("totalTreeEncounters",totalTreeEncounters)
    
    totalTNTNumber = totalTNTNumber + saveTNTNumber
    saveTNTNumber = 0
    saveLocalData("totalTNTNumber",totalTNTNumber)
    
end
--# Eat
function eat ()
    
    local w,h = apple.width * 2,apple.height * 2
    local top = appleY + h
    local bottom = appleY - h
    local left = appleX - w
    local right = appleX + w
    local x,y = CurrentTouch.x,CurrentTouch.y
    
    if x >= left and x <= right and y >= bottom and y <= top and appleGone == false then
        appleNumber = appleNumber + 1
        saveAppleNumber = saveAppleNumber + 1
        appleGone = true
        score = score + 4/functionTime
        saveScore = saveScore + 4/functionTime 
        sound("A Hero's Quest:Eat 3")
        
        if appleNumber == 1 then
            
            print("You now ate "..appleNumber.." apple!")
            
            else
            
            print("You now ate "..appleNumber.." apples!")
            
        end
        
    end
    
    local w3,h3 = rareApple.width * 2,rareApple.height * 2
    local top = rareappleY + h3
    local bottom = rareappleY - h3
    local left = rareappleX - w3
    local right = rareappleX + w3
    local x3,y3 = CurrentTouch.x,CurrentTouch.y
    
    if x3 >= left and x3 <= right and y3 >= bottom and y3 <= top and appleSpawn == 1 then
        appleNumber = appleNumber + 1
        saveAppleNumber = saveAppleNumber + 1 
        appleSpawn = 2
        score = score + 40/functionTime
        saveScore = saveScore + 40/functionTime 
        sound("A Hero's Quest:Eat 3")
        
        if appleNumber == 1 then
            
            print("You now ate "..appleNumber.." apple!")
            
            else
            
            print("You now ate "..appleNumber.." apples!")
            
        end
        
    end
    
end

function boom ()
    
    local w2,h2 = tnt.width * 2,tnt.height * 2
    local top = tntY + h2
    local bottom = tntY - h2
    local left = tntX - w2
    local right = tntX + w2
    local x2,y2 = CurrentTouch.x,CurrentTouch.y
    
    if x2 >= left and x2 <= right and y2 >= bottom and y2 <= top and tntSpawn == 1 then
        tntNumber = tntNumber + 1
        saveTNTNumber = saveTNTNumber + 1
        print("BOOM! You tried to eat "..tntNumber.." TNT.")
        tntSpawn = 2
        score = score - 10
        saveScore = saveScore - 10 
        sound(DATA, "ZgNAHxo7RkBAQ1VA6HatPTzT3z6BfBE/UQBAZlk+IEBAQCBr")
        
    end
    
end

function chop()
    
    local w4,h4 = tree.width,tree.height
    local top = treeY + h4
    local bottom = treeY - h4
    local left = treeX - w4
    local right = treeX + w4
    local x4,y4 = CurrentTouch.x,CurrentTouch.y
    
    if x4 >= left and x4 <= right and y4 >= bottom and y4 <= top and treeTrue == true then
        print("Tree Destroyed.")
        sound(DATA, "ZgNAWBY/QBkDXFJ5D7OAPWMPszwLyBc/KgASfz9ANEo6XnFX")
        treeTrue = false
        
    end
    
end

WARNING: For it to work, all the assets must be downloaded and the following sprites are used.

https://www.dropbox.com/s/6zav2pwd4a6r03q/Apple.png

https://www.dropbox.com/s/yp7g3la1mkkws9k/Blobby_Blue.png

https://www.dropbox.com/s/jmheewptpa41qpj/RareApple.png

https://www.dropbox.com/s/ia5kenqjic2uyxg/TNT.png

https://www.dropbox.com/s/rskr1jtygo263qp/Tree.png

@Adam9812 - for us lazy people who just want a quick peek, why don’t you make a short video for us?

Ok. Here’s one for the current version.

https://www.dropbox.com/s/plehsrahn71vwfz/Blobby%20Blue%20Preview.mov

Oh, and here’s a version which no longer allows apples and TNT to spawn near the edge.

Are you a Android fanboy or something?

@Goatboy76 No, I don’t even own an android. Why?

Its a game where you eat apples, and Andoird and Apple are arch rivals. It was a bad joke.

Oh. I do not know why I came up with this idea. It just popped into my head one day and I thought it would be cool to make into a game. :stuck_out_tongue:

Anyone have ideas on what to add? I am stumped.

Unpluralised it if apple number is only 1.

Apples fall from trees, right? Maybe do something with that.

Good Idea. This Friday I will see if I can add a tree in which increases the spawn rate of green apples as long as you don’t try to eat the tree.

The Update 2.1 is complete! It has added trees, which will change the spawn rate of green apples to 100% of the time if they are on! Be sure not to eat the trees though, they are extremely rare. Only 4% chance of spawning every time the spawn function is called.

EDIT: if you wish to get the update,also be sure to get the new tree sprite listed above.

Another Minor update. Now with a sound when you eat trees and it now saves the amount of times you encounter trees.

@Adam9812 this is a great little game.
One improvement though: when you load the sprites with:

apple=readImage(Dropbox:Apple) 

You could just draw them with

sprite(apple,appleX,appleY) 

As you have already loaded the sprite

Ok. It is now complete.