-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeroController.js
More file actions
121 lines (97 loc) · 3.08 KB
/
Copy pathHeroController.js
File metadata and controls
121 lines (97 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function HeroController() {
this._isRunning = false;
}
HeroController.SPEED = 300;
HeroController.prototype = {
constructor: HeroController,
moveLeft: function (dt) {
this._playWalkAnimation();
this.sprite.setFlipX(true);
var pos = this.rootNode.getPosition(),
halfWidth = this.rootNode.getContentSize().width / 2;
pos.x -= HeroController.SPEED * dt;
if (pos.x - halfWidth <= 60) {
pos.x = 60 + halfWidth;
}
this.rootNode.setPosition(pos);
if (this._bomb) {
this._bomb.setPosition(pos);
}
},
moveRight: function (dt) {
this._playWalkAnimation();
this.sprite.setFlipX(false);
var pos = this.rootNode.getPosition(),
halfWidth = this.rootNode.getContentSize().width / 2;
pos.x += HeroController.SPEED * dt;
if (pos.x + halfWidth > 840) {
pos.x = 840 - halfWidth;
}
this.rootNode.setPosition(pos);
if (this._bomb) {
this._bomb.setPosition(pos);
}
},
stop: function() {
if (!this._isRunning) {
return;
}
var animation = this.isCarryingBomb() ? 'stand_bomb' : 'stand';
this.rootNode.animationManager.runAnimationsForSequenceNamed(animation);
this._isRunning = false;
},
_playWalkAnimation: function() {
if (this._isRunning) {
return;
}
var animation = this.isCarryingBomb() ? 'run_bomb' : 'run';
this.rootNode.animationManager.runAnimationsForSequenceNamed(animation);
this._isRunning = true;
},
updateAction: function(action) {
this.actionLabel.setString(action);
if (!action || action.length === 0) {
this.actionLabel.setVisible(false);
} else {
this.actionLabel.setVisible(true);
}
},
pickBomb: function(bomb) {
this._bomb = bomb;
this.timerLabel.setVisible(true);
this.timerLabel.setString(bomb.controller.counter);
bomb.removeFromParent(false);
},
onBombTick: function() {
if (this.isCarryingBomb()) {
this.timerLabel.setString(this._bomb.controller.counter);
}
},
isCarryingBomb: function(bomb) {
if (bomb) {
return this._bomb === bomb;
}
return !!this._bomb;
},
dropBomb: function () {
var bomb = this._bomb;
this._bomb = null;
this._isRunning = !this._isRunning;
this.timerLabel.setVisible(false);
return bomb;
},
removeBombIfCarrying: function (bomb) {
if (this.isCarryingBomb(bomb)) {
this._bomb = null;
this._isRunning = !this._isRunning;
this.timerLabel.setVisible(false);
}
},
animateHit: function() {
this.rootNode.runAction(cc.Blink.create(1, 4));
//this.rootNode.animationManager.runAnimationsForSequenceNamed('flicker');
},
animateShout: function() {
this.rootNode.animationManager.runAnimationsForSequenceNamed('shout');
}
};