I need call sound for each object directly, but this code dont work for some reason
Slave = class()
--physics.pause()
function Slave:init(x)
local vecs = {vec2(0,0),vec2(0,130),vec2(30,130),vec2(0,0),vec2(30,0),vec2(30,130)}
self.skull = physics.body(CIRCLE,5)
self.skull.x = WIDTH/2
self.skull.y = 60
self.slaves = {}
self.time = 0
-- you can accept and set parameters here
--table to random time values, which will use below
self.jump = {}
for i = 1,5 do
self.slave = physics.body(POLYGON,unpack(vecs))
table.insert(self.slaves,self.slave)
--insert random values to make this guys jump
table.insert(self.jump,math.random(2,6))
self.slave.x = math.random(WIDTH/2-50,WIDTH/2+50)
self.slave.y = math.random(HEIGHT/2)
end
self.wallB = physics.body(EDGE,vec2(0,59),vec2(WIDTH,59))
self.wallB.restitution = 0.1
self.wallL = physics.body(EDGE,vec2(291,539),vec2(352,65))
self.wallL.restitution = 0.1
self.wallR = physics.body(EDGE,vec2(681,65),vec2(738,539))
self.wallL.restitution = 0.1
end
function Slave:draw()
-- Codea does not automatically call this method
self.time = self.time + DeltaTime
local time = math.floor(self.time)
local jump ={}
for i = 1,5 do
table.insert(jump,"SOUND_JUMP, 1")
end
for k,v in pairs(self.slaves) do
for a,b in pairs(self.jump) do
--here, this string makes random jumps for each man
if math.fmod(time,b) == 0 and a == k then
v.linearVelocity = v.linearVelocity + vec2(0,8)
--and here sound didnt appear, but must
sound(jump[a])
end
end
pushMatrix()
translate(v.x,v.y)
rotate(v.angle)
sprite("Documents:1111slave"..k,10,80,512/3,512/3)
popMatrix()
end
pushMatrix()
translate(self.skull.x,self.skull.y)
rotate(self.skull.angle)
sprite("Documents:1111Skull",0,0,512/17,512/17)
popMatrix()
end
function Slave:touched(touch)
-- Codea does not automatically call this method
end