Files
Jonas 76392172b5 fix: correct collision message and improve asset loading
- Fix typo in collision message from "Ihr seit koolidiert!" to "Es gab eine Kollision!"
- Reorder TODO comment in endGame method
- Rename "Früchte" folder to "Fruits" for consistency
- Add TileLoader class to preload and cache game assets
- Refactor Overlay class to use TileLoader for improved image handling
2025-04-28 14:59:18 +02:00

50 lines
1.5 KiB
JavaScript

import Overlay from "./Elements/Overlay.js";
import TileLoader from "./Elements/TileLoader.js";
import Game from "./Game.js"
class Loop{
/**@param {import("../../../../backend/node_modules/socket.io-client".Socket} socket @param {Game} game Autocompletions VSC*/
constructor(socket, game){
this.socket = socket;
this.game = game;
this.tileLoader = new TileLoader();
this.socket.on("loop", (data) => { this.loop(data) });
}
loop(data){
this.game.playGround.resetOverlay();
const tiles = data.playground.tiles;
// Spielfeld Zeichenen
tiles.forEach((row, x) => {
row.forEach((tile, y) => {
if(!tile) return;
if(tile.class === "Snake"){
const overlay = new Overlay(
this.tileLoader,
`Snakes/${tile.color}/${tile.type}.png`,
tile.deg
)
this.game.playGround.setOverlay(x, y, overlay);
}
else if(tile.class === "Fruit"){
const overlay = new Overlay(
this.tileLoader,
`Fruits/${tile.type}.png`
)
this.game.playGround.setOverlay(x, y, overlay);
}
})
});
// Score Anzeigen
this.game.uiManager.score.innerText = `${data.score}`;
this.game.playGround.draw();
}
}
export default Loop;