PlayerController.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // 角色逻辑控制
  2. var GameStates = require('GameStates');
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. this.GameMode = this.node.parent.getComponent('GameMode')
  10. this.GameCanvas = this.node.parent.getComponent('GameCanvas')
  11. },
  12. start () {
  13. },
  14. onBeginContact: function (contact, selfCollider, otherCollider) {
  15. cc.log(otherCollider.node.name)
  16. if(otherCollider.node.name=='fruitPrefab'){
  17. this.GameMode.addTool(otherCollider.node)
  18. setTimeout(function(){
  19. otherCollider.node.destroy()
  20. }.bind(this),300)
  21. }
  22. if(otherCollider.node.name=='PipeBody'){
  23. this.node.getChildByName('Scream').active = true
  24. setTimeout(function(){
  25. this.node.getChildByName('Scream').active = false
  26. }.bind(this),1000)
  27. }
  28. if(otherCollider.node.name=='DestinationFlag'){
  29. this.GameCanvas.gameOver(1,GameStates.gameScore,GameStates.gameTime)
  30. this.node.getComponent(cc.RigidBody).gravityScale = 0
  31. this.node.getComponent(cc.RigidBody).linearVelocity = cc.v2(0,0)
  32. }
  33. },
  34. // onEndContact: function (contact, selfCollider, otherCollider) {
  35. // },
  36. });