@@ -7,7 +7,9 @@ PIXI.input.mouseContainer = app.view;
77
88const diceImg = [ PIXI . Texture . from ( "assets/character.png" ) , 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 dangerTint = [ 0xffffff , 0xffff00 , 0xffcc00 , 0xff9900 , 0xff6600 , 0xff3300 , 0xff0000 ] ;
10+ // const dangerTint = [0xffffff, 0xffff00, 0xffcc00, 0xff9900, 0xff6600, 0xff3300, 0xff0000];
11+ const dangerTint = [ 0xffffff , 0xff20ff , 0x8020ff , 0x2020ff , 0x2080ff , 0x20ffff , 0x20ff80 ] ;
12+
1113const lifeTint = [ 0xff8877 , 0xff9988 , 0xffaa99 , 0xffbbaa , 0xffccbb , 0xffddcc , 0xffeedd ] ;
1214// USEFUL FUNCTIONS
1315
@@ -41,7 +43,7 @@ const states = {
4143 jumpMult : 3 ,
4244 danger : 3 ,
4345 dangerSpawnBoost : 0 ,
44- level : 1 ,
46+ level : 0 ,
4547 dangerCount : 0 ,
4648 score : 0
4749}
@@ -59,12 +61,18 @@ const textStyle = new PIXI.TextStyle({
5961
6062// Menu stuff
6163
62- const infoText = new PIXI . Text ( " [F] to enter fullscreen\n [Esc] to pause the game\n\n [A] is left, [D] is right\n[W] is jump, [S] is to drop\n\nGetting hit by an enemy die\n will lower your health by\n the shown number, jumping\n on top of it will restore\n your health by the number\n\n\n\n Press [W]" , textStyle ) ;
64+ const infoText = new PIXI . Text ( " [F] to enter fullscreen\n [Esc] to pause the game\n\n [A] is left, [D] is right\n[W] is jump, [S] is to drop\n\nGetting hit by an enemy die\n will lower your health by\n the shown number, jumping\n on top of it will restore\n your health by the number\n\n\n Press [W]" , textStyle ) ;
6365infoText . x = app . view . width * 0.5 ;
6466infoText . y = app . view . height * 0.5 ;
6567infoText . anchor = { x : 0.5 , y : 0.5 } ;
6668menu . addChild ( infoText ) ;
6769
70+ const menuScore = new PIXI . Text ( "" , textStyle ) ;
71+ menuScore . x = app . view . width * 0.5 ;
72+ menuScore . y = app . view . height * 0.05 ;
73+ menuScore . anchor = { x : 0.5 , y : 0.5 } ;
74+ menu . addChild ( menuScore ) ;
75+
6876// Allocation stuff
6977const topMessage = new PIXI . Text ( "Lady Luck rolls again!" , textStyle )
7078topMessage . x = app . view . width * 0.5 ;
@@ -79,26 +87,26 @@ let rollSprite = [];
7987const statName = [ ] ;
8088
8189statName [ 0 ] = new PIXI . Text ( "Jump Height" , textStyle )
82- statName [ 0 ] . x = app . view . width * 0.3 ;
90+ statName [ 0 ] . x = app . view . width * 0.2 ;
8391statName [ 0 ] . y = app . view . height * 0.4 ;
8492statName [ 0 ] . anchor = { x : 0.5 , y : 0.5 } ;
8593allocationScreen . addChild ( statName [ 0 ] ) ;
8694
87- statName [ 1 ] = new PIXI . Text ( "Difficulty " , textStyle )
88- statName [ 1 ] . x = app . view . width * 0.7 ;
95+ statName [ 1 ] = new PIXI . Text ( "Top Speed " , textStyle )
96+ statName [ 1 ] . x = app . view . width * 0.4 ;
8997statName [ 1 ] . y = app . view . height * 0.4 ;
9098statName [ 1 ] . anchor = { x : 0.5 , y : 0.5 } ;
9199allocationScreen . addChild ( statName [ 1 ] ) ;
92100
93- statName [ 2 ] = new PIXI . Text ( "Top Speed " , textStyle )
94- statName [ 2 ] . x = app . view . width * 0.3 ;
95- statName [ 2 ] . y = app . view . height * 0.65 ;
101+ statName [ 2 ] = new PIXI . Text ( "Difficulty " , textStyle )
102+ statName [ 2 ] . x = app . view . width * 0.6 ;
103+ statName [ 2 ] . y = app . view . height * 0.4 ;
96104statName [ 2 ] . anchor = { x : 0.5 , y : 0.5 } ;
97105allocationScreen . addChild ( statName [ 2 ] ) ;
98106
99107statName [ 3 ] = new PIXI . Text ( "Starting Health" , textStyle )
100- statName [ 3 ] . x = app . view . width * 0.7 ;
101- statName [ 3 ] . y = app . view . height * 0.65 ;
108+ statName [ 3 ] . x = app . view . width * 0.8 ;
109+ statName [ 3 ] . y = app . view . height * 0.4 ;
102110statName [ 3 ] . anchor = { x : 0.5 , y : 0.5 } ;
103111allocationScreen . addChild ( statName [ 3 ] ) ;
104112
@@ -143,13 +151,34 @@ app.ticker.add((deltaTime) => {
143151 if ( PIXI . input . getKeyFired ( "f" ) ) {
144152 PIXI . utils . openFullScreen ( app . view ) ;
145153 }
146- if ( ! states . start ) {
154+ if ( ! states . start || states . life <= 0 ) {
147155
148156 menu . visible = true ;
149157 scene . visible = false ;
150158 allocationScreen . visible = false ;
151-
152- states . start = PIXI . input . getKeyFired ( "w" ) ;
159+ menuScore . text = "Level " + states . level + " | " + states . score + " points" ;
160+ rollSprite = [ ] ;
161+
162+ if ( PIXI . input . getKeyFired ( "w" ) ) {
163+ states . start = true ;
164+ states . life = 6 ;
165+ states . speed = 3 ;
166+ states . speedMult = 3 ;
167+ states . jump = 3 ;
168+ states . jumpMult = 3 ;
169+ states . danger = 3 ;
170+ states . dangerSpawnBoost = 0 ;
171+ states . level = 1 ;
172+ states . dangerCount = 0 ;
173+ states . score = 0 ;
174+
175+ player . x = app . view . width * 0.5 ;
176+ player . y = app . view . height ;
177+ player . anchor = { x : 0.5 , y : 1.0 } ;
178+ player . vec = { x : 0 , y : 0 } ;
179+ player . tint = 0x33ff44 ;
180+ states . allocation = true ;
181+ }
153182 } else {
154183
155184 menu . visible = false ;
@@ -169,7 +198,7 @@ app.ticker.add((deltaTime) => {
169198 let num = rand ( 1 , 6 ) ;
170199 rollSprite [ i ] = new PIXI . Sprite . from ( diceImg [ num ] ) ;
171200 rollSprite [ i ] . x = ( app . view . width * ( i + 1 ) * 0.2 ) ^ 0 ;
172- rollSprite [ i ] . y = ( 0.25 * app . view . height ) ^ 0 ;
201+ rollSprite [ i ] . y = ( 0.3 * app . view . height ) ^ 0 ;
173202 rollSprite [ i ] . anchor = { x : 0.5 , y : 1 } ;
174203 rollSprite [ i ] . facing = num ;
175204 rollSprite [ i ] . tint = dangerTint [ 7 - num ] ;
@@ -206,13 +235,21 @@ app.ticker.add((deltaTime) => {
206235 if ( Math . abs ( danger . vec . y ) < 0.25 && danger . y == app . view . height ) {
207236 newRolls [ danger . slot ] = danger . facing ;
208237 danger . x = ( ( danger . slot + 1 ) * 0.2 * app . view . width ) ^ 0 ;
209- danger . y = ( 0.25 * app . view . height ) ^ 0 ;
238+ danger . y = ( 0.3 * app . view . height ) ^ 0 ;
210239 danger . roll = false ;
211240 }
212241 }
213-
214242 } ) ;
215243
244+ if ( PIXI . input . getKeyFired ( "w" ) ) {
245+ states . level ++ ;
246+ states . allocation = false ;
247+ states . jump = newRolls [ 0 ] ;
248+ states . speed = newRolls [ 1 ] ;
249+ states . danger = newRolls [ 2 ] ;
250+ states . life = newRolls [ 3 ] ;
251+ }
252+
216253 } else {
217254 if ( ! states . pause ) {
218255
@@ -224,7 +261,7 @@ app.ticker.add((deltaTime) => {
224261 player . texture = diceImg [ t ] ;
225262 player . tint = lifeTint [ t ] ;
226263
227- score . text = states . score + " points, " + ( 25 + states . level * 5 - states . dangerCount ) + " dice left" ;
264+ score . text = "Level " + states . level + " | " + states . score + " points, " + ( 25 + states . level * 5 - states . dangerCount ) + " dice left" ;
228265
229266 // X velocity
230267 player . vec . x = clamp ( player . vec . x * ( 1 - ( 0.1 * deltaTime ) * ( player . vec . y == 0 ) ) + ( PIXI . input . getKeyDown ( "d" ) - PIXI . input . getKeyDown ( "a" ) ) * ( player . vec . y == 0 ) * states . speedMult , states . speed * - states . speedMult , states . speed * states . speedMult ) ;
@@ -282,15 +319,15 @@ app.ticker.add((deltaTime) => {
282319 }
283320 if ( PIXI . collision . aabb ( player , danger ) ) {
284321 if ( player . y + player . height * 0.45 < danger . y ) {
285- // Jumped on top, score up AND heal
322+ // Jumped on top, score up AND heal AND bounce
286323 states . life = clamp ( states . life + danger . facing , 1 , 6 )
287- states . score += danger . facing ;
324+ player . vec . y = - 24 - states . jump * states . jumpMult ;
325+ states . score += danger . facing * 3 ;
288326 states . dangerCount ++ ;
289327 } else {
290328 // Hit by danger, lose life
291329 states . life -= danger . facing ;
292330 }
293- player . vec . y = - 40 - states . jump * states . jumpMult ;
294331 scene . removeChild ( danger ) ;
295332 dangerSet . delete ( danger ) ;
296333 } else if ( Math . abs ( danger . vec . y ) < 0.25 && danger . y == app . view . height ) {
@@ -301,7 +338,7 @@ app.ticker.add((deltaTime) => {
301338 }
302339 } ) ;
303340
304- if ( dangerSet . size < states . danger + states . level && Math . random ( ) < 0.0002 + states . dangerSpawnBoost ) {
341+ if ( dangerSet . size < states . danger + states . level && Math . random ( ) < states . dangerSpawnBoost ) {
305342 states . dangerSpawnBoost = 0 ;
306343 let num = rand ( 1 , 6 ) ;
307344 let newDanger = PIXI . Sprite . from ( diceImg [ num ] ) ;
@@ -327,7 +364,7 @@ app.ticker.add((deltaTime) => {
327364 scene . addChild ( newDanger ) ;
328365 dangerSet . add ( newDanger ) ;
329366 } else {
330- states . dangerSpawnBoost += 0.0001 * ( states . danger + states . level ) ;
367+ states . dangerSpawnBoost += 0.00005 * ( states . danger + states . level ) ;
331368 }
332369
333370 if ( states . dangerCount >= 25 + states . level * 5 ) {
0 commit comments