Submarine Runner Game is an underwater-themed action game where the player controls a submarine navigating through challenging environments, avoiding obstacles, and using power-ups to survive and defeat AI-controlled submarines while avoiding getting eaten by a shark.
The game consists of two types of submarines:
- Player Submarine: Controlled by the player using keyboard or controller inputs.
- AI Submarines: Enemies that patrol the environment, chase the player, and interact with the game world based on certain conditions.
The player must survive by using power-ups, avoiding obstacles, and outsmarting the AI submarines.
-
Player Submarine:
- The player can rotate the submarine upward and downward by pressing the space bar.
- Power-ups provide temporary enhancements such as speed boosts, teleportation, and disabling enemies.
- TURBO: Temporarily boosts the player's submarine speed.
- TELEPORT: Teleports the player submarine to a new location.
- FISHNET: Fires a net projectile that disables AI submarines.
- EMP: Disables nearby AI submarines with an EMP pulse.
- REVERSE_CONTROL: Reverses the movement controls of AI submarines.
-
AI Submarine:
- The AI submarines have an obstacle avoidance system using AI sensors that calculate whether to turn up or down based on obstacles in front of them.
-
Shark:
- The shark automatically targets the submarine in front of it and consumes it when in range.
The Submarine Runner Game is designed with a modular and maintainable codebase, utilizing key design principles to ensure scalability, flexibility, and ease of modification.
-
Player Submarine
- The player submarine is handled by a dedicated
PlayerSubmarineControllerclass, which controls its movement, power-ups, and interactions with the game world. - It implements logic for player input, such as acceleration, deceleration, and power-up activation.
- The power-ups are implemented as distinct components, which can be added to the player submarine and activated by using certain key inputs.
- The player submarine is handled by a dedicated
-
AI Submarine
-
The AI Submarine uses an obstacle avoidance system that relies on AI sensors to detect environmental hazards and adjust its movement accordingly. It avoids obstacles by determining whether it needs to steer up or down, based on the readings from its sensors:
- The top sensor detects obstacles above the submarine and causes it to steer downward.
- The bottom senso detects obstacles below the submarine and causes it to steer upward.
- The center sensor checks for obstacles directly ahead and adjusts the steering depending on their position.
-
The AISubmarine follows an autonomous movement model controlled by the
AISubmarineControllerclass. This controller uses the readings from the sensors to decide whether to move up, down, or rotate based on proximity to obstacles or other stimuli. -
Behavior and Decision-Making:
- If the submarine encounters an obstacle, the AISubmarine automatically adjusts its rotation to avoid collisions. For example, it can rotate up or down depending on where the obstacle is detected.
-
-
Power-ups
-
Power-ups in the game are special items that grant the player submarine enhanced abilities, allowing them to gain advantages or overcome specific challenges. The power-ups are defined as distinct classes, each implementing unique behaviors. When the player submarine collects a power-up, it activates the associated effect.
PowerUp Types:
-
The following power-ups are currently implemented:
- TURBO: Temporarily boosts the speed of the player submarine.
- TELEPORT: Teleports the player submarine to a nearby position.
- FISHNET: Launches a net that disables the movement of AI submarines.
- EMP: Temporarily disables enemy AI submarines by emitting an electromagnetic pulse.
- REVERSE_CONTROL: Reverses the movement controls of AI submarines.
PowerUp Class
- The base
PowerUpclass defines common behavior such as detecting collisions and triggering effects through theUsePowerUpmethod. Each specific power-up overrides this method to implement its unique behavior.
PowerUp Manager
- Manages power-up spawning and collection. Power-ups are randomly placed in the game world and are triggered when collected by the player submarine.
Specific PowerUp Implementations:
- EMPPowerUp: Disables AI submarines by triggering the
ConfigEMPmethod. - FishnetPowerUp: Fires a projectile that disables AI submarines.
- ReversePowerUp: Fires a projectile that flips AI submarine controls.
- TeleportPowerUp: Teleports the player submarine to a new location.
- TurboPowerUp: Increases player speed temporarily.
-
-
-
Game Manager
- The
GameManagerclass oversees the overall game flow, including the spawning of submarines, power-ups, and controlling the game state (e.g., start, pause, game over). - It also manages the scoring and handling the game's difficulty progression, such as increasing AI submarine speed and frequency of power-up spawns.
- The
- Observer Pattern: Power-ups and game events use the Observer pattern to notify relevant entities (like the player or AI) when changes occur (e.g., power-up pickup, game over).
- Singleton Pattern: The
GameManageris implemented as a singleton to ensure only one instance controls the overall game flow, keeping the game state consistent.
The code is organized into the following main folders:
- Controllers: Contains scripts for player and AI submarine behavior, game management, and UI controls.
- PowerUps: Contains scripts defining each power-up type and its behavior.
- Models: Holds data structures and classes for managing submarine states, power-up configurations, and other game models.
- Utilities: Contains helper scripts for tasks like event management, and sensor systems.
The architecture is designed with scalability in mind, allowing for:
- Adding new power-ups and AI behaviors easily by creating new classes and extending existing systems.
- Expanding the game world by introducing new types of obstacles, power-ups, and submarine types without disrupting the existing codebase.
The modular approach ensures that each component of the game is loosely coupled and easy to test individually, making the development process more efficient and reducing the risk of bugs.
This project represents my individual development efforts, where I solely created the code base for a game creative in Kwalee, with art being provided by various other colleagues. Feedback, suggestions, and collaborative contributions are highly encouraged. If you're passionate about mesh deformation techniques, Unity development workflows, or procedural generation, I’d love to connect!
You can connect with me on LinkedIn: Bhawesh Agarwal. Feel free to reach out if you're interested in discussing the game's mechanics, and development process, or if you simply want to talk about game design and development.