Hi,
I have created 3 blocks and a moving ball who should collide with each of the blocks to get reset. It only works with 2/3. Can you please tell me the specific problem?
You can find the whole thing attached.
Please help me
I would like to create a mini game in a 2.5D environment, but for now I can cancel everything, because I’m stuck at this point.
Cheers
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar ) -- Physik physics = require ("physics") physics.start() physics.setGravity (0,0) physics.setDrawMode("hybrid") --[[local screenCenterX = display.contentWidth/2 local screenCenterY = display.contentHeight/2 local background = display.newImage("test.png",0,0,true) background.x = screenCenterX background.y = screenCenterY]]-- ---------------------------------------------------------------------- -- AUFBAU -- ---------------------------------------------------------------------- -- REIHEN -------------------------------------------------- local reihe2 = display.newImage("gfx/lane2.png",380,230,true) reihe2.rotation = 60 reihe1Shape = { 4,56, 86,9, 89,621, 7,669 } physics.addBody( reihe2, { density=3.0, friction=0.8, bounce=0.3, isSensor = true} ) reihe2.bodyType = "static" local reihe3 = display.newImage("gfx/lane3.png",570,340,true) reihe3.rotation = 60 reihe3Shape = { 4,56, 86,9, 89,621, 7,669 } physics.addBody( reihe3, { density=3.0, friction=0.8, bounce=0.3, isSensor = true} ) reihe3.bodyType = "static" -- DER BALLON local ballon = display.newImage("gfx/ballon.png",pos\_x,pos\_y,true) physics.addBody( ballon, { density=3.0, friction=0.8, bounce=0.3, isSensor = true} ) ballon.nr = 2 -- Koordinaten /ID Startpositionen Array local ball\_pos = {{102,428},{322,508},{682,528}} ballon.nr = math.random(1,3) ballon.x = ball\_pos[ballon.nr][1] ballon.y = ball\_pos[ballon.nr][2] ---------------------------------------------------------------- -- BLÖCKE ---------------------------------------------- -- Blöcke zum Kollidieren local block = display.newImage("gfx/block.png",400,200,true) blockShape = { 0,80, 0,-25, -41,-48, -41,56 } physics.addBody( block, { density=3.0, friction=0.8, bounce=0.3, shape=blockShape } ) block.bodyType = "static" block.nr = 1 local block\_2 = display.newImage("gfx/block.png",600,300,true) block\_2Shape = { 0,80, 0,-25, -41,-48, -41,56 } physics.addBody( block\_2, { density=3.0, friction=0.8, bounce=0.3, shape=block\_2Shape } ) block\_2.bodyType = "static" block\_2.nr = 2 local block\_3 = display.newImage("gfx/block.png",800,400,true) block\_3Shape = { 0,80, 0,-25, -41,-48, -41,56 } physics.addBody( block\_3, { density=3.0, friction=0.8, bounce=0.3, shape=block\_3Shape } ) block\_3.bodyType = "static" block\_3.nr = 3 -------------------------------------------------------------- local pos\_x = ball\_pos[ballon.nr][1] local pos\_y = ball\_pos[ballon.nr][2] local function hitblock (event) if (event.target.nr == event.other.nr) then print("Treffer") ballon.nr = math.random(1,3) pos\_x = ball\_pos[ballon.nr][1] pos\_y = ball\_pos[ballon.nr][2] -- else end end block:addEventListener( "collision", hitblock ) block\_2:addEventListener( "collision", hitblock ) block\_3:addEventListener( "collision", hitblock ) local function movingobject(event) pos\_y = pos\_y-1 pos\_x = pos\_x+2 ballon.x = pos\_x ballon.y = pos\_y end Runtime:addEventListener("enterFrame", movingobject)