lifeManager.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. index: {
  14. default: 0,
  15. type:cc.Integer,
  16. }
  17. // foo: {
  18. // // ATTRIBUTES:
  19. // default: null, // The default value will be used only when the component attaching
  20. // // to a node for the first time
  21. // type: cc.SpriteFrame, // optional, default is typeof default
  22. // serializable: true, // optional, default is true
  23. // },
  24. // bar: {
  25. // get () {
  26. // return this._bar;
  27. // },
  28. // set (value) {
  29. // this._bar = value;
  30. // }
  31. // },
  32. },
  33. // LIFE-CYCLE CALLBACKS:
  34. onLoad () {
  35. this._init()
  36. },
  37. start () {
  38. },
  39. _init(){
  40. lifes[this.index] = this
  41. this.life = this.getComponent(cc.ProgressBar);
  42. this.Defend = UtilsNode.getNode("Defend",this.node)
  43. //防御值
  44. this.Defendlife = this.Defend.getComponent(cc.ProgressBar);
  45. this.initLife()
  46. },
  47. //初始化 血量 和防御值
  48. initLife(){
  49. this.life.progress = 1
  50. this.Defendlife.progress = 1
  51. },
  52. getLife(){
  53. // Log.info("现在得到的是",this.life.totalLength);
  54. // Log.info("现在得到的是",this.life.progress);
  55. return this.life.progress*100
  56. },
  57. //
  58. addLife(num,callback){
  59. // Log.info("现在得到的是",this.life.totalLength);
  60. // Log.info("现在得到的是",this.life.progress);
  61. var temp = this.life.progress*100+num
  62. this.life.progress= (this.life.progress*100+num)/100
  63. if (temp <= 0) {
  64. if (callback) {
  65. callback(this.index);
  66. return
  67. }
  68. }else{
  69. }
  70. },
  71. addDefendLife(num,callback){
  72. // Log.info("现在得到的是",this.life.totalLength);
  73. // Log.info("现在得到的是",this.life.progress);
  74. var temp = this.Defendlife.progress*100+num
  75. this.Defendlife.progress= (this.Defendlife.progress*100+num)/100
  76. if (temp <= 0) {
  77. if (callback) {
  78. callback(this.index);
  79. this.Defendlife.progress = 1
  80. return
  81. }
  82. }else{
  83. }
  84. },
  85. update (dt) {
  86. if (!gameManager.getGameType()) {
  87. if (this.Defendlife) {
  88. if (this.Defendlife.progress*100<100) {
  89. this.Defendlife.progress+=0.0005
  90. }else{
  91. this.Defendlife.progress = 1
  92. }
  93. }
  94. }else{
  95. }
  96. },
  97. });