-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-config.js
More file actions
101 lines (95 loc) · 3.31 KB
/
Copy pathgame-config.js
File metadata and controls
101 lines (95 loc) · 3.31 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Game Configuration and Initialization
// Check if Phaser is loaded
if (typeof Phaser === 'undefined') {
document.body.innerHTML = '<h1>Error: Phaser not loaded</h1>' +
'<p>Please make sure phaser.min.js is in the phaser directory.</p>';
} else {
// Game configuration
const getGameSize = () => {
const container = document.getElementById('game-container');
if (container) {
return {
width: container.clientWidth,
height: container.clientHeight
};
}
return { width: window.innerWidth, height: window.innerHeight };
};
const gameSize = getGameSize();
const config = {
type: Phaser.AUTO,
width: gameSize.width,
height: gameSize.height,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false,
fps: 120,
fixedStep: true
}
},
scene: [BabyBallGame],
render: {
pixelArt: false,
antialias: true,
roundPixels: false
},
backgroundColor: '#87CEEB',
transparent: false,
resolution: window.devicePixelRatio || 1,
scale: {
mode: Phaser.Scale.RESIZE,
autoCenter: Phaser.Scale.CENTER_BOTH,
parent: 'game-container',
expandParent: true
}
};
const game = new Phaser.Game(config);
// Handle window resize
window.addEventListener('resize', () => {
setTimeout(() => {
const newSize = getGameSize();
if (game.scale) {
game.scale.resize(newSize.width, newSize.height);
}
if (game.scene.scenes.length > 0) {
const scene = game.scene.scenes[0];
if (scene.gameWidth !== undefined && scene.gameHeight !== undefined) {
const oldWidth = scene.gameWidth;
const oldHeight = scene.gameHeight;
scene.gameWidth = newSize.width;
scene.gameHeight = newSize.height;
if (scene.physics && scene.physics.world) {
scene.physics.world.setBounds(0, 0, newSize.width, newSize.height);
}
if (scene.handleResizeCollisions) {
scene.handleResizeCollisions(oldWidth, oldHeight, newSize.width, newSize.height);
}
}
}
}, 100);
});
// Add reset button event listener
document.getElementById('reset-button').addEventListener('click', (event) => {
event.preventDefault();
if (game.scene.scenes.length > 0) {
const scene = game.scene.scenes[0];
if (scene.resetGame) {
scene.resetGame();
}
}
document.getElementById('reset-button').blur();
});
// Add mute button event listener
document.getElementById('mute-button').addEventListener('click', (event) => {
event.preventDefault();
if (game.scene.scenes.length > 0) {
const scene = game.scene.scenes[0];
if (scene.toggleMute) {
scene.toggleMute();
}
}
document.getElementById('mute-button').blur();
});
}