Water Hazards
- seanmcgarry65
- Jan 27, 2023
- 2 min read
This week, another new enemy, the Zora, was added to the game, as well as drowning mechanics. Two new items were also implemented, the bow and the potion, though there is currently no way to access them.

The Zora is an enemy that lives in water and periodically emerges to fire projectiles at the player. The implementation of drowning mechanics prevents the player from being able to walk over water.

This code controls the behavior of the Zora. It starts under the water, emerges, fires, then submerges again. While it is underwater it cannot be hurt by the player's weapons, or anything else. Unlike other enemies, the Zora doesn't move on its own, so it will always emerge from the same spot.

The Zora's bullet is destroyed on contact with solid objects, the player, or if it flies offscreen.

The first part of the drowning code sets a respawn point for the player so that they are not constantly drowning until they die if they step in the water.

When the player steps in water, they're set to be invisible, invincible, the controls are disabled, and a splash object is spawned, all while a sound plays. A moment later, the player is teleported back to the previously set spawn point, controls are re-enabled, the player is made visible and vulnerable again, and 5 health is subtracted from their hitpoints.

The two new items are the Bow and the Potion. The bow is a long-range weapon that fires arrows and allows the player to damage distant enemies, while the potion restores 25 hitpoints when used.

When the bow is used, it spawns an arrow bullet, and starts a cooldown timer. The player cannot fire another arrow until the cooldown is up. Meanwhile, once the arrow is spawned, it's rotated so that it faces and moves in the same direction the player was facing when they fired it.

On collision with a solid object, an enemy, or if it flies offscreen, the arrow is destroyed, much like the bullets fired by enemies at the player.

When the player uses a potion, it restores one quarter of their maximum health. It is then removed from their inventory, to prevent the player from spamming it and gaining infinite health.
The game can be played by following the link below.
Comments