-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-asteroids-game.html
122 lines (114 loc) · 4.99 KB
/
my-asteroids-game.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE HTML>
<html>
<head>
<title>Simeon Atanasov | My Asteroids Game – A Fun JavaScript Project</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="description" content="Dive into Simeon Atanasov's interactive Asteroids Game! Pilot a spaceship through space, dodge and destroy asteroids with dynamic physics, intuitive controls, and endless challenges. Play now!">
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Header -->
<header id="header">
<a href="index.html" class="title">Simeon Atanasov</a>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="power-bi.html">Power BI</a></li>
<li><a href="my-asteroids-game.html" class="active">My Asteroids Game</a></li>
<li><a href="risk-matrix-original.html">Risk Matrix</a></li>
</ul>
</nav>
</header>
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<section id="main" class="wrapper">
<div class="inner">
<header>
<!-- Other generic page content -->
<h1 class="major">Welcome to the Asteroids Game</h1>
</header>
<section>
<p>Embark on an intergalactic adventure in this classic asteroid game, where you control a spaceship, navigate through space, and blast away asteroids. With dynamic physics, intuitive controls, and a constant stream of new challenges, the game keeps you on your toes as you dodge, shoot, and survive. How long can you last in the vast expanse of space?
</p>
</section>
<!-- Game Section -->
<div id="game-container">
<canvas></canvas>
<button id="restartButton" style="display: none;">Restart Game</button>
<button id="soundToggle" style="position: absolute; top: 10px; right: 10px; z-index: 10;">
Sound: Off
</button>
</div>
<br />
<section>
<h2>Canvas Setup</h2>
<ul>
<li>The game takes up the entire browser window when opened separately (<code>canvas.width = window.innerWidth</code>), but here it is displayed within a <code>div</code> container with a specific size.</li>
<li>A 2D rendering context (<code>c</code>) is used for drawing.</li>
</ul>
</section>
<section>
<h2>Game Elements</h2>
<ul>
<li><strong>Player:</strong> A triangular spaceship that can rotate and move forward with inertia. Its position and vertices are updated based on velocity and rotation.</li>
<li><strong>Projectile:</strong> Circular bullets that shoot from the player's ship in the direction of its nose.</li>
<li><strong>Asteroids:</strong> Circular shapes with random sizes, velocities, and spawn locations around the screen.</li>
</ul>
</section>
<section>
<h2>Controls</h2>
<ul>
<li><strong>W:</strong> Thrust forward.</li>
<li><strong>A/D:</strong> Rotate left/right.</li>
<li><strong>S:</strong> Decelerate.</li>
<li><strong>Space:</strong> Shoot projectiles.</li>
</ul>
</section>
<section>
<h2>Physics and Logic</h2>
<ul>
<li><strong>Friction:</strong> Gradually reduces velocity when not thrusting.</li>
<li>
<strong>Collision Detection:</strong>
<ul>
<li><code>circleTriangleCollision:</code> Detects collision between the player (triangle) and asteroids.</li>
<li><code>circleCollision:</code> Handles projectile-asteroid collision.</li>
</ul>
</li>
<li><strong>Game Loop:</strong> The <code>animate</code> function redraws the canvas and updates game elements every frame.</li>
</ul>
</section>
<section>
<h2>Asteroid Spawning</h2>
<ul>
<li>New asteroids appear every 1 seconds (<code>setInterval</code>).</li>
<li>They spawn off-screen and move toward the screen with random velocities.</li>
</ul>
</section>
</section>
</div>
<!-- Footer -->
<footer id="footer" class="wrapper style1-alt">
<div class="inner">
<ul class="menu">
<li>© Simeon. All rights reserved.</li>
<li><a href="">Terms of use</a></li>
<li><a href="privacy-notice.html">Privacy notice</a></li>
<li><a href="cookie-notice.html">Cookie notice</a></li>
</ul>
</div>
</footer>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script src="pages/my-asteroids-game/my-asteroids-game.js" defer></script>
</body>
</html>