I have recently had an idea for a game and made a quick prototype to test out mechanics. You can tap the screen to spawn a growing circle which will push the ball away from itself. Any ideas comments or suggestions eg. I thought about making it into a breakout type game.
--# Main
-- Main
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)
function setup()
balls={}
leftWall=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT*4))
rightWall=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT*4))
bWall=physics.body(EDGE,vec2(0,200),vec2(WIDTH,200))
tWall=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
rep={}
parameter.watch("1/DeltaTime")
parameter.watch("#rep")
tr=table.remove
timer=0
physics.gravity(0,-150)
for i=1,1 do
spawnBall()
end
end
function draw()
if 1/DeltaTime<50 and ElapsedTime>1 then print(1/DeltaTime)end
background(0)
for i=#balls,1,-1 do
if balls[i].body.y<-100 then
balls[i].body:destroy()
table.remove(balls,i)
end
end
for i=1,#balls do
balls[i]:draw()
end
for i=#rep,1,-1 do
if rep[i].alive==false then
tr(rep,i)
end
end
for i=1,#rep do
rep[i]:draw()
end
pushStyle()
stroke(255)
strokeWidth(4)
line(0,200,WIDTH,200)
popStyle()
end
function touched(touch)
if touch.state==BEGAN then
table.insert(rep,Repulse(touch.x,touch.y))
end
end
function spawnBall()
print("ball")
table.insert(balls,
Ball(math.random(100,WIDTH-100),HEIGHT-100))
end
function angleBetween(ptA,ptB)
local angle=math.deg(math.atan2(ptA.y-ptB.y,ptA.x-ptB.x))
angle = angle + 90
return angle
end
--# Repulse
Repulse = class()
Repulse.size=200
Repulse.speed=6
Repulse.strength=0.05
function Repulse:init(x,y)
self.pos=vec2(x,y)
self.radius=0
self.alpha=255
self.alive=true
end
function Repulse:draw()
pushStyle()
if self.alive==false then return end
self.radius=self.radius+Repulse.speed
self.alpha=self.alpha-(255/Repulse.size)*Repulse.speed
if self.alpha<=20 then self.alive=false end
fill(255,0,0,self.alpha)
ellipse(self.pos.x,self.pos.y,self.radius)
for i=1,#balls do
local ball=balls[i].body
local dist=vec2(ball.x,ball.y):dist(self.pos)
if dist<self.radius+ball.radius then
local angle=angleBetween(self.pos,vec2(ball.x,ball.y))
local force=(self.radius+ball.radius)-dist
ball:applyForce(vec2(0,force):rotate(math.rad(angle))*Repulse.strength)
end
end
popStyle()
end
--# Ball
Ball = class()
Ball.radius=30
function Ball:init(x,y)
self.body=physics.body(CIRCLE,Ball.radius)
self.body.x=x
self.body.y=y
self.body.mass=0.05
self.body.restitution=0.5
--self.body.linearDamping=0.99
end
function Ball:draw()
pushStyle()
ellipseMode(RADIUS)
fill(255)
ellipse(self.body.x,self.body.y,self.body.radius)
popStyle()
end