-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameloop.js
47 lines (40 loc) · 993 Bytes
/
gameloop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// True when the project is running
let running = false;
// Get the canvas element
const cvs = document.getElementById("gameing"); // Yes that is spelled right
// Get the '2d' context
const ctx = cvs.getContext('2d');
// The screen size
let screenWidth;
let screenHeight;
// Start the forever loop
function init() {
if (!running) {
forever();
}
running = true;
};
// Set up the canvas
function setCanvasInfo() {
if (!isFullScreen()) {
cvs.style.display = "none";
} else {
cvs.style.display = "block";
cvs.width = window.innerWidth;
cvs.height = window.innerHeight;
screenWidth = window.innerWidth;
screenHeight = window.innerHeight;
}
};
// The forever loop
function forever() {
setCanvasInfo();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, screenWidth, screenHeight);
gameLoop();
window.requestAnimationFrame(forever);
};
// This is the real game loop that does the game logic
function gameLoop() {
map.draw(1);
};