11// SYSTEM SETUP
2- const app = new PIXI . Application ( { width : 1920 , height : 1080 , backgroundColor : 0x111111 , antialias : false } ) ;
2+ const app = new PIXI . Application ( { width : 1920 , height : 1080 , backgroundColor : 0x000000 , antialias : false } ) ;
33app . view . id = "PIXI" ;
44document . body . appendChild ( app . view ) ;
55
66PIXI . input . mouseContainer = app . view ;
77
88const diceImg = [ null , PIXI . Texture . from ( "assets/one.png" ) , PIXI . Texture . from ( "assets/two.png" ) , PIXI . Texture . from ( "assets/three.png" ) , PIXI . Texture . from ( "assets/four.png" ) , PIXI . Texture . from ( "assets/five.png" ) , PIXI . Texture . from ( "assets/six.png" ) ] ;
99
10+ const img = {
11+ bg : PIXI . Texture . from ( "assets/background.png" ) ,
12+ }
13+
1014const sound = {
11- hurt : PIXI . sound . Sound . from ( "assets/hurt.mp3" ) ,
15+ hit : [ PIXI . sound . Sound . from ( "assets/hitS.wav" ) , PIXI . sound . Sound . from ( "assets/hitM.wav" ) , PIXI . sound . Sound . from ( "assets/hitL.wav" ) ] ,
16+ bounce : [ PIXI . sound . Sound . from ( "assets/bounceS.wav" ) , PIXI . sound . Sound . from ( "assets/bounceM.wav" ) , PIXI . sound . Sound . from ( "assets/bounceL.wav" ) ]
1217}
1318
1419// const dangerTint = [0xffffff, 0xffff00, 0xffcc00, 0xff9900, 0xff6600, 0xff3300, 0xff0000];
15- const dangerTint = [ 0xffffff , 0xff20ff , 0x8020ff , 0x2020ff , 0x2080ff , 0x20ffff , 0x20ff80 ] ;
16-
17- const lifeTint = [ 0xff8877 , 0xff9988 , 0xffaa99 , 0xffbbaa , 0xffccbb , 0xffddcc , 0xffeedd ] ;
20+ const dangerTint = [
21+ 0xffffff ,
22+ 0xD92BBC ,
23+ 0xD92B9F ,
24+ 0xD92B82 ,
25+ 0xD92B65 ,
26+ 0xD92B48 ,
27+ 0xD92B2B
28+ ] ;
29+
30+ const lifeTint = [
31+ 0xff2211 ,
32+ 0xff4433 ,
33+ 0xff6655 ,
34+ 0xff8877 ,
35+ 0xffaa99 ,
36+ 0xffccbb ,
37+ 0xffeedd
38+ ] ;
39+
40+ const bgTint = [
41+ 0x773355 ,
42+ 0x775533 ,
43+ 0x557733 ,
44+ 0x553377 ,
45+ 0x335577 ,
46+ 0x337755 ,
47+ ]
1848// USEFUL FUNCTIONS
1949
2050const clamp = ( x , min , max ) => {
@@ -26,14 +56,15 @@ const rand = (min, max) => {
2656}
2757
2858// GAME SETUP
59+ let bg = PIXI . Sprite . from ( img . bg ) ;
60+ bg . anchor = { x :0.5 , y :0 } ;
61+ bg . x = 0.5 * app . view . width ;
62+ bg . y = 0 ;
63+ app . stage . addChild ( bg ) ;
2964
3065const scene = new PIXI . Container ( ) ;
3166app . stage . addChild ( scene ) ;
3267
33- const bloomContainer = new PIXI . ParticleContainer ( ) ;
34- bloomContainer . visible = false ;
35- app . stage . addChild ( bloomContainer ) ;
36-
3768const allocationScreen = new PIXI . Container ( ) ;
3869app . stage . addChild ( allocationScreen ) ;
3970
@@ -159,13 +190,17 @@ app.ticker.add((deltaTime) => {
159190 if ( PIXI . input . getKeyFired ( "f" ) ) {
160191 PIXI . utils . openFullScreen ( app . view ) ;
161192 }
193+ if ( app . stage . x != 0 ) {
194+ app . stage . x += ( 0 - app . stage . x ) * 1.75 ;
195+ }
162196 if ( ! states . start || states . life <= 0 ) {
163-
164197 menuContainer . visible = true ;
165198 scene . visible = false ;
166199 allocationScreen . visible = false ;
167200 menu . score . text = "Level " + states . level + " | " + states . score + " points" ;
168201
202+ bg . tint = bgTint [ 0 ] ;
203+
169204 if ( PIXI . input . getKeyFired ( "e" ) ) {
170205 states . start = true ;
171206 states . allocation = true ;
@@ -194,6 +229,8 @@ app.ticker.add((deltaTime) => {
194229 scene . visible = false ;
195230 allocationScreen . visible = true ;
196231
232+ bg . tint = bgTint [ 0 ] ;
233+
197234 if ( rollSprite . length == 0 ) {
198235 for ( let i = 0 ; i < 4 ; i ++ ) {
199236 let num = rand ( 1 , 6 ) ;
@@ -203,7 +240,7 @@ app.ticker.add((deltaTime) => {
203240 rollSprite [ i ] . anchor = { x : 0.5 , y : 1 } ;
204241 rollSprite [ i ] . facing = num ;
205242 rollSprite [ i ] . tint = dangerTint [ 7 - num ] ;
206- rollSprite [ i ] . vec = { x : 0 , y : 0 } ;
243+ rollSprite [ i ] . vec = { x : rand ( - 16 , 16 ) , y : rand ( - 16 , 16 ) } ;
207244 rollSprite [ i ] . roll = true ;
208245 rollSprite [ i ] . slot = i ;
209246 allocationScreen . addChild ( rollSprite [ i ] ) ;
@@ -222,6 +259,7 @@ app.ticker.add((deltaTime) => {
222259 danger . facing = rand ( 1 , 6 ) ;
223260 danger . texture = diceImg [ danger . facing ] ;
224261 danger . tint = dangerTint [ 7 - danger . facing ] ;
262+ sound . bounce [ rand ( 0 , 2 ) ] . play ( ) ;
225263 }
226264 }
227265 danger . x = ( danger . x + danger . vec . x ) ^ 0 ;
@@ -258,22 +296,19 @@ app.ticker.add((deltaTime) => {
258296 newRolls = [ ] ;
259297 directions . visible = false ;
260298
299+ bg . tint = bgTint [ rand ( 1 , bgTint . length - 1 ) ] ;
300+
261301 dangerSet . forEach ( ( danger ) => {
262302 scene . removeChild ( danger ) ;
263303 dangerSet . delete ( danger ) ;
264304 } ) ;
265- scene . x = 0 ; // Reset screen shake
266305 }
267306 }
268307
269308 } else {
270309 allocationScreen . visible = false ;
271310 scene . visible = true ;
272311
273- if ( scene . x != 0 ) {
274- scene . x += ( 0 - scene . x ) * 1.875 ;
275- }
276-
277312 let t = Math . max ( states . life , 1 ) ;
278313 player . texture = diceImg [ t ] ;
279314 player . tint = lifeTint [ t ] ;
@@ -304,6 +339,7 @@ app.ticker.add((deltaTime) => {
304339 player . x = ( app . view . width - player . width * 0.5 ) ;
305340 player . vec . x *= - phys . bounce ;
306341 }
342+ player . x = ( player . x + 0.5 ) ^ 0 ;
307343 // Player Y position
308344 player . y = Math . min ( player . y + player . vec . y , app . view . height ) ^ 0 ;
309345
@@ -320,6 +356,7 @@ app.ticker.add((deltaTime) => {
320356 danger . facing = rand ( 1 , 6 ) ;
321357 danger . texture = diceImg [ danger . facing ] ;
322358 danger . tint = dangerTint [ danger . facing ] ;
359+ sound . bounce [ rand ( 0 , 2 ) ] . play ( ) ;
323360 }
324361 }
325362 danger . x = ( danger . x + danger . vec . x ) ^ 0 ;
@@ -331,7 +368,7 @@ app.ticker.add((deltaTime) => {
331368 danger . vec . x *= - phys . bounce ;
332369 }
333370 if ( PIXI . collision . aabb ( player , danger ) ) {
334- if ( player . y + player . height * 0.35 < danger . y ) {
371+ if ( player . y - player . vec . y * 0.5 < danger . y ) {
335372 // Jumped on top, score up AND heal AND bounce
336373 states . life = clamp ( states . life + danger . facing , 1 , 6 )
337374 player . vec . y = - 24 - states . jump * states . jumpMult ;
@@ -340,9 +377,9 @@ app.ticker.add((deltaTime) => {
340377 } else {
341378 // Hit by danger, lose life
342379 states . life -= danger . facing ;
343- scene . x += phys . shake ;
344- sound . hurt . play ( ) ;
380+ app . stage . x += phys . shake ;
345381 }
382+ sound . hit [ rand ( 0 , 2 ) ] . play ( ) ;
346383 scene . removeChild ( danger ) ;
347384 dangerSet . delete ( danger ) ;
348385 } else if ( Math . abs ( danger . vec . y ) < 0.25 && danger . y == app . view . height ) {
0 commit comments