Skip to content

Commit f73446a

Browse files
committed
Pew pew charmanders.
1 parent 1f606f2 commit f73446a

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

src/index.js

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Boot extends Phaser.Scene {
1010
preload() {
1111
this.load.image("arwing", "assets/arwing.png");
1212
this.load.image("background", "assets/sky.jpg");
13+
this.load.image("laser", "assets/charmander.png");
1314
}
1415

1516
create() {
@@ -44,7 +45,9 @@ class Ship extends Phaser.GameObjects.Sprite {
4445
this.MAX_SPEED = 5;
4546
this.speedlazerScene = scene;
4647
scene.add.existing(this);
47-
this.scaleX = +-1;
48+
this.scaleX = -1;
49+
50+
this.laser = null;
4851
}
4952

5053
create() {
@@ -64,11 +67,12 @@ class Ship extends Phaser.GameObjects.Sprite {
6467
spacebar: this.speedlazerScene.input.keyboard.addKey(KEYS.spacebar)
6568
};
6669

67-
this.bullets = this.speedlazerScene.add.group({
68-
classType: Bullet,
69-
key: "bullet",
70-
runChildUpdate: true
70+
this.laser = this.speedlazerScene.add.group({
71+
classType: Laser,
72+
runChildUpdate: true // runs the update function from the specified class.
7173
});
74+
75+
// console.log(this.laser);
7276
}
7377

7478
update() {
@@ -81,26 +85,53 @@ class Ship extends Phaser.GameObjects.Sprite {
8185
} else if (this.key.right.isDown) {
8286
this.x += this.MAX_SPEED;
8387
} else if (this.key.spacebar.isDown) {
84-
let bullet = this.bullets.get();
85-
86-
if (bullet) {
87-
bullet.fire();
88-
}
88+
this.laser.get().fire();
8989
}
9090
}
9191
}
9292

93-
class Bullet extends Phaser.GameObjects.Sprite {
93+
class Laser extends Phaser.GameObjects.Sprite {
9494
constructor(scene) {
95-
super(scene, 0, 0, "bullet");
95+
super(scene, 0, 0, "laser");
96+
scene.add.existing(this);
97+
this.scene = scene;
98+
this.scaleX = 0.1;
99+
this.scaleY = 0.1;
100+
this.x = scene.ship.x;
101+
this.y = scene.ship.y;
96102
}
97103

98104
fire() {
99-
/* eslint-disable no-console */
100-
console.log("IMMA FIRIN MA BULLETS");
105+
// console.log("Fire...", this.scene);
106+
}
107+
108+
update() {
109+
this.x += 5;
101110
}
102111
}
103112

113+
// class Bullet extends Phaser.GameObjects.Sprite {
114+
// constructor(scene) {
115+
// super(scene, 0, 0, "bullet");
116+
// console.log(this);
117+
// this.scaleX = 0.1;
118+
// this.scaleY = 0.1;
119+
// this.x = 300;
120+
// this.y = 300;
121+
// this.speed = Phaser.Math.GetSpeed(400, 1);
122+
// // this.setVisible(true);
123+
// // this.x = 125;
124+
// // this.visible = false;
125+
// }
126+
//
127+
// fire(shipPosition) {
128+
// this.visible = true;
129+
// this.x += this.speed * 100;
130+
// /* eslint-disable no-console */
131+
// console.log("IMMA FIRIN MA BULLETS");
132+
// }
133+
// }
134+
104135
const config = {
105136
type: Phaser.AUTO,
106137
width: 800,

0 commit comments

Comments
 (0)