-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.js
More file actions
30 lines (27 loc) · 760 Bytes
/
bullet.js
File metadata and controls
30 lines (27 loc) · 760 Bytes
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
//bullet.js
var Bullet = function()
{
this.image = document.createElement("img");
this.position = new Vector2();
this.position.add(player.gunOffset);
this.position.add(player.position);
this.velocity = new Vector2(1, 0);
this.width = 0;
this.height = 0;
this.speed = 256;
this.rotation = player.rotation;
this.velocity.rotateDirection(this.rotation);
this.velocity.multiplyScalar(this.speed);
this.image.src = "bullet.png";
SetupImageEvents(this, this.image);
};
Bullet.prototype.update = function(deltaTime)
{
var posChange = this.velocity.copy();
posChange.multiplyScalar(deltaTime);
this.position.add(posChange);
};
Bullet.prototype.draw = function()
{
DrawImage(context, this.image, this.position.x, this.position.y, this.rotation);
}