-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSmokeSFX.js
More file actions
121 lines (106 loc) · 3.06 KB
/
SmokeSFX.js
File metadata and controls
121 lines (106 loc) · 3.06 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
var SmokeSFX = (function () {
var states = {
DOWN: 0,
UP: 1,
STRAIGHT: 3
};
var LIFE_TIME = .4;
var UPDATE_RATE = 7;
function SmokeSFX () {
this.vy = -30;
this.imperviousToShootingRay = false;
this.inUse = false;
this.lifeTime = 0;
this.width = 16;
this.height = 16;
this.state = states.STRAIGHT;
this.idleTimeDuration = Game.calculateFrameDuration(UPDATE_RATE);
this.affectedByGravity = false;
this.imperviousToShootingRay = false;
this.spriteImg = resources.get('player');
this.animations = [];
this.initAnimations();
};
SmokeSFX.prototype = new Character();
SmokeSFX.prototype.beforePositionUpdate = function (dt) {
this.lifeTime += dt;
if(this.lifeTime >= LIFE_TIME) {
this.inUse = false;
this.lifeTime = 0;
}
};
SmokeSFX.prototype.spawn = function (x, y) {
this.x = x - this.width * .5;
this.y = y;
this.inUse = true;
this.lifeTime = 0;
var animation = this.getAnimation();
if(animation) { animation.reset(); }
};
SmokeSFX.prototype.render = function (viewportContext) {
var animation = this.getAnimation();
if(animation) {
animation.render(viewportContext, Math.floor(this.x), Math.floor(this.y));
}
};
SmokeSFX.prototype.switchToUp = function () {
this.state = states.UP;
};
SmokeSFX.prototype.switchToDown = function () {
this.state = states.DOWN;
};
SmokeSFX.prototype.switchToStraight = function () {
this.state = states.STRAIGHT;
};
SmokeSFX.prototype.initAnimations = function () {
this.animations[states.DOWN] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 3071
},
{
x: 3167
}
],
width: this.width,
height: this.height,
repeat: false,
frames: 2,
animSpeed: UPDATE_RATE
}));
this.animations[states.UP] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 3103
},
{
x: 3199
}
],
width: this.width,
height: this.height,
repeat: false,
frames: 2,
animSpeed: UPDATE_RATE
}));
this.animations[states.STRAIGHT] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 3135
},
{
x: 3231
}
],
width: this.width,
height: this.height,
repeat: false,
frames: 2,
animSpeed: UPDATE_RATE
}));
};
return SmokeSFX;
})();