Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bullets2
function setup()
physics.gravity(0,0)
bullets={}
ball={}
ball = {} --NEW
for i = 1,5 do --NEW
ball[i] = Ballons()
end
end
function touched(touch)
x = touch.x
y = touch.y
if touch.state == BEGAN then --create bullet
local bullet = physics.body(CIRCLE,10) -- <<NEW
bullet.x,bullet.y = x,y
bullet.linearVelocity = vec2(1000,0)
bullet.restitution = 0
bullet.type = DYNAMIC
table.insert(bullets,bullet)
end
end
function draw()
background(0, 0, 0, 255)
--draw bullets
pushStyle()
fill(255, 255, 255, 255)
for i,b in pairs(bullets) do
if b.x<1 or b.x>WIDTH or b.y<1 or b.y>HEIGHT then
--b:destroy()
table.remove(bullets,i)
else
ellipse(b.x,b.y,10)
end
end
popStyle()
for i = 1,#ball do -- NEW drawing the ballons
pushStyle()
fill(ball[i].ballon.colr)
ellipse(ball[i].ballon.x, ball[i].ballon.y, ball[i].radius*2)
popStyle()
end
end
Ballons = class() --NEW
function Ballons:init(x,y,r,c,lv)
self.radius = r or math.random(25,50)
self.ballon = physics.body(CIRCLE,self.radius)
self.ballon.x = x or math.random(WIDTH/2,WIDTH)
self.ballon.y = y or math.random(-HEIGHT/2,-self.radius)
self.ballon.linearVelocity = lv or vec2(0,math.random(100,150))
self.ballon.colr = c or color(math.random(255),math.random(255),math.random(255),math.random(100,150))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.