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

Implements weapon systems including animations, shooting mechanics, and particle effects. More...

#include <animation.h>
#include <vec2.h>
#include <particle_emitterpresets.h>

Go to the source code of this file.

Classes

struct  GunResources
 Resources used by a gun. More...
 
struct  GunState
 Gun state structure. More...
 
struct  GunConfig
 Gun configuration structure. More...
 
struct  GunStats
 Gun statistics structure. More...
 
struct  GunData
 Gun data structure. More...
 

Macros

#define GUN_SHOTGUN_NAME   "Beretta 1301 Tactical"
 Gun name definitions.
 
#define GUN_BATTLE_RIFLE_NAME   "FN SCAR-H"
 
#define GUN_SMG_NAME   "HK UMP45"
 
#define GUN_ASSAULT_RIFLE_NAME   "M4A1 URG-I"
 
#define GUN_PISTOL_NAME   "Glock 17"
 
#define GUN_REVOLVER_NAME   "Chiappa Rhino 200DS"
 
#define GUN_ARMOR_PISTOL_NAME   "FN Five-seveN Mk3 MRD"
 
#define GUN_RAPID_SMG_NAME   "KRISS Vector"
 
#define GUN_PDW_NAME   "FN P90"
 
#define GUN_BURST_RIFLE_NAME   "M16A4"
 
#define GUN_BULLPUP_RIFLE_NAME   "Kel-Tec RFB"
 
#define GUN_AUTO_SHOTGUN_NAME   "Atchisson AA-12"
 
#define BULLET_VELOCITY_SLOW   400
 Bullet velocity constants.
 
#define BULLET_VELOCITY_MID   600
 
#define BULLET_VELOCITY_FAST   800
 
#define BULLET_VELOCITY_REAL_FAST   1000
 

Typedefs

typedef enum Gun Gun
 
typedef enum GunFireMode GunFireMode
 
typedef struct GunResources GunResources
 Resources used by a gun.
 
typedef struct GunState GunState
 Gun state structure.
 
typedef struct GunConfig GunConfig
 Gun configuration structure.
 
typedef struct GunStats GunStats
 Gun statistics structure.
 
typedef struct GunData GunData
 Gun data structure.
 

Enumerations

enum  Gun {
  GUN_NONE = -1 , GUN_PISTOL , GUN_SMG , GUN_SHOTGUN ,
  GUN_ASSAULT_RIFLE , GUN_BATTLE_RIFLE , GUN_REVOLVER , GUN_ARMOR_PISTOL ,
  GUN_RAPID_SMG , GUN_PDW , GUN_BURST_RIFLE , GUN_BULLPUP_RIFLE ,
  GUN_AUTO_SHOTGUN , GUN_COUNT
}
 
enum  GunFireMode { FIREMODE_SEMI , FIREMODE_AUTO , FIREMODE_BURST }
 

Functions

void Gun_UpdatePosition (GunData *gun, Vec2 ownerPosition, Vec2 targetPosition, Vec2 gunOffset)
 Updates gun position, orientation and associated particle emitters.
 
void Gun_AnimationUpdate ()
 Updates gun animations.
 
void Gun_Render ()
 Renders all guns.
 
void Gun_Start ()
 Initializes gun systems.
 
void Gun_Update ()
 Updates gun state.
 

Variables

GunData Gun_Pistol
 Pistol weapon data.
 
GunData Gun_SMG
 SMG weapon data.
 
GunData Gun_Shotgun
 Shotgun weapon data.
 
GunData Gun_AssaultRifle
 Assault rifle weapon data.
 
GunData Gun_BattleRifle
 Battle rifle weapon data.
 
GunData GunList [GUN_COUNT]
 Array of all available guns.
 

Detailed Description

Implements weapon systems including animations, shooting mechanics, and particle effects.

This includes the gun's animations, rendering, and updating.

Author
Mango
Date
2025-03-06

Macro Definition Documentation

◆ BULLET_VELOCITY_FAST

#define BULLET_VELOCITY_FAST   800

◆ BULLET_VELOCITY_MID

#define BULLET_VELOCITY_MID   600

◆ BULLET_VELOCITY_REAL_FAST

#define BULLET_VELOCITY_REAL_FAST   1000

◆ BULLET_VELOCITY_SLOW

#define BULLET_VELOCITY_SLOW   400

Bullet velocity constants.

◆ GUN_ARMOR_PISTOL_NAME

#define GUN_ARMOR_PISTOL_NAME   "FN Five-seveN Mk3 MRD"

◆ GUN_ASSAULT_RIFLE_NAME

#define GUN_ASSAULT_RIFLE_NAME   "M4A1 URG-I"

◆ GUN_AUTO_SHOTGUN_NAME

#define GUN_AUTO_SHOTGUN_NAME   "Atchisson AA-12"

◆ GUN_BATTLE_RIFLE_NAME

#define GUN_BATTLE_RIFLE_NAME   "FN SCAR-H"

◆ GUN_BULLPUP_RIFLE_NAME

#define GUN_BULLPUP_RIFLE_NAME   "Kel-Tec RFB"

◆ GUN_BURST_RIFLE_NAME

#define GUN_BURST_RIFLE_NAME   "M16A4"

◆ GUN_PDW_NAME

#define GUN_PDW_NAME   "FN P90"

◆ GUN_PISTOL_NAME

#define GUN_PISTOL_NAME   "Glock 17"

◆ GUN_RAPID_SMG_NAME

#define GUN_RAPID_SMG_NAME   "KRISS Vector"

◆ GUN_REVOLVER_NAME

#define GUN_REVOLVER_NAME   "Chiappa Rhino 200DS"

◆ GUN_SHOTGUN_NAME

#define GUN_SHOTGUN_NAME   "Beretta 1301 Tactical"

Gun name definitions.

◆ GUN_SMG_NAME

#define GUN_SMG_NAME   "HK UMP45"

Typedef Documentation

◆ Gun

typedef enum Gun Gun

◆ GunConfig

typedef struct GunConfig GunConfig

Gun configuration structure.

Contains positioning data and particle effect configurations for a gun

◆ GunData

typedef struct GunData GunData

Gun data structure.

Complete definition of a gun, including name, resources, state, config, stats, and animation data

◆ GunFireMode

typedef enum GunFireMode GunFireMode

◆ GunResources

typedef struct GunResources GunResources

Resources used by a gun.

◆ GunState

typedef struct GunState GunState

Gun state structure.

Contains the runtime state information for a gun

◆ GunStats

typedef struct GunStats GunStats

Gun statistics structure.

Contains the configuration values that define a gun's capabilities

Enumeration Type Documentation

◆ Gun

enum Gun
Enumerator
GUN_NONE 
GUN_PISTOL 
GUN_SMG 
GUN_SHOTGUN 
GUN_ASSAULT_RIFLE 
GUN_BATTLE_RIFLE 
GUN_REVOLVER 
GUN_ARMOR_PISTOL 
GUN_RAPID_SMG 
GUN_PDW 
GUN_BURST_RIFLE 
GUN_BULLPUP_RIFLE 
GUN_AUTO_SHOTGUN 
GUN_COUNT 

◆ GunFireMode

Enumerator
FIREMODE_SEMI 

Semi-automatic (one shot per trigger pull)

FIREMODE_AUTO 
FIREMODE_BURST 

Fully automatic (continuous fire while trigger held)

Function Documentation

◆ Gun_AnimationUpdate()

void Gun_AnimationUpdate ( )

Updates gun animations.

Updates gun animations.

Selects the appropriate animation clip based on gun orientation and advances the animation frame.

◆ Gun_Render()

void Gun_Render ( )

Renders all guns.

Renders all guns.

Draws the current weapon with proper rotation and flipping, and renders muzzle flash and casing particles with correct layering based on weapon orientation.

◆ Gun_Start()

void Gun_Start ( )

Initializes gun systems.

Initializes gun systems.

Populates the gun list with all weapon types, assigns particle emitter presets, and creates animation resources for each gun.

◆ Gun_Update()

void Gun_Update ( )

Updates gun state.

Updates gun state.

Updates the gun's position relative to the player, calculates the angle based on mouse position, and updates particle emitter positions for muzzle flash and casings. Flips the gun sprite horizontally when aiming to the left.

◆ Gun_UpdatePosition()

void Gun_UpdatePosition ( GunData *  gun,
Vec2  ownerPosition,
Vec2  targetPosition,
Vec2  gunOffset 
)

Updates gun position, orientation and associated particle emitters.

Parameters
gunPointer to the gun data structure
ownerPositionPosition of the entity that owns the gun
targetPositionPosition to aim at (usually player position)
gunOffsetAdditional offset from owner position

A generalized function to handle gun positioning, orientation, and particle emitter updates for any entity (player or enemy) that uses a gun. This eliminates duplicate code across different enemy types.

Parameters
gunPointer to the gun data structure
ownerPositionPosition of the entity that owns the gun
targetPositionPosition to aim at (usually player position)
gunOffsetAdditional offset from owner position

Variable Documentation

◆ Gun_AssaultRifle

GunData Gun_AssaultRifle
extern

Assault rifle weapon data.

Global definition for the assault rifle gun type

◆ Gun_BattleRifle

GunData Gun_BattleRifle
extern

Battle rifle weapon data.

Global definition for the battle rifle gun type

◆ Gun_Pistol

GunData Gun_Pistol
extern

Pistol weapon data.

Global definition for the pistol gun type

◆ Gun_Shotgun

GunData Gun_Shotgun
extern

Shotgun weapon data.

Global definition for the shotgun gun type

◆ Gun_SMG

GunData Gun_SMG
extern

SMG weapon data.

Global definition for the submachine gun type

◆ GunList

GunData GunList[GUN_COUNT]
extern

Array of all available guns.