-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
37 lines (29 loc) · 858 Bytes
/
main.js
File metadata and controls
37 lines (29 loc) · 858 Bytes
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
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = 600;
canvas.height = 800;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
async function initGame() {
try {
await SceneManager.init();
Input.init(canvas);
Renderer.init(ctx);
gameLoop();
} catch (error) {
console.error('Error during initialization:', error);
}
}
function gameLoop() {
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update game state and character
SceneManager.update();
// Render current scene
Renderer.render();
// Continue the game loop
requestAnimationFrame(gameLoop);
}
window.addEventListener('load', initGame);