-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerup.js
62 lines (49 loc) · 1.33 KB
/
Powerup.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
// ==========
// POWERUP
// ==========
"use strict";
/* jshint browser: true, devel: true, globalstrict: true */
/*
0 1 2 3 4 5 6 7 8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
// A rectangle collision object for walls
function Powerup(cx, cy, typeOf) {
// Common inherited setup logic from Entity
this.setup();
this.sprite = typeOf == 'multiGun' ? g_sprites.multiPower : g_sprites.superGun;
this.cx = cx;
this.cy = cy;
this.typeOf = typeOf;
this.killMe = false;
};
Powerup.prototype = new Entity();
Powerup.prototype.velX = 0.75;
Powerup.prototype.getRadius = function () {
return {
width: this.sprite.width*1.5,
height: this.sprite.height*1.5
};
};
Powerup.prototype.update = function (du) {
spatialManager.unregisterSq(this);
if (this.killMe) {
return entityManager.KILL_ME_NOW;
}
//Update position
if (!this.halt) {
this.cx -= this.velX * du;
}
//Kill powerup if it is off the screen
if (this.cx < 0) {
return entityManager.KILL_ME_NOW;
}
spatialManager.registerSq(this);
};
Powerup.prototype.collideWithShip = function () {
//Kill the powerup entity
this.killMe = true;
}
Powerup.prototype.render = function (ctx) {
this.sprite.drawAt(ctx, this.cx, this.cy, this.rotation);
};