99 */
1010
1111const SpaceInvaders = ( ( ) => {
12- // ─── Emoji assets ────────────────────────────────────────────────────────
13-
14- const BURST_EMOJIS = [
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-
4712 const ALIEN_ROWS = [ "👾" , "👽" , "🛸" , "🐙" , "👾" ] ;
4813 const GAME_ID = "space-invaders" ;
4914
@@ -70,7 +35,7 @@ const SpaceInvaders = (() => {
7035 width : "100vw" ,
7136 height : "100vh" ,
7237 zIndex : "10000" ,
73- pointerEvents : "none" , // non-interactive until explosion is done
38+ pointerEvents : "auto" ,
7439 } ) ;
7540 document . body . appendChild ( canvas ) ;
7641
@@ -97,24 +62,7 @@ const SpaceInvaders = (() => {
9762 // ─── Scene callbacks ─────────────────────────────────────────────────────
9863
9964 function _onCreate ( ) {
100- const particles = _spawnExplosion ( this ) ;
101-
102- // After 5 s, fade out the explosion and start the real game
103- this . time . delayedCall ( 5000 , ( ) => {
104- this . tweens . add ( {
105- targets : particles . getChildren ( ) ,
106- alpha : 0 ,
107- duration : 1000 ,
108- onComplete : ( ) => {
109- particles . clear ( true , true ) ;
110-
111- const canvas = document . getElementById ( "game-canvas-" + GAME_ID ) ;
112- if ( canvas ) canvas . style . pointerEvents = "auto" ;
113-
114- _setupGame ( this ) ;
115- } ,
116- } ) ;
117- } ) ;
65+ _setupGame ( this ) ;
11866 }
11967
12068 function _onUpdate ( ) {
@@ -135,34 +83,6 @@ const SpaceInvaders = (() => {
13583
13684 // ─── Game setup ──────────────────────────────────────────────────────────
13785
138- function _spawnExplosion ( scene ) {
139- const heartEl = document . getElementById ( "footer-heart" ) ;
140- const rect = heartEl
141- ? heartEl . getBoundingClientRect ( )
142- : { left : window . innerWidth / 2 , top : window . innerHeight - 60 } ;
143-
144- const group = scene . add . group ( ) ;
145-
146- for ( let i = 0 ; i < 40 ; i ++ ) {
147- const emoji = Phaser . Utils . Array . GetRandom ( BURST_EMOJIS ) ;
148- const p = scene . add . text ( rect . left , rect . top , emoji , {
149- fontSize : "32px" ,
150- } ) ;
151-
152- scene . physics . add . existing ( p ) ;
153- p . body . setVelocity (
154- Phaser . Math . Between ( - 400 , 400 ) ,
155- Phaser . Math . Between ( - 600 , - 1200 ) ,
156- ) ;
157- p . body . setBounce ( 0.6 ) ;
158- p . body . setCollideWorldBounds ( true ) ;
159- p . body . setAngularVelocity ( Phaser . Math . Between ( - 200 , 200 ) ) ;
160- group . add ( p ) ;
161- }
162-
163- return group ;
164- }
165-
16686 function _setupGame ( scene ) {
16787 // Player rocket
16888 scene . si_player = scene . add . text (
0 commit comments