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 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 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 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 NewstickGroup:translate(0, -960) end if Player1.x \> 1000 then endGame() elseif Player1.x \< -1000 then endGame() end end Runtime:addEventListener ("enterFrame", move) --Player Functions local function onTouch(event) if(event.phase == "ended") then transition.to(Player1, {x=event.x}) end end Runtime:addEventListener("touch", onTouch) -- LocalCollision local function onLocalCollision (self, event ) if ( event.phase == "began" ) then if (self.ID == "mainSquare" and event.other.ID == "Crash") then endGame() end 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