Organize People to walk on roads when you tap the screen!
Note:
Only every 2 seconds you can place an object by tapping the screen.
My Code:
--# Main
--# Main
displayMode(FULLSCREEN)
function setup()
Player1NumberElexir=0
elexir=0
objects = {} -- creates a table for objects
parameter.watch("CurrentTouch.y")
parameter.watch("CurrentTouch.x")
parameter.watch("elexir")
parameter.watch("Player1NumberElexir")
end
function draw()
background(40, 40, 50)
rect(125,0,50,HEIGHT)
rect(475,0,50,HEIGHT)
elexir=elexir+1
if elexir==80
then
Player1NumberElexir=Player1NumberElexir+1
elexir=0
end
if Player1NumberElexir==11
then
Player1NumberElexir=10
end
for i, o in pairs(objects) do
o:draw() -- loop through your objects table and draw
end
end
function touched(touch)
if CurrentTouch.y < HEIGHT/2 and Player1NumberElexir>=2 and touch.state==BEGAN
then
table.insert(objects,Object(touch.x,touch.y))
Player1NumberElexir=Player1NumberElexir-2
end
end
--# object
Object = class()
function Object:init(x,y)
self.x = x
self.y = y
end
function Object:draw()
self.y = self.y+1
if self.x < WIDTH/2
then
if self.x<100
then
self.x=self.x+1
end
if self.x>150
then
self.x=self.x-1
end
end
if self.x > WIDTH/2
then
if self.x<450
then
self.x=self.x+1
end
if self.x>500
then
self.x=self.x-1
end
end
--self.y=self.y+1
print(self.x)
stroke(255, 255, 255, 255)
strokeWidth(5)
fill(29, 114, 133, 255)
sprite("Planet Cute:Character Boy",self.x,self.y,50)
-- if self.x > WIDTH/2
-- then
-- end
end