Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
enemy_update.c File Reference

Core enemy update system. More...

#include <player.h>
#include <random.h>
#include <enemy.h>
#include <enemy_types.h>
#include <time_system.h>

Functions

void Enemy_Update ()
 [PostUpdate] Updates all active enemies in the game.
 
void Enemy_HandleSpawning (EnemyData *enemy)
 [Utility] Manages the spawning process for an enemy.
 
void Enemy_HandleMovement (EnemyData *enemy)
 [Utility] Handles enemy movement physics and velocity calculations.
 
void Enemy_TryMove (EnemyData *enemy, Vec2 movement)
 [Utility] Attempts to move the enemy by the given vector, checking for collisions.
 
void Enemy_HandleDeath (EnemyData *enemy)
 [Utility] Handles the death of an enemy.
 

Detailed Description

Core enemy update system.

Manages updates for all active enemies, handling state changes, movement physics, collision detection, and AI activation.

Author
Mango
Date
2025-03-05

Function Documentation

◆ Enemy_HandleDeath()

void Enemy_HandleDeath ( EnemyData *  enemy)

[Utility] Handles the death of an enemy.

Sets health to 0, marks as dead, and removes collision. Called when an enemy's health reaches zero or when they spawn inside another object.

Parameters
enemyPointer to the enemy that died

◆ Enemy_HandleMovement()

void Enemy_HandleMovement ( EnemyData *  enemy)

[Utility] Handles enemy movement physics and velocity calculations.

Implements a complex movement system that decomposes velocity into forward and lateral components to apply different physics rules to each, then recombines them.

Parameters
enemyPointer to the enemy to move

◆ Enemy_HandleSpawning()

void Enemy_HandleSpawning ( EnemyData *  enemy)

[Utility] Manages the spawning process for an enemy.

Handles the 1-second delay between the appearance of the [+] indicator and the enemy actually spawning. Also checks for collision at spawn point.

Parameters
enemyPointer to the enemy being spawned
Todo:
[enemy_update.c:62] Play spawn sfx here

◆ Enemy_TryMove()

void Enemy_TryMove ( EnemyData *  enemy,
Vec2  movement 
)

[Utility] Attempts to move the enemy by the given vector, checking for collisions.

Tries to move an enemy to a new position but cancels the movement if a collision would occur with walls, the player, or other enemies.

Parameters
enemyPointer to the enemy to move
movementVector representing the attempted movement

◆ Enemy_Update()

void Enemy_Update ( )

[PostUpdate] Updates all active enemies in the game.

Main update loop for all enemies in the game. Skips dead enemies, handles special states like spawning, and processes movement and death conditions for each enemy.