Shooting a gun

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.

@Brandon,

I hope this gets you going again: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/12/brandonCombining.zip

(_ may take a while to process to full resolution _)

https://www.youtube.com/watch?v=Or9wqO1cuOk&feature=youtu.be

I posted the wrong video but now the links right.  Please wait for it to finish processing.

It’s still not showing up . It says the video is unavailable 

Try it now.

Great I fixed it 

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

You need to learn about collision detection next and detect when the bullet hits the zombie.  See:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Rob

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 

@Brandon,

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?

Sure no problem .

OHHHH I had to add a static body 

When I shoot the gun it doesn’t touch the zombie . It’s like it touches the air around the zombie and bounces back .

Okay I fixed it all . Thanks to everyone who helped .

I want to make a bomb explosion . Do I do that witht he same code for the zombie ? I already have the sprite sheets