-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.js
93 lines (59 loc) · 1.64 KB
/
Bullet.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
// ======
// BULLET
// ======
"use strict";
/* jshint browser: true, devel: true, globalstrict: true */
/*
0 1 2 3 4 5 6 7 8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
// A generic contructor which accepts an arbitrary descriptor object
function Bullet(descr) {
// Common inherited setup logic from Entity
this.setup(descr);
// Make a noise when I am created (i.e. fired)
this.fireSound.play();
/*
// Diagnostics to check inheritance stuff
this._bulletProperty = true;
console.dir(this);
*/
}
Bullet.prototype = new Entity();
// HACKED-IN AUDIO (no preloading)
Bullet.prototype.fireSound = new Audio(
"sounds/bulletFire.ogg");
Bullet.prototype.zappedSound = new Audio(
"sounds/bulletZapped.ogg");
// Initial, inheritable, default values
Bullet.prototype.cx = 200;
Bullet.prototype.cy = -300;
Bullet.prototype.velX = 1;
Bullet.prototype.velY = 1;
Bullet.prototype.update = function (du) {
// TODO: YOUR STUFF HERE! --- Unregister and check for death
this.cx += this.velX * du;
this.cy += this.velY * du;
if(this.collidesWithWall())
return entityManager.KILL_ME_NOW
if(this.collidesWithBall())
return entityManager.KILL_ME_NOW
};
Bullet.prototype.getRadius = function () {
return 4;
};
Bullet.prototype.collidesWithWall = function () {
//Hit the wall
if((this.cy - g_sprites.bullet.height/2) < 0)
return true
else
return false
};
Bullet.prototype.collidesWithBall = function () {
return false
};
Bullet.prototype.render = function (ctx) {
g_sprites.bullet.drawWrappedCentredAt(
ctx, this.cx, this.cy, 0
);
};