diff --git a/sketch.js b/sketch.js index 34e3e39..f67a4f3 100644 --- a/sketch.js +++ b/sketch.js @@ -96,7 +96,7 @@ function GameCharacter() { }; this._drawEyes = function (draw_left, draw_right, eyes_height) { fill(0); - if (game_state == "FAILURE") { + if (game_state == 'FAILURE') { textAlign(CENTER); textSize(this.x_step * 2); text( @@ -279,7 +279,7 @@ function GameCharacter() { gameChar.invincibility_time += 180; if (this.curLives == 0) { playSound(audio.failure_drum); - game_state = "FAILURE"; + game_state = 'FAILURE'; // recheck music to stop playing playMusic(); } @@ -295,7 +295,7 @@ function GameCharacter() { playSound(audio.failure_drum); } else { this.curLives = 0; - game_state = "FAILURE"; + game_state = 'FAILURE'; // recheck music to stop playing playMusic(); } @@ -497,7 +497,13 @@ function Enemy(curGroundIndex, x, y, size) { }; this.collidesWith = function (who) { if ( - dist(who.x, who.y - 20 /*to account for gameChar's center*/, this.x, this.y) < this.size / 2 && + dist( + who.x, + who.y - 20 /*to account for gameChar's center*/, + this.x, + this.y, + ) < + this.size / 2 && who.curGroundIndex == this.curGroundIndex ) return true; @@ -520,8 +526,8 @@ function preload() { jump: loadSound('assets/audio/jump.wav'), stream_short: loadSound('assets/audio/stream-short.wav'), victory: loadSound('assets/audio/victory.wav'), - music: loadSound('assets/audio/Floating Cities.mp3') - } + music: loadSound('assets/audio/Floating Cities.mp3'), + }; audio.music.playMode('untilDone'); audio.stream_short.playMode('untilDone'); } @@ -554,7 +560,7 @@ function setup() { startGame((level_start = true)); } function startGame(level_start) { - game_state = "LEVEL"; + game_state = 'LEVEL'; floorPos_y = 432; text_size = sqrt(width) + sqrt(height); if (music_enabled) playMusic(); @@ -831,19 +837,20 @@ function drawInterface() { push(); fill(0); text('Score: ' + game_score, 12, text_size); - textSize(text_size/2); - if (music_enabled) phrase = "enabled"; else phrase = "disabled"; - text('Music - ' + phrase, 300, text_size/2); - if (sound_enabled) phrase = "enabled"; else phrase = "disabled"; + textSize(text_size / 2); + if (music_enabled) phrase = 'enabled'; + else phrase = 'disabled'; + text('Music - ' + phrase, 300, text_size / 2); + if (sound_enabled) phrase = 'enabled'; + else phrase = 'disabled'; text('Sound - ' + phrase, 300, text_size); textSize(text_size); stroke(255); strokeWeight(2); drawLives(); - if (game_state == "FAILURE") { + if (game_state == 'FAILURE') { text('Game over. Press space to continue...', 0, height / 2); - } - else if (flagpole.isReached) + } else if (flagpole.isReached) text('Level complete. Press space to continue...', 0, height / 2); if (showDebugData) { text(gameChar.curGroundIndex, 99, 99); @@ -855,7 +862,6 @@ function drawInterface() { drawFps(); } pop(); - } function drawCharTrace() { debug_charTrace.push([gameChar.x, gameChar.y]); @@ -1192,7 +1198,7 @@ function checkFlagpole() { if (gameChar.x >= finish_position_x) { flagpole.isReached = true; playSound(audio.victory); - game_state = "WIN"; + game_state = 'WIN'; // Stops music by recheking the game state playMusic(); } @@ -1214,7 +1220,7 @@ function drawFps() { pop(); } function keyPressed() { - if (game_state == "FAILURE" || game_state == "WIN") { + if (game_state == 'FAILURE' || game_state == 'WIN') { if (keyCode == 32 /*Space*/) { /*Hard resets the game*/ startGame((level_start = true)); @@ -1241,7 +1247,10 @@ function keyPressed() { if (keyCode == 77 /*M*/) showDebugData = !showDebugData; if (keyCode == 78 /*N*/) shadows_enabled = !shadows_enabled; if (keyCode == 79 /*P*/) sound_enabled = !sound_enabled; - if (keyCode == 80 /*O*/) {music_enabled = !music_enabled; playMusic()}; + if (keyCode == 80 /*O*/) { + music_enabled = !music_enabled; + playMusic(); + } } function keyReleased() { if (keyCode == 65 /*A*/ || keyCode == LEFT_ARROW) gameChar.isLeft = false; @@ -1251,7 +1260,7 @@ function playSound(sound) { if (sound_enabled) sound.play(); } function playMusic() { - if (music_enabled && game_state == "LEVEL") { + if (music_enabled && game_state == 'LEVEL') { audio.music.play(); } else { audio.music.stop();