Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --PLAYER STATE SETTINGS
- local STATE_IDLE = "playerStill"
- local STATE_WALKING = "playerWalk"
- local STATE_JUMPING = "playerJump"
- local DIRECTION_LEFT = -1
- local DIRECTION_RIGHT = 1
- local player = loader:spriteWithUniqueName("Player")
- -------------------------------------------------------------------------------------
- --BUTTON PART
- local buttonJumpPress = function( event )
- if event.phase == "began" then
- if player.canJump == true then
- audio.play( boingSound, { channel= 3 } )
- player:applyLinearImpulse(0, -10, player.x, player.y)
- player:startAnimationWithUniqueName(player.state);
- elseif event.phase == "ended" then
- player:startAnimationWithUniqueName(player.state);
- end
- end
- end
- ---------------------------------------------------------------------------------------
- --COLLISION PART
- local function onLocalCollision( self, event )
- if ( event.phase == "began" ) then
- if(event.other.lhTag == LevelHelper_TAG.GROUND) then
- player.canJump = true
- player:startAnimationWithUniqueName(player.state, player)
- end
- if(event.other.lhTag == LevelHelper_TAG.GOLD) then
- score:addPoints(50)
- score:addToBag("gold_can")
- loader:removeSprite(event.other)
- end
- if(event.other.lhTag == LevelHelper_TAG.CHEST) then
- score:addPoints(200)
- score:addToBag("chest")
- loader:removeSprite(event.other)
- end
- if(event.other.lhTag == LevelHelper_TAG.KEY) then
- print( "Youve got the key " )
- score:addPoints(100)
- score:addToBag("key")
- loader:removeSprite(event.other)
- end
- if(event.other.lhTag == LevelHelper_TAG.ENEMY) then
- print("enemy colide registred")
- goToRestartMenu()
- end
- if(event.other.lhTag == LevelHelper_TAG.CHECKPOINT) then
- print("Next level please")
- player.collision = nil
- goToNextLevel()
- return
- end
- elseif ( event.phase == "ended" ) then
- if (event.other.lhTag == LevelHelper_TAG.GROUND) then
- player.canJump = false
- end
- end
- end
- player.collision = onLocalCollision
- player:addEventListener( "collision", player )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement