require "box2d"
a=0
b2.setScale(30)
-- this table holds the dynamic bodies and their sprites
local actors = {}
-- create world
local world = b2.World.new(0, 9.8)
-- create ground body
local ground = world:createBody({})
-- ground body is consists of 24 tiny edges
local shape = b2.EdgeShape.new()
local groundFilter = {categoryBits = 1, maskBits = 6}
for x=0,600,20 do
local x1 = x
local x2 = x + 20
local y1 = math.cos((x1 - 240) * 0.01) * 80 + 500
local y2 = math.cos((x2 - 240) * 0.01) * 80 + 500
shape:set(x1, y1, x2, y2)
ground:createFixture({shape = shape, density = 0, filter})
end
-- Faucet box:
local shape = b2.EdgeShape.new()
shape:set(190,190,210,190)
ground:createFixture({shape = shape, density = 0, filter})
local shape = b2.EdgeShape.new()
shape:set(190,190,190,230)
ground:createFixture({shape = shape, density = 0, filter})
local shape = b2.EdgeShape.new()
shape:set(210,190,210,230)
ground:createFixture({shape = shape, density = 0, filter})
------------------------------
local shape1 = b2.PolygonShape.new() -- Water group 1
shape1:setAsBox(200, 50)
local shape2 = b2.PolygonShape.new() -- Water group 2
shape2:setAsBox(200, 50)
local ps1= world:createParticleSystem({ radius=5})
-- ps1:setTexture(Texture.new("Bubble.png"))
stage:addChild(ps1)
ps1:createParticleGroup(
{shape=shape2,
position={x=10,y=50},
color = 0xFF0000,
alpha=1,
flags=0
})
ps1:createParticleGroup(
{shape=shape1,
position={x=500,y=250},
color = 0x00FFFF,
alpha=1,
flags=0
})
local ps1= world:createParticleSystem({ radius=5})
ps1:setTexture(Texture.new("ball.png"))
stage:addChild(ps1)
-- step the world and then update the position and rotation of sprites
local function onEnterFrame()
a=a+1
world:step(1/60, 8, 3)
if a < 6000 then
shape1:setAsBox(10, 10)
ps1:createParticleGroup(
{shape=shape1,
position={x=200,y=200},
color = 0x00FFFF,
alpha=1,
flags=0
})
stage:addChild(ps1)
end
end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)