Spaces:
Sleeping
Sleeping
Upload game.js
Browse files- static/game/game.js +44 -41
static/game/game.js
CHANGED
@@ -9,7 +9,10 @@ let baseMapImg;
|
|
9 |
let girlfriendImg;
|
10 |
let clownImg;
|
11 |
|
12 |
-
let isSoundOn =
|
|
|
|
|
|
|
13 |
const soundIcon = document.getElementById("soundIcon");
|
14 |
const bgMusic = document.getElementById("bgMusic");
|
15 |
|
@@ -20,51 +23,51 @@ let chatMessages = [];
|
|
20 |
let furnitureSprites = {};
|
21 |
|
22 |
function setup() {
|
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 |
function draw() {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
}
|
|
|
9 |
let girlfriendImg;
|
10 |
let clownImg;
|
11 |
|
12 |
+
let isSoundOn =
|
13 |
+
localStorage.getItem("isSoundOn") === null
|
14 |
+
? true
|
15 |
+
: localStorage.getItem("isSoundOn") !== "false";
|
16 |
const soundIcon = document.getElementById("soundIcon");
|
17 |
const bgMusic = document.getElementById("bgMusic");
|
18 |
|
|
|
23 |
let furnitureSprites = {};
|
24 |
|
25 |
function setup() {
|
26 |
+
baseMapImg = loadImage("/assets/img/appartment/BaseMap.PNG");
|
27 |
+
girlfriendImg = loadImage("/assets/img/gf.png");
|
28 |
+
clownImg = loadImage("/assets/img/clown.png");
|
29 |
|
30 |
+
gameState = new GameState({
|
31 |
+
...getApt(),
|
32 |
+
grid: getGrid(),
|
33 |
+
furniture: getFurniture(),
|
34 |
+
});
|
35 |
|
36 |
+
furnitureSprites = loadFurnitureSprites(gameState.map_data.furniture);
|
37 |
|
38 |
+
GRID_COLS = gameState.map_data.gridCols;
|
39 |
+
GRID_ROWS = gameState.map_data.gridRows;
|
40 |
|
41 |
+
girlfriend = new Girlfriend(gameState, girlfriendImg);
|
42 |
+
clown = new Clown(gameState, clownImg);
|
43 |
|
44 |
+
// Once loaded, initialize the P5 canvas with correct dims
|
45 |
+
let canvas = createCanvas(GRID_COLS * CELL_SIZE, GRID_ROWS * CELL_SIZE);
|
46 |
+
canvas.parent("mapWrapper");
|
47 |
+
adjustScale();
|
48 |
}
|
49 |
|
50 |
function draw() {
|
51 |
+
clear();
|
52 |
+
|
53 |
+
if (baseMapImg) {
|
54 |
+
image(baseMapImg, 0, 0, GRID_COLS * CELL_SIZE, GRID_ROWS * CELL_SIZE);
|
55 |
+
}
|
56 |
+
if (furnitureSprites) {
|
57 |
+
drawFurniture(gameState.map_data.furniture, furnitureSprites);
|
58 |
+
}
|
59 |
+
//drawGrid();
|
60 |
+
// drawWallsAndDoors();
|
61 |
+
|
62 |
+
drawLabels(gameState.map_data.rooms);
|
63 |
+
|
64 |
+
if (girlfriend) {
|
65 |
+
girlfriend.drawPath(CELL_SIZE);
|
66 |
+
girlfriend.draw(CELL_SIZE);
|
67 |
+
}
|
68 |
+
if (clown) {
|
69 |
+
clown.checkForGirlfriend(girlfriend);
|
70 |
+
clown.drawPath(CELL_SIZE);
|
71 |
+
clown.draw(CELL_SIZE);
|
72 |
+
}
|
73 |
+
}
|