@@ -10,6 +10,7 @@ class Boot extends Phaser.Scene {
10
10
preload ( ) {
11
11
this . load . image ( "arwing" , "assets/arwing.png" ) ;
12
12
this . load . image ( "background" , "assets/sky.jpg" ) ;
13
+ this . load . image ( "laser" , "assets/charmander.png" ) ;
13
14
}
14
15
15
16
create ( ) {
@@ -44,7 +45,9 @@ class Ship extends Phaser.GameObjects.Sprite {
44
45
this . MAX_SPEED = 5 ;
45
46
this . speedlazerScene = scene ;
46
47
scene . add . existing ( this ) ;
47
- this . scaleX = + - 1 ;
48
+ this . scaleX = - 1 ;
49
+
50
+ this . laser = null ;
48
51
}
49
52
50
53
create ( ) {
@@ -64,11 +67,12 @@ class Ship extends Phaser.GameObjects.Sprite {
64
67
spacebar : this . speedlazerScene . input . keyboard . addKey ( KEYS . spacebar )
65
68
} ;
66
69
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.
71
73
} ) ;
74
+
75
+ // console.log(this.laser);
72
76
}
73
77
74
78
update ( ) {
@@ -81,26 +85,53 @@ class Ship extends Phaser.GameObjects.Sprite {
81
85
} else if ( this . key . right . isDown ) {
82
86
this . x += this . MAX_SPEED ;
83
87
} 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 ( ) ;
89
89
}
90
90
}
91
91
}
92
92
93
- class Bullet extends Phaser . GameObjects . Sprite {
93
+ class Laser extends Phaser . GameObjects . Sprite {
94
94
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 ;
96
102
}
97
103
98
104
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 ;
101
110
}
102
111
}
103
112
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
+
104
135
const config = {
105
136
type : Phaser . AUTO ,
106
137
width : 800 ,
0 commit comments