Below is a complete response to your query. I'll break it down into two parts as requested:
- Enemy Design: I'll describe a custom enemy for your 2D top-down action roguelike game with a MOBA-like combat system. This includes its concept, stats, abilities, and how it fits into the game's mechanics.
- AI Script in GDScript: I'll provide a GDScript implementation for the enemy's AI. This script combines behaviors like chasing, walking around (patrolling or wandering), and using abilities. It uses a simple state machine to manage these behaviors, making it modular and extensible.
1. Enemy Design
For a 2D top-down action roguelike with MOBA-like combat, enemies should feel dynamic, strategic, and challenging. They need to have auto-attacks, abilities with cooldowns, and intelligent behaviors to encourage player positioning and decision-making (e.g., kiting or dodging).
Enemy Concept: "Shadow Stalker"
-
Description: The Shadow Stalker is a stealthy, agile enemy that embodies the roguelike's procedural and unpredictable nature while incorporating MOBA elements like ability combos and positioning. It's a humanoid shadow creature that lurks in dark areas of the procedurally generated levels. It starts off passive, wandering around to scout, but becomes aggressive when it detects the player. Its design rewards players who use terrain, abilities, and timing to outmaneuver it.
-
Appearance: A dark, ethereal figure with glowing red eyes and tendrils of shadow. In a 2D top-down view, it could be represented as a sprite with animations for walking, attacking, and ability usage (e.g., fading in/out for stealth).
-
Role in the Game: As a mid-tier enemy, it serves as a common foe in early to mid-game levels. It encourages players to manage distance and use abilities strategically, similar to MOBA minions or early-game champions. In a roguelike context, it could spawn in packs or adapt to the player's build (e.g., faster if the player is a melee class).
-
Stats (Adjust these based on your game's balance):
- Health: 150 HP (moderate durability, allowing for a few hits before defeat).
- Damage: 20 base damage (from basic auto-attacks).
- Speed: 200 pixels/second (fast enough to chase but not overwhelming, promoting kiting).
- Detection Range: 300 pixels (how far it can "see" the player to start chasing).
- Attack Range: 50 pixels (melee range, forcing close-quarters combat).
- Ability Cooldowns: 5-10 seconds per ability to mimic MOBA timing.
-
Abilities (MOBA-inspired, with cooldowns and strategic use):
- Basic Attack: A quick melee swing that deals damage if the player is in range. This is an auto-attack with a 1-second cooldown, like a MOBA auto-attack.
- Shadow Dash (Offensive Ability): The enemy dashes forward 150 pixels in the direction of the player, dealing 30 damage on impact and briefly stunning the player for 0.5 seconds. Cooldown: 8 seconds. This ability is used when chasing and the player is just out of reach, rewarding players who predict and dodge it.
- Vanish (Defensive/Utility Ability): The enemy becomes invisible and gains a speed boost (50% increase) for 3 seconds, allowing it to reposition or escape. Cooldown: 10 seconds. This is triggered when the enemy is low on health or when it needs to close a gap after patrolling.
-
Behaviors:
- Chasing: If the player enters detection range, the enemy prioritizes moving toward them, using abilities to close gaps.
- Walking Around: When idle, it patrols randomly within a small area (e.g., 100-200 pixels radius) to simulate scouting. This makes levels feel alive and gives players opportunities to avoid or ambush.
- Using Abilities: Abilities are used based on conditions (e.g., Shadow Dash when the player is fleeing, Vanish when health is below 50%). This adds MOBA-like depth, as players must react to ability cues (e.g., visual effects or audio cues).
- Other Mechanics: The enemy could have weaknesses, like taking extra damage from light-based player abilities, tying into roguelike itemization and strategy.
This design ensures the enemy is engaging without being overly complex, fitting the roguelike's replayability and the MOBA's tactical combat.
2. AI Script in GDScript
I'll write the AI script assuming you're using Godot Engine (version 4.x, as it's the latest). The enemy will be a CharacterBody2D node, which is ideal for 2D top-down movement. The script uses a state machine to handle the combined behaviors (chasing, walking around, and using abilities).
- Key Features of the Script:
- State Machine: Uses an enum for states (IDLE, PATROLLING, CHASING, ATTACKING). This allows smooth transitions between behaviors.
- Chasing: Detects the player within a range and moves toward them.
- Walking Around: If no player is detected, the enemy wanders randomly (simulating patrolling).
- Using Abilities: Abilities are triggered based on conditions (e.g., distance to player, cooldown timers). I use Godot's Timer nodes for cooldowns.
- Movement: Uses
velocity and move_and_slide for smooth 2D movement.
- Detection: Uses Godot's built-in physics for raycasting or area detection to find the player.
- Edge Cases: Handles things like ability cooldowns, state transitions, and basic collision.
Attach this script to your enemy scene's root node (e.g., a CharacterBody2D named "ShadowStalker").
Explanation of the Script:
- State Machine: The
state variable drives the behavior. It checks distances and timers to transition between states.
- Chasing: In the
CHASING state, the enemy moves toward the player and uses abilities like Shadow Dash if available.
- Walking Around: In
PATROLLING, the enemy moves in a random direction and changes it periodically, with a chance to use Vanish.
- Using Abilities: Abilities are called conditionally (e.g., in
handle_chasing). Timers ensure cooldowns are respected.
- Movement and Physics: Uses Godot's
velocity and move_and_slide for smooth, collision-aware movement.
- Extensibility: You can add more states, abilities, or conditions (e.g., line-of-sight checks using RayCast2D). Make sure to handle player interactions (e.g.,
player.take_damage) in your player's script.
This script is a solid starting point. Test it in Godot, tweak values for balance, and expand as needed for your game's specifics! If you have more details (e.g., custom animations or level integration), I can refine this further.