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