Spaces:
Sleeping
Sleeping
Update static/scripts.js
Browse files- static/scripts.js +14 -3
static/scripts.js
CHANGED
@@ -24,6 +24,8 @@ images['potion'].src = '/static/potion.png';
|
|
24 |
images['sword'].src = '/static/sword.png';
|
25 |
images['door'].src = '/static/door.png';
|
26 |
|
|
|
|
|
27 |
let allImagesLoaded = false;
|
28 |
let imagesLoaded = 0;
|
29 |
const totalImages = Object.keys(images).length;
|
@@ -58,21 +60,30 @@ socket.on('message', (msg) => {
|
|
58 |
});
|
59 |
|
60 |
function drawGame(state) {
|
|
|
61 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
62 |
for (let y = 0; y < state.terrain.length; y++) {
|
63 |
for (let x = 0; x < state.terrain[y].length; x++) {
|
64 |
-
const
|
|
|
|
|
65 |
if (img && img.complete) {
|
66 |
ctx.drawImage(img, x * tileSize, y * tileSize, tileSize, tileSize);
|
|
|
|
|
67 |
}
|
68 |
}
|
69 |
}
|
70 |
for (let y = 0; y < state.entities.length; y++) {
|
71 |
for (let x = 0; x < state.entities[y].length; x++) {
|
72 |
-
|
73 |
-
|
|
|
|
|
74 |
if (img && img.complete) {
|
75 |
ctx.drawImage(img, x * tileSize, y * tileSize, tileSize, tileSize);
|
|
|
|
|
76 |
}
|
77 |
}
|
78 |
}
|
|
|
24 |
images['sword'].src = '/static/sword.png';
|
25 |
images['door'].src = '/static/door.png';
|
26 |
|
27 |
+
|
28 |
+
|
29 |
let allImagesLoaded = false;
|
30 |
let imagesLoaded = 0;
|
31 |
const totalImages = Object.keys(images).length;
|
|
|
60 |
});
|
61 |
|
62 |
function drawGame(state) {
|
63 |
+
console.log('Drawing game with state:', state); // Log the entire state
|
64 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
65 |
for (let y = 0; y < state.terrain.length; y++) {
|
66 |
for (let x = 0; x < state.terrain[y].length; x++) {
|
67 |
+
const terrainType = state.terrain[y][x] || 'f';
|
68 |
+
console.log(`Terrain at (${x},${y}): ${terrainType}`);
|
69 |
+
const img = images[terrainType];
|
70 |
if (img && img.complete) {
|
71 |
ctx.drawImage(img, x * tileSize, y * tileSize, tileSize, tileSize);
|
72 |
+
} else {
|
73 |
+
console.warn(`Image not ready for ${terrainType}`);
|
74 |
}
|
75 |
}
|
76 |
}
|
77 |
for (let y = 0; y < state.entities.length; y++) {
|
78 |
for (let x = 0; x < state.entities[y].length; x++) {
|
79 |
+
const entityType = state.entities[y][x];
|
80 |
+
if (entityType) {
|
81 |
+
console.log(`Entity at (${x},${y}): ${entityType}`);
|
82 |
+
const img = images[entityType];
|
83 |
if (img && img.complete) {
|
84 |
ctx.drawImage(img, x * tileSize, y * tileSize, tileSize, tileSize);
|
85 |
+
} else {
|
86 |
+
console.warn(`Image not ready for ${entityType}`);
|
87 |
}
|
88 |
}
|
89 |
}
|