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

Manages player character state, movement, animations, and interactions. More...

#include <vec2.h>
#include <animation.h>
#include <stdbool.h>
#include <gun.h>
#include <particle_emitterpresets.h>
#include <colliders.h>
#include <game.h>
#include <sound.h>

Go to the source code of this file.

Classes

struct  SkillState
 
struct  SkillResources
 
struct  SkillStat
 
struct  PlayerState
 Contains the player's current state information. More...
 
struct  PlayerResources
 Contains the player's resources and timers. More...
 
struct  PlayerStat
 Contains the player's stats and attributes. More...
 
struct  PlayerData
 Main player data structure. More...
 

Typedefs

typedef enum PlayerPassive PlayerPassive
 
typedef struct SkillState SkillState
 
typedef struct SkillResources SkillResources
 
typedef struct SkillStat SkillStat
 
typedef struct PlayerState PlayerState
 Contains the player's current state information.
 
typedef struct PlayerResources PlayerResources
 Contains the player's resources and timers.
 
typedef struct PlayerStat PlayerStat
 Contains the player's stats and attributes.
 
typedef struct PlayerData PlayerData
 Main player data structure.
 

Enumerations

enum  PlayerPassive {
  ARMORED_UP , GHOST_LOAD , HEMO_CYCLE , KINETIC_ARMOR ,
  LAST_STAND , OVER_PRESSURED , SCAVENGER , TOTAL_SKILLS
}
 

Functions

void Player_Input_Handler ()
 Handles player input.
 
int Player_Render ()
 Renders the player.
 
int Player_Start ()
 Initializes the player.
 
int Player_PostUpdate ()
 Post-update operations for player.
 
int Player_Preupdate ()
 Pre-update operations for player.
 
bool Player_DetectCollision ()
 Detects collisions for player.
 
int Player_Move ()
 Moves the player.
 
int Player_Look (Vec2 direction)
 Makes player look in specified direction.
 
void Player_UpdateHitbox ()
 Updates player hitbox.
 
int Player_Dash ()
 Initiates player dash.
 
int Player_HandleDash ()
 Handles ongoing dash state.
 
int Player_CrashOut ()
 Activates crashout ability.
 
int Player_HandleCrashOut ()
 Handles ongoing crashout state.
 
void Player_Shoot ()
 Makes player shoot current weapon.
 
void Player_SwitchGun ()
 Changes player's current weapon.
 
int Player_AnimationInit ()
 Initializes player animations.
 
int Player_AnimationUpdate ()
 Updates player animations.
 
void Skill_Update ()
 
void scavenger ()
 
void Player_TakeDamage (int damage)
 
void Player_RenderDamageEffect ()
 
bool kineticArmor ()
 
bool ghostLoad ()
 
int Parry ()
 
int Handle_ParryRender ()
 
int Handle_Parry ()
 
void Player_PickUpGun (void *data, int interactableIndex)
 Picks up a gun.
 
void Player_OpenCrate (void *data, int interactableIndex)
 Opens a crate This function is a callback when the player interacts with a closed crate.
 
void Player_ReadLog (void *data, int interactableIndex)
 

Variables

PlayerData player
 Global player instance.
 

Detailed Description

Manages player character state, movement, animations, and interactions.

Todo:
Add player stats and abilities struct as well.
Author
Mango
Date
2025-02-28

Typedef Documentation

◆ PlayerData

typedef struct PlayerData PlayerData

Main player data structure.

◆ PlayerPassive

◆ PlayerResources

Contains the player's resources and timers.

◆ PlayerStat

typedef struct PlayerStat PlayerStat

Contains the player's stats and attributes.

◆ PlayerState

typedef struct PlayerState PlayerState

Contains the player's current state information.

◆ SkillResources

◆ SkillStat

typedef struct SkillStat SkillStat

◆ SkillState

typedef struct SkillState SkillState

Enumeration Type Documentation

◆ PlayerPassive

Enumerator
ARMORED_UP 
GHOST_LOAD 
HEMO_CYCLE 
KINETIC_ARMOR 
LAST_STAND 
OVER_PRESSURED 
SCAVENGER 
TOTAL_SKILLS 

Function Documentation

◆ ghostLoad()

bool ghostLoad ( )

◆ Handle_Parry()

int Handle_Parry ( )

◆ Handle_ParryRender()

int Handle_ParryRender ( )

◆ kineticArmor()

bool kineticArmor ( )

◆ Parry()

int Parry ( )

◆ Player_AnimationInit()

int Player_AnimationInit ( )

Initializes player animations.

Returns
Status code

Initializes player animations.

Creates and sets up the player's animation system from the animation data defined in player_data.c.

Returns
int Status code (0 for success, 1 for error)

◆ Player_AnimationUpdate()

int Player_AnimationUpdate ( )

Updates player animations.

Returns
Status code

Updates player animations.

Selects the appropriate animation based on player state (idle or walking) and advances the animation frames.

Returns
int Status code (0 for success)

◆ Player_CrashOut()

int Player_CrashOut ( )

Activates crashout ability.

Returns
Status code

Activates crashout ability.

Takes 25% of the player's current health and gives a 2x damage multiplier for 15 seconds. Has a cooldown before it can be used again.

Returns
int Status code (0 for success, 1 for on cooldown)

◆ Player_Dash()

int Player_Dash ( )

Initiates player dash.

Returns
Status code

Initiates player dash.

Activates the dash ability if off cooldown and player has directional input. Plays dash sound effect and locks direction during dash.

Returns
int Status code (0 for success)
Todo:
[player_skills.c:24] Change dash sfx

◆ Player_DetectCollision()

bool Player_DetectCollision ( )

Detects collisions for player.

Returns
True if collision detected

Detects collisions for player.

Detects if the player is colliding with any objects in the game world and triggers the appropriate response based on collision type.

Returns
bool True if collision detected, false otherwise

◆ Player_HandleCrashOut()

int Player_HandleCrashOut ( )

Handles ongoing crashout state.

Returns
Status code

Handles ongoing crashout state.

Updates visual effects, checks duration, and resets state when completed.

Returns
int Status code (0 for success)

◆ Player_HandleDash()

int Player_HandleDash ( )

Handles ongoing dash state.

Returns
Status code

Handles ongoing dash state.

This is called every frame player.state.dashing is true. Updates dash particle effects and handles dash movement.

Returns
int Status code (0 for success)

◆ Player_Input_Handler()

void Player_Input_Handler ( )

Handles player input.

Handles player input.

Checks keyboard and mouse input to trigger player actions including movement, dashing, weapon switching, and shooting.

◆ Player_Look()

int Player_Look ( Vec2  direction)

Makes player look in specified direction.

Parameters
directionDirection vector
Returns
Status code

Makes player look in specified direction.

Updates the player's direction vector and sets appropriate movement speed. Ignores input if the direction is locked (e.g., during a dash).

Parameters
directionThe direction to move the player in
Returns
int Status code (0 for success)

◆ Player_Move()

int Player_Move ( )

Moves the player.

Returns
Status code

Moves the player.

Applies the player's direction and speed to position, handles collision checking, and updates movement state flags.

Returns
int Status code (0 for success)

◆ Player_OpenCrate()

void Player_OpenCrate ( void *  data,
int  interactableIndex 
)

Opens a crate This function is a callback when the player interacts with a closed crate.

Parameters
dataThe gun data
interactableIndexThe index of the interactable crate.

◆ Player_PickUpGun()

void Player_PickUpGun ( void *  data,
int  interactableIndex 
)

Picks up a gun.

This function is a callback when the player interacts with a gun on the ground.

Parameters
dataThe gun data
interactableIndexThe index of the interactable gun on the ground.
Todo:
[player_combat.c:77] Add gun pickup sfx

◆ Player_PostUpdate()

int Player_PostUpdate ( )

Post-update operations for player.

Returns
Status code

Post-update operations for player.

This function is called inside App_PostUpdate(). It updates the player's input, position, and animations in sequence.

Returns
int Status code (0 for success)

◆ Player_Preupdate()

int Player_Preupdate ( )

Pre-update operations for player.

Returns
Status code

Pre-update operations for player.

Clears movement and location flags to ensure they're recalculated each frame, and resets direction vector if not locked.

Returns
int Status code (0 for success)

◆ Player_ReadLog()

void Player_ReadLog ( void *  data,
int  interactableIndex 
)

◆ Player_Render()

int Player_Render ( )

Renders the player.

Returns
Status code

Renders the player.

Draws the player's character sprite and dash particle effects at the appropriate screen position. Flips the sprite based on mouse cursor position.

Returns
int Status code (0 for success)

◆ Player_RenderDamageEffect()

void Player_RenderDamageEffect ( )

◆ Player_Shoot()

void Player_Shoot ( )

Makes player shoot current weapon.

Makes player shoot current weapon.

Activates the shooting sequence, including sound effects, particle effects for muzzle flash and casings, and creating bullet projectiles.

◆ Player_Start()

int Player_Start ( )

Initializes the player.

Returns
Status code

Initializes the player.

This function is called in App_Start(). It initializes the player's animations and sets the player's current gun to the pistol. Also sets up collision, particle effects, and timers.

Returns
int Status code (0 for success)

◆ Player_SwitchGun()

void Player_SwitchGun ( )

Changes player's current weapon.

Changes player's current weapon.

◆ Player_TakeDamage()

void Player_TakeDamage ( int  damage)

◆ Player_UpdateHitbox()

void Player_UpdateHitbox ( )

Updates player hitbox.

Updates player hitbox.

Recalculates the position of the player's collision hitbox to match their current world position, with appropriate offsets.

◆ scavenger()

void scavenger ( )

◆ Skill_Update()

void Skill_Update ( )

Variable Documentation

◆ player

PlayerData player
extern

Global player instance.

Global player instance.

Contains all default values for the player including position, collision properties, movement speeds, sprite data, and animation definitions.