Added debug features, an FPS ledger

This commit is contained in:
Mottributo 2023-03-23 17:21:02 +03:00
parent 91c2069bad
commit 4aa0718158

View File

@ -1,6 +1,8 @@
var floorPos_y; var floorPos_y;
var cameraPosX; var cameraPosX;
var processStop_timer; var processStop_timer;
var fps_recent_values = [];
var showDebugData = false;
var gameChar; var gameChar;
@ -288,9 +290,12 @@ function draw() {
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) {
text(gameChar.curGroundPosYIndex, 99, 99); text(gameChar.curGroundPosYIndex, 99, 99);
text(gameChar.getCurGroundPosY(), 188, 99); text(gameChar.getCurGroundPosY(), 188, 99);
text(gameChar.sprite, 277, 99); text(gameChar.sprite, 277, 99);
drawFps();
}
pop(); pop();
} }
@ -579,8 +584,8 @@ function drawClouds() {
push(); push();
translate((frameCount / clouds[i].y) * 20, 0); // imitating clouds movement, upper ones should go faster translate((frameCount / clouds[i].y) * 20, 0); // imitating clouds movement, upper ones should go faster
// Adding counter-translating to implement parallax, the feeling of depth // Adding counter-translating to implement parallax, the feeling of depth
// TODO: fix jitter during movement (possibly by implementing vectorized movement)
translate(cameraPosX / 1.1, 0); translate(cameraPosX / 1.1, 0);
noStroke(); noStroke();
fill(palette.cloud0); fill(palette.cloud0);
ellipse( ellipse(
@ -616,7 +621,7 @@ function drawMountains() {
for (i = 0; i < mountains.length; i++) { for (i = 0; i < mountains.length; i++) {
push(); push();
// slowing down translation to add parallax, the feeling of depth // slowing down translation to add parallax, the feeling of depth
translate(cameraPosX / 2.2, 0); translate(cameraPosX / 2, 0);
noStroke(); noStroke();
fill(palette.mountain_shadow); fill(palette.mountain_shadow);
triangle( triangle(
@ -778,7 +783,24 @@ function checkPlayerDie() {
} }
} }
} }
function drawFps() {
push();
fps = Math.round(frameRate() * 10) / 10;
if (fps_recent_values.length < 200) fps_recent_values.push(fps);
else fps_recent_values.shift();
fps_recent_values.push(fps);
fill("red");
text(fps, 400, 99);
stroke("black");
beginShape(LINES);
for (i = 1; i < fps_recent_values.length; i++) {
vertex(i, fps_recent_values[i]);
}
endShape();
pop();
}
function keyPressed() { function keyPressed() {
console.log(frameCount + " pressed " + key + " " + keyCode); console.log(frameCount + " pressed " + key + " " + keyCode);
if (gameChar.curLives < 1 || flagpole.isReached) { if (gameChar.curLives < 1 || flagpole.isReached) {
@ -801,9 +823,10 @@ function keyPressed() {
gameChar.jumpingStrength = 15; gameChar.jumpingStrength = 15;
} }
} }
if (keyCode == 77 /*M*/) showDebugData = !showDebugData;
} }
function keyReleased() { function keyReleased() {
console.log(frameCount + " released " + key + " " + keyCode); console.log(frameCount + " released " + key + " " + keyCode);
if (keyCode == 65 /*A*/) gameChar.isLeft = false; if (keyCode == 65 /*A*/) gameChar.isLeft = false;
if (keyCode == 68 /*D*/) gameChar.isRight = false; if (keyCode == 68 /*D*/) gameChar.isRight = false;
} }