I really need help with my game!

Hello, I really need help with my game! The problem is that the player won’t die and I can’t seem to find out how to add more enemies going down from the screen to kill the Player?  May anyone please help me my code is in the bottom for game.lua please help!

--Setting Locals&nbsp;local composer = require ("composer") local scene = composer.newScene() local physics = require( "physics" ) physics.start() local \_W = display.contentWidth local \_H = display.contentHeight local scrollSpeed = 7 local Newmovedstick = 30 --storyboard CREATE SCENE function scene:create(event) stickGroup = display.newGroup() gameGroup = display.newGroup() NewstickGroup = display.newGroup() local stick1 = display.newImageRect(stickGroup, "Images/Game/stick1.jpg", 260, 10) stickGroup:insert(stick1) stick1.x = 20 stick1.y = 155 physics.addBody (stick1, "static") stick1.ID = "Crash" local stick2 = display.newImageRect(stickGroup, "Images/Game/stick2.jpg", 260, 10) stickGroup:insert(stick2) stick2.x = 350 stick2.y = 155 physics.addBody (stick2, "static") stick2.ID = "Crash" local baseBottom = display.newImageRect(gameGroup,"Images/Game/baseBottom.jpg", 1000, 10) baseBottom.x = 160 baseBottom.y = 480 gameGroup:insert(baseBottom) physics.addBody (baseBottom, "static") --If you put Player1 into gameGroup it will remove the cool animation when Player falls local Player1 = display.newImage("Images/Game/Player.jpg") Player1.x = 180 Player1.y = 479 Player1.ID = "mainSquare" physics.addBody (Player1, "dynamic") local function createSticks() local Newstick1 = display.newImageRect(NewstickGroup, "Images/Game/Newstick1.jpg", 260, 10) NewstickGroup:insert(Newstick1) Newstick1.x = 20 Newstick1.y = 60 physics.addBody (Newstick1, "static") Newstick1.ID = "Crash" local Newstick2 = display.newImageRect(NewstickGroup, "Images/Game/Newstick2.jpg", 260, 10) NewstickGroup:insert(Newstick2) Newstick2.x = 350 Newstick2.y = 60 physics.addBody (Newstick2, "static") Newstick2.ID = "Crash" local whereFrom = math.random( 1 ) if ( whereFrom == 1 ) then NewstickGroup.x = NewstickGroup.x + Newmovedstick end if NewstickGroup.x \> 100 then&nbsp; NewstickGroup.x = Newmovedstick - NewstickGroup.x end end local function move() --This moves the stickGroup ONLY (the first sticks in the game) stickGroup.y = stickGroup.y + scrollSpeed if(stickGroup.y + stickGroup.contentWidth) \> 1040 then&nbsp; stickGroup:translate(0, -960) creatingSticksTimer = timer.performWithDelay( 5000, createSticks) end --This moves the NEWstickGroup ONLY (the placed sticks in the game) NewstickGroup.y = NewstickGroup.y + scrollSpeed if(NewstickGroup.y + NewstickGroup.contentWidth) \> 1040 then&nbsp; NewstickGroup:translate(0, -960) end if Player1.x \> 1000 then endGame()&nbsp; elseif Player1.x \< -1000 then endGame() end end Runtime:addEventListener ("enterFrame", move) --Player Functions local function onTouch(event) if(event.phase == "ended") then&nbsp; transition.to(Player1, {x=event.x}) end end Runtime:addEventListener("touch", onTouch) -- LocalCollision local function onLocalCollision (self, event ) &nbsp; &nbsp; if ( event.phase == "began" ) then &nbsp; &nbsp; if (self.ID == "mainSquare" and event.other.ID == "Crash") then &nbsp; &nbsp; endGame() &nbsp; &nbsp; end &nbsp; &nbsp; end end --End Game local function endGame() Player1:removeEventListener( "collision", Player1) Runtime:removeEventListener ("enterFrame", move) Runtime:removeEventListener("touch", onTouch) display.remove( gameGroup ) gameGroup = nil display.remove( stickGroup ) stickGroup = nil --timer.cancel( creatingSticksTimer ) composer.removeScene( "game" ) composer.gotoScene("restart") end Player1.collision = onLocalCollision Player1:addEventListener( "collision", Player1) end scene:addEventListener( "create", scene ) return scene

So in all for can anyone help me with the problem that I have with my game! I still cannot find out how to solve it! Can anyone reach out and guide me!

1.  Only ask one question per post.  Nobody likes to answer 2 and more unrelated questions in a post.  It is too much work for the answering party.

  1. I will help you with the ‘not getting collisions’ problem.

I see that you are:

  • putting objects in separate groups
  • moving those groups to move the objects.

This won’t work.  The physics system requires that all objects have the same ‘base coordinates’.  i.e. While the objects may be in different groups, those groups must have their <0,0> at the same place.  

In short, you need to move the objects, not the groups.

Additionally, you should be using velocities and forces, not manually changing the <x,y> position of the objects.  While this may ‘kind of’ work, it wont’ work consistently.  

The physics engine is no aware of your changes and if the object has gone to sleep (a physics optimization) it will not see the manual update.

PS - Don’t move static objects.  They must stay in place.  If you need to move an object an not have it react to gravity and other forces, make the body ‘kinematic’, not ‘static’.

Thank You RoamingGamer, I managed to fix the collision problems and also made the player die once again. But, this is another topic which is how to make the sticks(enemy) move from the x-axis down for the player while making more sticks come from the top going down until the player dies.  It’ll start slow then end fast! I will make another topic of a guide in the meantime ill figure it out my self.  If you have any information about this please also guide me that would help me a lot.  Bye and Thank You!

please start a new thread

One topic per thread

I don’t answer meandering posts all in the same thread.  It invalidates the value of a thread to future readers which goes against my purpose here.

So in all for can anyone help me with the problem that I have with my game! I still cannot find out how to solve it! Can anyone reach out and guide me!

1.  Only ask one question per post.  Nobody likes to answer 2 and more unrelated questions in a post.  It is too much work for the answering party.

  1. I will help you with the ‘not getting collisions’ problem.

I see that you are:

  • putting objects in separate groups
  • moving those groups to move the objects.

This won’t work.  The physics system requires that all objects have the same ‘base coordinates’.  i.e. While the objects may be in different groups, those groups must have their <0,0> at the same place.  

In short, you need to move the objects, not the groups.

Additionally, you should be using velocities and forces, not manually changing the <x,y> position of the objects.  While this may ‘kind of’ work, it wont’ work consistently.  

The physics engine is no aware of your changes and if the object has gone to sleep (a physics optimization) it will not see the manual update.

PS - Don’t move static objects.  They must stay in place.  If you need to move an object an not have it react to gravity and other forces, make the body ‘kinematic’, not ‘static’.

Thank You RoamingGamer, I managed to fix the collision problems and also made the player die once again. But, this is another topic which is how to make the sticks(enemy) move from the x-axis down for the player while making more sticks come from the top going down until the player dies.  It’ll start slow then end fast! I will make another topic of a guide in the meantime ill figure it out my self.  If you have any information about this please also guide me that would help me a lot.  Bye and Thank You!

please start a new thread

One topic per thread

I don’t answer meandering posts all in the same thread.  It invalidates the value of a thread to future readers which goes against my purpose here.