Post by warspyking on Feb 3, 2016 0:37:42 GMT
Despite not having food textures, I made a game where you have a "net" and you catch "food".
Post your high scores!
Post your high scores!
---ButtonCode---
local Food
local CreateFood
local net
local DrawNet
do
--quick net define
function DrawNet(n)
local lx,ly = n.Position.X-n.Size.X/2, n.Position.Y-n.Size.Y/2
local rx,ry = n.Position.X+n.Size.X/2, n.Position.Y+n.Size.Y/2
draw.fillrect(lx, ly, rx, ry, draw.black)
end
local real = {Position={X=0,Y=0},Size={X=0,Y=0}}
net = setmetatable({},{__index = real,
__newindex = function(t,k,v)
real[k] = v
DrawNet(t)
end
})
Food = {}
local function DrawFood(b)
local lx,ly = b.Position.X-b.Size.X/2, b.Position.Y-b.Size.Y/2
local rx,ry = b.Position.X+b.Size.X/2, b.Position.Y+b.Size.Y/2
draw.rect(lx, ly, rx, ry, b.BorderColor)
draw.fillrect(lx, ly, rx, ry, b.FillColor)
draw.stringinrect(b.Text, lx, ly, rx, ry, b.StringColor)
end
local function Draw(buttons,c)
draw.clear(c or draw.white)
for i,b in ipairs(buttons) do
DrawFood(b)
end
end
function CreateFood(s,p,n,bc,fc,a,t,sc,f,fs)
if f and fs then
draw.setfont(f, fs)
end
local real = {Size=s,Position=p,Name=n,BorderColor=bc,FillColor=fc,Action=a,Text=t or "",StringColor=sc or draw.black,Active=true}
local b = setmetatable({},{
__index = real,
__newindex = function(t,k,v)
real[k] = v
Draw(Food)
end
})
Food[#Food+1] = b
Draw(Food)
return b
end
local function IsInside(x,y,b)
return x < b.Position.X+b.Size.X/2 and x > b.Position.X-b.Size.X/2 and y < b.Position.Y+b.Size.Y/2 and y > b.Position.Y-b.Size.Y/2
end
local function FindFood(x,y)
for i,b in ipairs(Food) do
if IsInside(x,y,b) and b.Active then
return b
end
end
end
local function SetNet(x,y)
net.Position = {X=x, Y=net.Position.Y}
end
draw.tracktouches(SetNet, SetNet, SetNet)
end
---GameCode---
local size = 30
local time = 1
local lvlup = 20
local decrement = 3
local rarity = 30
local maxlvl = 10
local Colors = {draw.yellow, draw.orange, draw.red, draw.green, draw.blue, draw.purple, draw.gray, draw.darkgray, draw.black}
local Caught = 0
--
local i = 0
local dots = 1
local lvl = 1
local win = false
draw.setscreen(1)
draw.settitle("Falling Food")
local width,height = draw.getport()
local Squashed = 0
local Finished = false
function Catch(b, x, y)
Caught = Caught + 1
for i,v in ipairs(Food) do
if v == b then
table.remove(Food, i)
break
end
end
end
function RandomSlot()
local slots = math.floor((width-45)/size)
return size*math.random(slots)
end
function GenerateFood()
local slot = RandomSlot()
return CreateFood({X=size, Y=size}, {X=slot, Y=size}, tostring(#Food+1), draw.blue, Colors[lvl], Catch)
end
net.Position = {X=width/2,Y=height-50}
net.Size = {X=30,Y=10}
GenerateFood()
while not Finished do
draw.beginframe()
i = i + 1
if i%rarity == 0 then
GenerateFood()
dots = dots + 1
end
if dots%lvlup == 0 then
size = size - 3
rarity = rarity - 3
decrement = decrement + 2
lvlup = math.floor(lvlup*1.5)
lvl = lvl + 1
end
if lvl == maxlvl then
win = true
Finished = true
break
end
for i,v in ipairs(Food) do
v.Position = {X = v.Position.X, Y = v.Position.Y + decrement}
if v.Position.X < net.Position.X + net.Size.X/2 and v.Position.X > net.Position.X - net.Size.X/2 and v.Position.Y < net.Position.Y + net.Size.Y/2 and v.Position.Y > net.Position.Y - net.Size.Y/2 then
v:Action()
elseif v.Position.Y + size/2 >= height then
Finished = true
end
end
DrawNet(net)
draw.doevents()
sleep(time)
draw.endframe()
end
draw.setscreen(0)
if not win then
print("YOU LOSE!")
print("You succesfully caught ".. Caught .." pieces of food!")
else
print("YOU WIN!")
print("You succesfully caught all ".. Caught .." pieces of food!")
end