Added debug features, an FPS ledger
This commit is contained in:
parent
91c2069bad
commit
4aa0718158
27
sketch.js
27
sketch.js
@ -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,6 +823,7 @@ 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user