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 cameraPosX;
var processStop_timer;
var fps_recent_values = [];
var showDebugData = false;
var gameChar;
@ -288,9 +290,12 @@ function draw() {
text("Game over. Press space to continue...", 0, height / 2);
else if (flagpole.isReached)
text("Level complete. Press space to continue...", 0, height / 2);
if (showDebugData) {
text(gameChar.curGroundPosYIndex, 99, 99);
text(gameChar.getCurGroundPosY(), 188, 99);
text(gameChar.sprite, 277, 99);
drawFps();
}
pop();
}
@ -579,8 +584,8 @@ function drawClouds() {
push();
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
// TODO: fix jitter during movement (possibly by implementing vectorized movement)
translate(cameraPosX / 1.1, 0);
noStroke();
fill(palette.cloud0);
ellipse(
@ -616,7 +621,7 @@ function drawMountains() {
for (i = 0; i < mountains.length; i++) {
push();
// slowing down translation to add parallax, the feeling of depth
translate(cameraPosX / 2.2, 0);
translate(cameraPosX / 2, 0);
noStroke();
fill(palette.mountain_shadow);
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() {
console.log(frameCount + " pressed " + key + " " + keyCode);
if (gameChar.curLives < 1 || flagpole.isReached) {
@ -801,6 +823,7 @@ function keyPressed() {
gameChar.jumpingStrength = 15;
}
}
if (keyCode == 77 /*M*/) showDebugData = !showDebugData;
}
function keyReleased() {
console.log(frameCount + " released " + key + " " + keyCode);