-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprites.js
185 lines (171 loc) · 5.48 KB
/
sprites.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"use strict";
(function(){
var G = (window.FireGame = window.FireGame || {});
var sprites = G.sprites = {};
var MG = MajicGame;
var U = MajicUnits;
var Bh = MG.behavior;
var GBh = G.behavior;
sprites.Background = MG.makeSpriteClass({
draw: G.art.drawBackground
});
var aR = G.areaRect;
sprites.Floater = MG.makeSpriteClass({
x: U.pixels( 600 ).relax()
, y: U.pixels( 500 ).relax()
, speed: U.pixels( 100 ).per.second
, draw: G.art.drawFloater
, fadeRate: U.units( 20 ).per.second
, initSprite: function(obj) {
this.mergeData(obj);
this.cX = this.x;
this.cY = this.y;
}
, spawn: function() {
// Point at player
var p = G.state.player;
var rot = Math.atan2(p.x - this.x, p.y - this.y);
this.h = this.speed.mul( Math.sin(rot) );
this.v = this.speed.mul( Math.cos(rot) );
}
, onDie: function(handler) {
this.deathListeners = this.deathListeners || [];
this.deathListeners.push(handler);
}
, behavior: [
GBh.fadeSpriteFrames
//, GBh.pace
, Bh.momentum
, Bh.bouncingBounds(aR)
]
});
sprites.Magnesium = MG.makeSpriteClass({
spriteFrames: 'magnesia'
, fadeRate: U.units( 15 ).per.second
}, sprites.Floater);
sprites.Infantry = MG.makeSpriteClass({
spriteFrames: 'infantry'
, fadeRate: U.units( 10 ).per.second
}, sprites.Floater);
sprites.GreaseFire = MG.makeSpriteClass({
spriteFrames: 'sparky'
, fadeRate: U.units( 10 ).per.second
}, sprites.Floater);
sprites.Player = MG.makeSpriteClass({
height: 80
, width: 80
, draw: G.art.drawPlayer
, scale: 80/96
, initSprite: function(config) {
this.mergeData(config);
var bounds = {
t: U.pixels( this.height/2 ).relax()
, l: U.pixels( this.width/2 ).relax()
, b: U.pixels( G.state.area.h - this.height/2 ).relax()
, r: U.pixels( G.state.area.w - this.width/2 ).relax()
};
this.behavior.push( Bh.boundsStop(bounds) );
}
, behavior: [
Bh.momentum
, Bh.thrustKeys(
{
forward: ['w', 'ArrowUp']
, back: ['s', 'ArrowDown']
, left: ['a', 'ArrowLeft']
, right: ['d', 'ArrowRight']
}
, U.pixels( 1200 ).per.second.per.second
)
, Bh.friction( U.pixels( 440 ).per.second.per.second )
, Bh.speedLimited( U.pixels( 260 ).per.second )
]
});
sprites.Particle = MG.makeSpriteClass({
size: U.pixels(15)
, speed: U.pixels( 500 ).per.second
, color: 'blue'
, startFade: U.seconds(1)
, fadeTime: U.seconds(0.2)
, initSprite: function(fromPos, atPos) {
var x1 = fromPos.x.as( U.pixels );
var y1 = fromPos.y.as( U.pixels );
var x2 = atPos.x.as( U.pixels );
var y2 = atPos.y.as( U.pixels );
var rot = Math.atan2(x2-x1, y2-y1);
this.h = this.speed.mul( Math.cos(rot) );
this.v = this.speed.mul( Math.sin(rot) );
this.x = x1;
this.y = y1;
this.started = G.gm.timeElapsed;
}
, behavior: [
Bh.momentum
, GBh.particleFade
]
});
sprites.DeviceSelector = MG.makeSpriteClass({
draw: G.art.drawSelector
, deviceSize: U.pixels( 60 )
, devices: [
{tag: 'dev:water', color: 'green', sound: 'waterfoam'}
, {tag: 'dev:powder', color: 'white', sound: 'drypowder'}
, {tag: 'dev:chem', color: 'blue', sound: 'drychem'}
]
, selected: 0
, behavior: [
GBh.selectKey('Tab')
]
});
sprites.Spawner = MG.makeSpriteClass({
draw: G.art.drawSpawner
, handles: function(classIn) {
return (classIn == this.spawnClass);
}
});
sprites.SpawnPoints = MG.makeSpriteClass({
draw: G.art.drawSpawnPoints
, spawners: [
// Infantry
new sprites.Spawner({
x: U.pixels( 300 ).relax()
, y: U.pixels( 500 ).relax()
, spawnClass: sprites.Infantry
//, gfx: 'lab'
//, scale: 0.4
})
// GreaseFire
, new sprites.Spawner({
x: U.pixels( 600 ).relax()
, y: U.pixels( 700 ).relax()
, spawnClass: sprites.GreaseFire
, gfx: 'kitchen'
, scale: 0.4
})
// Magnesium
, new sprites.Spawner({
x: U.pixels( 850 ).relax()
, y: U.pixels( 300 ).relax()
, spawnClass: sprites.Magnesium
, gfx: 'lab'
, scale: 0.4
})
]
, behavior: [
GBh.spawning
]
, initSprite(obj) {
this.mergeData(obj);
var mk = new MajicKeys;
mk.onDown('\b', handler);
mk.onDown('Backspace', handler);
var self = this;
function handler() {
if (self.spriteCollection && self.spriteCollection.length != 0) {
self.spriteCollection.shift();
createjs.Sound.play('fwoosh');
}
}
}
});
})();