An enemy attack pattern is the fixed loop an enemy runs every time it attacks: warn, attack, recover. Because it's fixed you can learn it, and the recovery is your opening: the hopper below sits open for 0.7 s after every leap.
- opening (700 ms): you step aside, Nothing to dodge: it stays open n ms more. you swing, Free hit: n ms of the opening left.
Enemy attack patterns: every enemy asks one question
Every enemy asks the two questions Mike Stout names (Game Developer, 2015): "Can you avoid my damage?" during the warning, and "Can you hit me?" during the recovery. Variety comes from the first question, not from more health: the walker asks if you know your reach, the charger if you're in its line, the hopper if you'll move after it commits, the drone if you're still moving.
You're in control from the first frame. The steps are below.
- Press T to show each enemy's state over its head. Green means it's your turn.
- Hopper: wait for it to crouch, then move with ← → after it takes off. Hit it with C while it lands (0.7 s).
- Drones: keep moving. Each one locks its aim halfway through its warning, so the shot goes where you were. Hit them with ↑ + C from the platform.
- At the end there's a walker under a drone: one keeps you busy on the ground while the other shoots.
On a phone you get on-screen buttons: ← → to move, JUMP, and T for the technique.
The real game, running in your browser. The first load fetches the engine; after that it is cached.
Openings: the guard you can't mash
Hit the guard's shield from the front and you get a clang, no damage and a recoil 1.9 times stronger than usual. It asks whether you can wait, and it opens four ways: for 0.85 s after its thrust, from above, from behind, and during the 0.45 s it takes to turn after you dash through it. Against a walker you press attack; against a guard you decide when.
You're in control from the first frame. The steps are below.
- Walk up to the first guard and hit its shield with C: a metal clang, no damage, and you get pushed back almost twice as far.
- Get within about two tiles to provoke its thrust. Back off or dash through with X, then hit it during the 0.85 s its guard is down.
- Or jump over it with Space and strike down with ↓ + C: the shield doesn't cover its head. It also takes 0.45 s to turn around.
- The second guard has a drone overhead. There's no time to wait for openings now: pick which one goes first.
On a phone you get on-screen buttons: ← → to move, JUMP, and T for the technique.
The real game, running in your browser. The first load fetches the engine; after that it is cached.
How to implement enemy attack patterns
- Put the shared loop in one base class: patrol, warning, attack, recovery. Each enemy only decides what to do in each state.
- End every attack in an open state of fixed length, like a recovery, a daze or a landing. An enemy with no opening isn't fair.
- If an attack aims, lock the aim halfway through the warning. A shot that corrects until the last frame can't be dodged by skill.
- Make a shield a check on each hit, not a second collision box: it blocks only slashes from the front while the guard is up.
The code in Godot 4
## ¿Para el escudo este golpe? Sólo los tajos que vienen de frente y con la guardia alta.
func _blocks(hit: Hit) -> bool:
if hit.kind != &"slash" or state == &"recover":
return false
if hit.direction.y > 0.5:
return false # desde arriba: el escudo no cubre la cabeza
if not is_instance_valid(hit.source) or not hit.source is Node2D:
return false
var attacker_side := signf((hit.source as Node2D).global_position.x - global_position.x)
return attacker_side == float(facing) &"windup":
# La puntería sigue al jugador sólo la primera mitad del aviso.
if not _aim_locked and has_target():
_aim = target.global_position
_aim_locked = windup_ratio() >= 0.5
if windup_done():
_shoot()
release(&"cooldown") Each return false is an opening: the guard recovering, a hit from above, a hit from behind.
Quick answers
What is an opening in combat design?
A window where the enemy can't defend or answer and you can hit it freely: the recovery after an attack, a daze, a landing. The drone's is plainer, the 1.5 s between shots.
How many enemy types does a game need?
Fewer than it seems, if each asks a different question. Five plus a boss is enough here, and pairs like a walker under a drone add situations without new code.
Discussion
Comments are hosted on GitHub Discussions — sign in with GitHub to reply.