You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-3
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Since I've already worked on a project to reproduce [PONG](https://armlessjohn40
21
21
* Implement collision mechanics
22
22
~~* Collision with the black hole~~
23
23
~~* Collision with the borders~~
24
-
* Collision between Ships
24
+
~~* Collision between Ships~~
25
25
* Collision between Shots
26
26
* Collision Ship-Shots
27
27
* Create gameover screen
@@ -149,6 +149,41 @@ function addGravity(element, cx, cy, gravity) {
149
149
150
150
## Implement collision mechanics
151
151
### 11:35 - Collision with the black hole
152
-
The black hole spawns any Ship that reaches its position to a random position in the board with `speed=0`.
152
+
The black hole spawns any Ship that reaches its position to a random position in the board with `speed=0`. This is checked in the object's update method.
153
153
### 12:20 - Collision with the borders
154
-
The game board wraps around itself, making it infinite. So, whenever a player or shot reaches the borders, they're spawned back in the other side of the board.
154
+
The game board wraps around itself, making it infinite. So, whenever a player or shot reaches the borders, they're spawned back in the other side of the board. This also happens for the `Shot` class. The collision is checked in the object's update method.
155
+
### 14:00 - Collision between Ships
156
+
When the two players collide, there is an explosion and the game should end. This check is made in the gameloop's update method.
157
+
The collision is calculated using [Separating Axis Theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem). It ended up in a function with 15 constants and a single if statement to tell whether the ships have collided.
I also created an `explode` method in the `Ship` class so when they collide, it shows a satisfying explosion. The explosion have 4 frames of dots generated randomly with varying radius.
0 commit comments