forked from andriikushch/game-off-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.js
49 lines (42 loc) · 1.24 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
var Bullet = new Phaser.Class({
Extends: Phaser.GameObjects.Image,
initialize:
// Bullet Constructor
function Bullet (scene)
{
Phaser.GameObjects.Image.call(this, scene, 0, 0, 'bullet');
this.speed = 0.1;
this.xSpeed = 0;
this.ySpeed = 0;
this.setSize(6, 6, true);
},
// Fires a bullet from the player to the reticle
fire: function (shooter, target)
{
this.setPosition(shooter.x, shooter.y); // Initial position
switch (shooter.directionOfMove) {
case "up":
this.ySpeed = -1*this.speed;
this.xSpeed = 0;
break;
case "down":
this.ySpeed = this.speed;
this.xSpeed = 0;
break;
case "left":
this.xSpeed = -1*this.speed;
this.ySpeed = 0;
break;
case "right":
this.xSpeed = this.speed;
this.ySpeed = 0;
break;
}
},
// Updates the position of the bullet each cycle
update: function (time, delta)
{
this.x += this.xSpeed * delta;
this.y += this.ySpeed * delta;
}
});