@@ -7,16 +7,23 @@ function preload() {
77 game . load . image ( 'bullet' , 'assets/misc/bullet0.png' ) ;
88 game . load . image ( 'alien' , 'assets/sprites/space-baddie.png' ) ;
99 game . load . image ( 'ship' , 'assets/sprites/shmup-ship.png' ) ;
10+ game . load . spritesheet ( 'kaboom' , 'assets/games/tanks/explosion.png' , 64 , 64 , 23 ) ;
11+ game . load . image ( 'starfield' , 'assets/misc/starfield.jpg' ) ;
1012
1113}
1214
1315var player ;
1416var aliens ;
1517var bullets ;
1618var bulletTime = 0 ;
19+ var cursors ;
20+ var fireButton ;
21+ var explosions ;
1722
1823function create ( ) {
1924
25+ s = game . add . tileSprite ( 0 , 0 , 800 , 600 , 'starfield' ) ;
26+
2027 player = game . add . sprite ( 400 , 500 , 'ship' ) ;
2128 player . anchor . setTo ( 0.5 , 0.5 ) ;
2229
@@ -33,21 +40,29 @@ function create() {
3340 aliens . x = 100 ;
3441 aliens . y = 50 ;
3542
36- bullets = game . add . group ( null , 'bullets' ) ;
43+ // Our bullet group
44+ bullets = game . add . group ( ) ;
45+ bullets . createMultiple ( 30 , 'bullet' ) ;
46+ bullets . setAll ( 'anchor.x' , 0.5 ) ;
47+ bullets . setAll ( 'anchor.y' , 1 ) ;
48+ bullets . setAll ( 'outOfBoundsKill' , true ) ;
49+
50+ // Explosion pool
51+ explosions = game . add . group ( ) ;
3752
3853 for ( var i = 0 ; i < 10 ; i ++ )
3954 {
40- var b = bullets . create ( 0 , 0 , 'bullet' ) ;
41- b . name = 'bullet' + i ;
42- b . exists = false ;
43- b . visible = false ;
44- b . anchor . setTo ( 0.5 , 1 ) ;
45- b . events . onOutOfBounds . add ( resetBullet , this ) ;
55+ var explosionAnimation = explosions . create ( 0 , 0 , 'kaboom' , [ 0 ] , false ) ;
56+ explosionAnimation . anchor . setTo ( 0.5 , 0.5 ) ;
57+ explosionAnimation . animations . add ( 'kaboom' ) ;
4658 }
4759
4860 var tween = game . add . tween ( aliens ) . to ( { x : 200 } , 3000 , Phaser . Easing . Linear . None , true , 0 , 1000 , true ) ;
4961 tween . onComplete . add ( descend , this ) ;
5062
63+ cursors = game . input . keyboard . createCursorKeys ( ) ;
64+ fireButton = game . input . keyboard . addKey ( Phaser . Keyboard . SPACEBAR ) ;
65+
5166}
5267
5368
@@ -60,16 +75,16 @@ function update() {
6075 player . body . velocity . x = 0 ;
6176 player . body . velocity . y = 0 ;
6277
63- if ( game . input . keyboard . isDown ( Phaser . Keyboard . LEFT ) )
78+ if ( cursors . left . isDown )
6479 {
6580 player . body . velocity . x = - 200 ;
6681 }
67- else if ( game . input . keyboard . isDown ( Phaser . Keyboard . RIGHT ) )
82+ else if ( cursors . right . isDown )
6883 {
6984 player . body . velocity . x = 200 ;
7085 }
7186
72- if ( game . input . keyboard . isDown ( Phaser . Keyboard . SPACEBAR ) )
87+ if ( fireButton . isDown )
7388 {
7489 fireBullet ( ) ;
7590 }
@@ -104,16 +119,11 @@ function collisionHandler (bullet, alien) {
104119 bullet . kill ( ) ;
105120 alien . kill ( ) ;
106121
107- }
108-
109- function render ( ) {
110-
111- // aliens.forEach(renderBounds, this);
112-
113- game . debug . renderQuadTree ( game . physics . quadTree ) ;
122+ var explosionAnimation = explosions . getFirstDead ( ) ;
123+ explosionAnimation . reset ( alien . body . x , alien . body . y ) ;
124+ explosionAnimation . play ( 'kaboom' , 30 , false , true ) ;
114125
115126}
116127
117- function renderBounds ( s ) {
118- game . debug . renderSpriteBounds ( s , 'rgba(0,0,255,0.4)' , true ) ;
128+ function render ( ) {
119129}
0 commit comments