I’m disappointed to read this. It is a terrible idea and totally defeats the purpose of the content and instruction I’ve given you so far.
If you can’t use the game.lua construct I gave you and understand the concepts of scope, visibility, group layering, the painters-algorithm,… you are going to find yourself in the same place you started this thread.
How do i give the zombie a body so when the bullet hits the zombie the users points go up by 5 points . I tried to use isBullet but that didn’t help . It made no change at all
I tried to add a body and the zombie is just falling down .
zombie = display.newSprite( imageSheet, sequenceData ) physics.addBody( zombie, {density=3.0} )
local Coins = 0 local centerX = 350 local centerY = 60 local CoinsTxt = display.newText( "Coins: "..Coins, centerX, centerY, native.systemFontBold, 20 ) end local bullet = {} local bCounter = 1 local function shootBullet(event) if event.phase == "ended" then bullet[bCounter] = display.newImage( "bullet5.png", 40, 298, 1, 6) bullet[bCounter].value = bCounter physics.addBody( bullet[bCounter], "dynamic" ) bullet[bCounter].gravityScale = 0 bullet[bCounter].myName = "bullet" bullet[bCounter]:setLinearVelocity( 2100, -20 ) bCounter = bCounter + 1 end end local function onCollision( self, event ) if event.phase =="began" then Coins = Coins + 5 CoinsTxt.text="Coins: "..Coins end end function game.start( ) -- Game is already started, just exit if( isRunning ) then return end -- Mark game as running isRunning = true gun:addEventListener( "touch", shootBullet ) end
Whenever I add an event listener for the zombie I get a couple of errors
You should put you game on Pause, then go read the physics guide and poke around the physics examples that come with Corona till you understand:
bodies
gravity
linearVelocity
forces
…
After that you’ll be able to understand why your zombie ‘falls’ when you add a body. Till then, us just telling you won’t help a lot. It will only move you forward incrementally.
Note: Your effort has inspired me (still thinking about it) to make a side-scroller template. I’ll post back here if I make it OK?