You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.8 KiB

<!DOCTYPE html>
<html>
<head>
<title>I love X Engine</title>
<style>
body {
margin: 0;
padding: 0;
background: #000;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: Arial, sans-serif;
}
#game {
text-align: center;
}
.welcome-screen {
opacity: 1;
transition: opacity 0.5s;
}
.welcome-screen.hidden {
opacity: 0;
}
h1 {
font-size: 48px;
margin-bottom: 20px;
}
.start-message {
font-size: 24px;
color: #aaa;
}
.hidden {
display: none;
}
#gameCanvas {
border: 1px solid #333;
background: #000;
}
.loader {
width: 48px;
height: 48px;
border: 5px solid #fff;
border-bottom-color: transparent;
border-radius: 50%;
display: inline-block;
box-sizing: border-box;
animation: rotation 1s linear infinite;
margin-bottom: 15px;
}
@keyframes rotation {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#loading {
text-align: center;
}
#loading p {
font-size: 18px;
color: #aaa;
}
</style>
</head>
<body>
<div id="game">
<div id="welcome" class="welcome-screen">
<h1>Welkom bij I love X!</h1>
<p class="start-message">Druk op SPATIE om te beginnen</p>
</div>
<canvas id="gameCanvas" class="hidden"></canvas>
<div id="loading" class="hidden">
<div class="loader"></div>
<p>Loading... <span id="progress">0%</span></p>
</div>
</div>
<script>
const { ipcRenderer } = require('electron');
// Game states
const STATES = {
WELCOME: 'welcome',
LOADING: 'loading',
PLAYING: 'playing',
PAUSED: 'paused',
ERROR: 'error'
};
let gameState = STATES.WELCOME;
let loadingProgress = 0;
// Error handling
window.onerror = function(msg, url, line) {
console.error(`Error: ${msg}\nAt: ${url}:${line}`);
gameState = STATES.ERROR;
ipcRenderer.send('error:occurred', { msg, url, line });
};
// Handle keyboard input
document.addEventListener('keydown', (event) => {
if (event.code === 'Space' && gameState === STATES.WELCOME) {
startGame();
} else if (event.code === 'Escape' && gameState === STATES.PLAYING) {
pauseGame();
}
});
// Start game
function startGame() {
showLoading();
gameState = STATES.LOADING;
ipcRenderer.send('game:start');
}
function showLoading() {
document.getElementById('welcome').classList.add('hidden');
document.getElementById('loading').classList.remove('hidden');
startLoadingProgress();
}
function startLoadingProgress() {
const progressElement = document.getElementById('progress');
const updateProgress = () => {
if (loadingProgress < 100 && gameState === STATES.LOADING) {
loadingProgress += 1;
progressElement.textContent = `${loadingProgress}%`;
setTimeout(updateProgress, 50);
}
};
updateProgress();
}
function pauseGame() {
gameState = STATES.PAUSED;
ipcRenderer.send('game:pause');
}
// Listen for engine events
ipcRenderer.on('engine:ready', (event, data) => {
console.log('Engine ready:', data);
if (gameState === STATES.LOADING) {
document.getElementById('loading').classList.add('hidden');
document.getElementById('gameCanvas').classList.remove('hidden');
gameState = STATES.PLAYING;
}
});
ipcRenderer.on('game:started', () => {
console.log('Game started');
});
ipcRenderer.on('game:paused', () => {
console.log('Game paused');
});
ipcRenderer.on('error:engine', (event, error) => {
console.error('Engine error:', error);
gameState = STATES.ERROR;
});
</script>
</body>
</html>