This commit is contained in:
Joowon Kim 2025-05-11 12:52:56 +09:00
parent 9ec95b775c
commit 4a130072c4
2 changed files with 17 additions and 3 deletions

View File

@ -8,6 +8,7 @@
- https://github.com/joowonkime/Mario-fan-game - https://github.com/joowonkime/Mario-fan-game
# 3. Youtube Video Link # 3. Youtube Video Link
https://youtu.be/_2y0Jxiq-nE
# 4. Explanation of Game # 4. Explanation of Game
@ -319,9 +320,9 @@ Returns the shouldDestroy flag to indicate if the bomb should be removed.
Creates a missile object at a given location with a lifeTime of 20 seconds. Creates a missile object at a given location with a lifeTime of 20 seconds.
#### update() #### update()
If a player collides horizontally with the missile, they are pushed along the missile's direction. If a player collides horizontally(X) with the missile, they are pushed along the missile's direction.
If a player collides vertically, they can stand on top of the missile like a platform. If a player collides vertically(Y), they can stand on top of the missile like a platform.
Collision detection is handled by hits(). Collision detection is handled by hits().
@ -336,9 +337,13 @@ Returns the shouldDestroy flag to indicate if the missile should be removed.
Functions similarly to other object classes. Items are spawned mid-air via randomSpawnItem() and fall due to gravity until they land on a tile. Functions similarly to other object classes. Items are spawned mid-air via randomSpawnItem() and fall due to gravity until they land on a tile.
Collision with the player is checked using the hits() method. Collision with the player is checked using the hits() method.
When picked up, the item's toRemove flag is set to true. When picked up, the item's toRemove flag is set to true.
#### update()
In update, we continuously check whether the tile in the position it is placed in is broken or not, and if it is broken, we change it to stuck = false and make it fall back down due to gravity.
### drawUI(): ### drawUI():
Renders a UI panel on the bottom-left and bottom-right corners of the screen, showing each player's current status and resources. Renders a UI panel on the bottom-left and bottom-right corners of the screen, showing each player's current status and resources.
### drawVictoryScreen(): ### drawVictoryScreen():
When gameOver is true, a victory screen is displayed in the center of the canvas showing the winners sprite along with the text "YOU WIN!". When gameOver is true, a victory screen is displayed in the center of the canvas showing the winners sprite along with the text "YOU WIN!".
### window.addEventListener("keydown", )
By using e.preventDefault(), I prevented the screen from scrolling when the player uses the arrow keys, eliminating the inconvenience of the game screen moving.

View File

@ -48,6 +48,13 @@ function preload() {
preloadSounds(); preloadSounds();
} }
window.addEventListener("keydown", function(e) {
const blockedKeys = [37, 38, 39, 40];
if (blockedKeys.includes(e.keyCode)) {
e.preventDefault();
}
}, false);
function setup() { function setup() {
createCanvas(800, 600); createCanvas(800, 600);
sliceAssets(); sliceAssets();
@ -720,6 +727,8 @@ class Bomb {
return this.shouldRemove; return this.shouldRemove;
} }
} }
class BigMissile { class BigMissile {
constructor(x, y, vx) { constructor(x, y, vx) {
this.spawnTime = millis(); this.spawnTime = millis();