Skip to content

Instantly share code, notes, and snippets.

@omerfarukz
Created March 31, 2014 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerfarukz/9903040 to your computer and use it in GitHub Desktop.
Save omerfarukz/9903040 to your computer and use it in GitHub Desktop.
require("vector")
local physics = require("physics")
physics.setDrawMode("normal")
physics.start()
local ground = display.newRect(0,470,320,10)
ground.anchorX, ground.anchorY = 0,0
ground:setFillColor(0,1,0)
physics.addBody(ground,"static")
for i=0,9 do
for k=1,6 do
local box = display.newRect(200+(k*12),440 - (i*30),10,30)
box.anchorX, box.anchorY = 0,0
box:setFillColor(1/i+ 0.3,0,1)
physics.addBody(box,{friction=0.3})
end
end
local circleBig = display.newCircle(80,440, 30)
circleBig:setFillColor(1,0.2,0)
physics.addBody(circleBig, {radius=30,friction=0.1, density=0.1})
local bomb = display.newCircle(160,0,10)
bomb.name = "bomb"
physics.addBody(bomb,{radius=10, bounce=0.4})
local particles = {}
function drawParticles()
local distance = 20
local bv = vector:new(bomb.x, bomb.y)
for i=0,360, 20 do
if i ~= 0 then
local angle = (2*math.pi)/360*i
local px = bomb.x + distance*math.cos(angle)
local py = bomb.y + distance*math.sin(angle)
local p = display.newCircle(px,py,10)
p.alpha = 0
p.name = "bomb_particle"
p.gravityScale = 0
p.isBullet = true
physics.addBody(p)
local pv = vector:new(p.x, p.y)
p.forceVector = bv:sub(pv):normalize()
local asd = p.forceVector:imul(10)
p:applyForce(asd.x, asd.y, p.x, p.y)
table.insert(particles, p)
end
end
end
function makeBlast()
end
local function onCollision( e )
if e.object1.name=="bomb" and e.object2.name=="bomb" then
return
end
if ( e.phase == "ended" ) then
if e.object1.name ~= nil and e.object1.name == "bomb_particle" then
physics.removeBody(e.object1)
e.object1:removeSelf()
elseif e.object2.name ~= nil and e.object2.name == "bomb_particle" then
physics.removeBody(e.object2)
e.object2:removeSelf()
end
end
end
local function onTouch( event )
if event.phase ~= "began" then
return true
end
physics.removeBody(bomb)
--bomb:removeSelf()
drawParticles()
--makeBlast()
return true
end
Runtime:addEventListener( "collision", onCollision )
Runtime:addEventListener( "touch", onTouch )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment