-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
71 lines (55 loc) · 1.4 KB
/
sketch.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let gamemap;
let engine;
let inputHandler;
//Game's resolution (windows size)
const gameWidth = window.innerWidth / 1.6;
const gameHeight = gameWidth / 1.6;
let gameScale = 1;
function setup() {
createCanvas(gameWidth, gameHeight);
noStroke();
pixelDensity(2);
frameRate(60);
gamemap = new Map();
gamemap.createRandomRoomMap(50, 50);
inputHandler = new InputHandler();
engine = new RayEngine(gameWidth, gameHeight, gamemap);
}
function draw() {
scale(gameScale);
//Clear the canvas for the next frame
background(35);
inputHandler.checkKeys();
if (inputHandler.isKeyDown("up")) {
engine.walkUp(inputHandler.getKey("up"));
}
else if (inputHandler.isKeyDown("down")) {
engine.walkDown(inputHandler.getKey("down"));
}
else {
engine.stopWalking();
}
if (inputHandler.isKeyDown("left")) {
engine.strafeLeft(inputHandler.getKey("left"));
}
else if (inputHandler.isKeyDown("right")) {
engine.strafeRight(inputHandler.getKey("right"));
}
else {
engine.stopStrafing();
}
if (inputHandler.isKeyDown("rotateright")) {
engine.rotateRight(inputHandler.getKey("rotateright"));
}
else if (inputHandler.isKeyDown("rotateleft")) {
engine.rotateLeft(inputHandler.getKey("rotateleft"));
}
else {
engine.stopRotation();
}
engine.generateFrame(deltaTime);
image(engine.frameBuffer, 0, 0);
}
function mouseClicked() {
requestPointerLock();
}