|
3 | 3 | <head>
|
4 | 4 | <meta charset="UTF-8">
|
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
| - <title>Your SDL Project</title> |
| 6 | + <title>Flappy Bird!</title> |
| 7 | + <link rel="stylesheet" href="style.css"> |
7 | 8 | </head>
|
8 |
| -<body style="margin: 0; display: flex; flex-direction: column; align-items: center; padding-top: 16px;"> |
9 |
| - <button type="button" id="game-start-button"> |
10 |
| - <span>Start Game!</span> |
11 |
| - </button> |
| 9 | +<body> |
| 10 | + <!-- Header --> |
| 11 | + <header class="header"> |
| 12 | + <img src="assets/logo.png" alt="Game Logo" class="logo"> |
| 13 | + <h1>Flappy Bird!</h1> |
| 14 | + <br> |
| 15 | + <p class="developer">by Kordeyrow</p> |
| 16 | + <br> |
| 17 | + </header> |
12 | 18 |
|
13 |
| - <div id="game-container"> |
14 |
| - <div id="status">Loading...</div> |
15 |
| - <canvas id="game-board" width="500" height="600" style="display:none"></canvas> |
16 |
| - </div> |
| 19 | + <!-- Main content --> |
| 20 | + <main class="main-content"> |
| 21 | + <div id="game-container" class="game-container"> |
| 22 | + <button type="button" id="game-start-button" class="start-button">Play Game!</button> |
| 23 | + <div id="status" class="loading">Loading...</div> |
| 24 | + <canvas id="game-board" width="460px" height="640px" style="display:none"></canvas> |
| 25 | + </div> |
| 26 | + |
| 27 | + <div class="game-description"> |
| 28 | + <p>Built with SDL.</p> |
| 29 | + </div> |
| 30 | + |
| 31 | + <!-- GitHub link --> |
| 32 | + <div class="github-link"> |
| 33 | + <a href="https://github.com/Kordeyrow/flappy-bird-sdl" target="_blank">View on GitHub</a> |
| 34 | + </div> |
| 35 | + </main> |
| 36 | + |
| 37 | + <!-- Footer --> |
| 38 | + <footer class="footer"> |
| 39 | + <p>© 2024 Kordeyrow.</p> |
| 40 | + </footer> |
17 | 41 |
|
18 | 42 | <script>
|
19 |
| - // Flag to check if the start button was clicked |
20 | 43 | let startGameRequested = false;
|
21 | 44 |
|
22 |
| - // Emscripten Module setup |
23 | 45 | var Module = {
|
24 |
| - // This function runs after the WebAssembly runtime is fully initialized |
25 | 46 | onRuntimeInitialized() {
|
26 | 47 | const status = document.getElementById('status');
|
27 |
| - status.remove(); |
| 48 | + status.style.display = 'none'; // Hide loading after initialization |
28 | 49 |
|
29 |
| - // Only call start_game if the start button was clicked |
30 | 50 | if (startGameRequested) {
|
31 | 51 | Module.ccall('start_game', null, [], []);
|
32 | 52 | }
|
33 | 53 | },
|
34 |
| - canvas: (function () { |
35 |
| - const canvas = document.getElementById('game-board'); |
36 |
| - return canvas; |
37 |
| - })(), |
38 |
| - // Prevents main() from automatically starting |
| 54 | + canvas: document.getElementById('game-board'), |
39 | 55 | noInitialRun: true
|
40 | 56 | };
|
41 | 57 |
|
42 |
| - // DOM Elements |
43 | 58 | const startGameButton = document.getElementById('game-start-button');
|
44 | 59 | const canvas = document.getElementById('game-board');
|
| 60 | + const status = document.getElementById('status'); |
45 | 61 |
|
46 |
| - // Button event listener to start the game |
47 | 62 | startGameButton.addEventListener('click', () => {
|
48 | 63 | canvas.style.display = 'block';
|
49 |
| - startGameButton.remove(); |
50 |
| - startGameRequested = true; // Set the flag to indicate start was requested |
| 64 | + startGameButton.style.display = 'none'; // Hide button |
| 65 | + status.style.display = 'flex'; // Show loading message |
| 66 | + startGameRequested = true; |
51 | 67 |
|
52 |
| - // Dynamically load the game script only when the button is clicked |
53 |
| - var script = document.createElement('script'); |
| 68 | + const script = document.createElement('script'); |
54 | 69 | script.src = "./flappy-bird.js";
|
55 | 70 | document.body.appendChild(script);
|
56 | 71 | });
|
|
0 commit comments