Skip to content

Commit

Permalink
[ADD] FPS pointer system
Browse files Browse the repository at this point in the history
  • Loading branch information
aldo-rl committed Oct 8, 2020
1 parent 93ad12d commit bc96c6a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const MINIMAP_SCALE_FACTOR = 0.2;
const VISION_ANGLE = Math.PI / 3;
const RAY_WIDTH = 2; // can be increased for optimization
const NUM_RAYS = WINDOW_WIDTH / RAY_WIDTH;
// FPS
let FPS = 0
const SECONDS_TO_REFRESH_FPS = 1
class Map {
constructor() {
this.grid = [
Expand Down Expand Up @@ -319,6 +322,23 @@ function render3DProjectedWalls() {
}
}

function setUpFontFPS() {
fill(255,255,255);
noStroke()
textSize(14)
}

function updateFPS() {
setUpFontFPS()
let fpsRate = parseInt(getFrameRate())
if(frameCount % (SECONDS_TO_REFRESH_FPS * 60) == 0) {
text('FPS: ' + fpsRate, WINDOW_WIDTH - 70, 30);
FPS = parseInt(getFrameRate())
} else {
FPS = FPS === 0 ?fpsRate :FPS
text('FPS: ' + FPS, WINDOW_WIDTH - 70, 30)
}
}

function setup() {
// initialize all objects
Expand All @@ -345,6 +365,9 @@ function draw() {
ray.render()
}
player.render()

// FPS
updateFPS()
}

// actions
Expand Down

0 comments on commit bc96c6a

Please sign in to comment.