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

This file contains the definition of the EnemyData struct and its functions. More...

#include <SDL.h>
#include <vec2.h>
#include <colliders.h>
#include <animation.h>
#include <timer.h>
#include <particle_emitterpresets.h>
#include <chunks.h>

Go to the source code of this file.

Classes

struct  EnemyState
 Enemy state structure. More...
 
struct  EnemyStats
 Enemy statistics structure. More...
 
struct  EnemyResources
 Enemy resources structure. More...
 
struct  EnemyData
 Enemy data structure. More...
 

Macros

#define ENEMY_MAX   100
 

Typedefs

typedef struct EnemyState EnemyState
 Enemy state structure.
 
typedef struct EnemyStats EnemyStats
 Enemy statistics structure.
 
typedef struct EnemyResources EnemyResources
 Enemy resources structure.
 
typedef struct EnemyData EnemyData
 Forward declaration of EnemyData structure.
 

Enumerations

enum  EnemyType {
  ENEMY_TYPE_PROXY , ENEMY_TYPE_ECHO , ENEMY_TYPE_KAMIKAZE , ENEMY_TYPE_RECHARGE ,
  ENEMY_TYPE_VANTAGE , ENEMY_TYPE_RADIUS , ENEMY_TYPE_SABOT , ENEMY_TYPE_TACTICIAN ,
  ENEMY_TYPE_JUGGERNAUT , ENEMY_TYPE_SENTRY , ENEMY_TYPE_LIBET , ENEMY_TYPE_COUNT
}
 Enemy type enumeration. More...
 

Functions

void Enemy_Init ()
 [Start] Initializes the enemy system
 
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.
 
void EnemyManager_Update ()
 [PostUpdate] Updates the enemy management system
 
void EnemyManager_RenderClearText ()
 
void Enemy_Render ()
 [Render] Renders all active enemies
 
void Enemy_Destroy ()
 
void Enemy_Spawn (EnemyData data, Vec2 position)
 [Utility] Spawns an enemy of the given type at the specified position
 
void Enemy_TakeDamage (EnemyData *enemy, int damage)
 [Utility] Applies damage to an enemy
 
void Enemy_CreateHealthText (Vec2 position, int damage)
 
void Enemy_UpdateHealthTexts ()
 
void Enemy_RenderHealthTexts ()
 
int EnemyManage_CountEnemyInChunk (EnvironmentChunk *chunk)
 [Utility] Counts the number of active enemies in a specific chunk
 

Variables

ParticleEmitter * TacticianBuffEffectEmitter
 
EnemyData * enemyList [ENEMY_TYPE_COUNT]
 
EnemyData enemies [ENEMY_MAX]
 Array of enemies.
 
SDL_Texture * Enemy_spawnIndicator
 Texture for enemy spawn indicator.
 

Detailed Description

This file contains the definition of the EnemyData struct and its functions.

Author
Mango
Date
2025-03-18

Macro Definition Documentation

◆ ENEMY_MAX

#define ENEMY_MAX   100

Typedef Documentation

◆ EnemyData

typedef struct EnemyData EnemyData

Forward declaration of EnemyData structure.

Enemy data structure.

Complete definition of an enemy, including type, state, stats, resources, animation data, and function pointers for behavior

◆ EnemyResources

Enemy resources structure.

Contains pointers to runtime resources needed by the enemy

◆ EnemyState

typedef struct EnemyState EnemyState

Enemy state structure.

Contains the current runtime state information for an enemy, including position, movement, collision, and health status

◆ EnemyStats

typedef struct EnemyStats EnemyStats

Enemy statistics structure.

Contains the configuration values that define an enemy's capabilities

Enumeration Type Documentation

◆ EnemyType

enum EnemyType

Enemy type enumeration.

Defines the different types of enemies in the game

Enumerator
ENEMY_TYPE_PROXY 
ENEMY_TYPE_ECHO 
ENEMY_TYPE_KAMIKAZE 
ENEMY_TYPE_RECHARGE 
ENEMY_TYPE_VANTAGE 
ENEMY_TYPE_RADIUS 
ENEMY_TYPE_SABOT 
ENEMY_TYPE_TACTICIAN 
ENEMY_TYPE_JUGGERNAUT 
ENEMY_TYPE_SENTRY 
ENEMY_TYPE_LIBET 
ENEMY_TYPE_COUNT 

Function Documentation

◆ Enemy_CreateHealthText()

void Enemy_CreateHealthText ( Vec2  position,
int  damage 
)

◆ Enemy_Destroy()

void Enemy_Destroy ( )

◆ 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_Init()

void Enemy_Init ( )

[Start] Initializes the enemy system

Prepares all enemy slots as inactive and loads necessary textures.

◆ Enemy_Render()

void Enemy_Render ( )

[Render] Renders all active enemies

Iterates through the enemy array and calls each enemy's specific render function if they are active.

◆ Enemy_RenderHealthTexts()

void Enemy_RenderHealthTexts ( )

◆ Enemy_Spawn()

void Enemy_Spawn ( EnemyData  data,
Vec2  position 
)

[Utility] Spawns an enemy of the given type at the specified position

Creates a new enemy instance based on the provided template and initializes it at the given position. If no position is provided (NULL), a random valid position is chosen.

Parameters
dataThe enemy data template to use for spawning
positionPosition vector for enemy spawn location

◆ Enemy_TakeDamage()

void Enemy_TakeDamage ( EnemyData *  enemy,
int  damage 
)

[Utility] Applies damage to an enemy

Reduces an enemy's health based on the damage amount. Enemies with 0 or less health after damage will be marked for death processing.

Parameters
enemyPointer to the enemy to damage
damageAmount of damage to apply

◆ 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.

◆ Enemy_UpdateHealthTexts()

void Enemy_UpdateHealthTexts ( )

◆ EnemyManage_CountEnemyInChunk()

int EnemyManage_CountEnemyInChunk ( EnvironmentChunk *  chunk)

[Utility] Counts the number of active enemies in a specific chunk

Parameters
chunkPointer to the chunk to check
Returns
int Number of active enemies in the chunk

◆ EnemyManager_RenderClearText()

void EnemyManager_RenderClearText ( )

◆ EnemyManager_Update()

void EnemyManager_Update ( )

[PostUpdate] Updates the enemy management system

Handles enemy spawning, despawning, and room transitions. Manages which enemies are active based on player position.

Todo:
[enemy_manager.c:87] Add enemy spawning sfx here (Aka the red [+] thing appearing)

Variable Documentation

◆ enemies

EnemyData enemies[ENEMY_MAX]
extern

Array of enemies.

Holds all the enemies in the game

Array of enemies.

◆ Enemy_spawnIndicator

SDL_Texture* Enemy_spawnIndicator
extern

Texture for enemy spawn indicator.

◆ enemyList

EnemyData* enemyList[ENEMY_TYPE_COUNT]
extern

◆ TacticianBuffEffectEmitter

ParticleEmitter* TacticianBuffEffectEmitter
extern