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

Implements environment chunks that form game maps and rooms. More...

#include <tiles.h>
#include <colliders.h>

Go to the source code of this file.

Classes

struct  EnvironmentChunk
 Represents a chunk of the environment. More...
 

Macros

#define HALLWAY_SIZE_TILE   6
 Width/height of hallway in tiles.
 
#define CHUNK_SIZE_TILE   60
 Size of a chunk in tiles.
 
#define CHUNK_SIZE_PIXEL   (CHUNK_SIZE_TILE * TILE_SIZE_PIXELS)
 Size of a chunk in pixels.
 
#define HALLWAY_START   (CHUNK_SIZE_TILE - HALLWAY_SIZE_TILE) / 2
 Starting position of hallway within a chunk.
 
#define HALLWAY_END   HALLWAY_START + HALLWAY_SIZE_TILE
 Ending position of hallway within a chunk.
 
#define ROOM_STARTX(roomsize)   (CHUNK_SIZE_TILE - (roomsize).x) / 2
 Starting X position of a room based on its size.
 
#define ROOM_STARTY(roomsize)   (CHUNK_SIZE_TILE - (roomsize).y) / 2
 Starting Y position of a room based on its size.
 
#define ROOM_ENDX(roomsize)   ROOM_STARTX(roomsize) + (roomsize).x
 Ending X position of a room based on its size.
 
#define ROOM_ENDY(roomsize)   ROOM_STARTY(roomsize) + (roomsize).y
 Ending Y position of a room based on its size.
 

Enumerations

enum  RoomHallways {
  HALLWAY_NONE = 0 , HALLWAY_UP = 1 << 0 , HALLWAY_DOWN = 1 << 1 , HALLWAY_LEFT = 1 << 2 ,
  HALLWAY_RIGHT = 1 << 3
}
 Possible hallways directions in a room. More...
 
enum  RoomFloorPattern { ROOM_FLOOR_PATTERN_1 , ROOM_FLOOR_PATTERN_RANDOM }
 Possible floor patterns in a room. More...
 
enum  RoomType {
  ROOM_TYPE_START , ROOM_TYPE_NORMAL , ROOM_TYPE_BOSS , ROOM_TYPE_END ,
  ROOM_TYPE_CRATE
}
 Possible types of rooms. More...
 

Functions

EnvironmentChunk Chunk_GenerateTiles (Vec2 position, RoomType roomType, Vec2 roomSize, RoomFloorPattern floorPattern, RoomHallways hallways)
 Generates tiles for a chunk.
 
void Chunk_GenerateTilesButVoid (EnvironmentChunk *chunk)
 Generates void tiles for a chunk.
 
void Chunk_GenerateFloorTiles (EnvironmentChunk *chunk)
 Generates floor tiles for a chunk.
 
void Chunk_GenerateWallTiles (EnvironmentChunk *chunk)
 Generates wall tiles for a chunk.
 
void Chunk_GenerateHallways (EnvironmentChunk *chunk)
 Generates hallways for a chunk.
 
void Chunk_GenerateHallwayWallTiles (EnvironmentChunk *chunk)
 Generates hallway wall tiles for a chunk.
 
void Chunk_GenerateColliders (EnvironmentChunk *chunk)
 Generates colliders for a chunk.
 
void Chunk_AddWallCollider (Vec2 startTile, Vec2 endtile, EnvironmentChunk *chunk)
 Adds a wall collider to a chunk.
 
void Chunk_AddRoomTrigger (Vec2 startTile, Vec2 endtile, EnvironmentChunk *chunk)
 Adds a room trigger to a chunk.
 
void Chunk_AddHallwayTrigger (Vec2 startTile, Vec2 endtile, EnvironmentChunk *chunk)
 Adds a hallway trigger to a chunk.
 
void Chunk_AddEndTrigger (Vec2 startTile, Vec2 endtile, EnvironmentChunk *chunk)
 Adds an end trigger to a chunk.
 
void Chunk_HandlePlayerInsideRoom ()
 Handles player inside a room.
 
void Chunk_HandlePlayerInsideHallway ()
 Handles player inside a hallway.
 
void Chunk_HandlePlayerInsideEnd ()
 Handles player inside the end.
 
void Chunk_Start ()
 Starts the chunk.
 
void Chunk_Render (const EnvironmentChunk *chunk)
 Renders the chunk.
 
EnvironmentChunk * Chunk_GetCurrentChunk (Vec2 position)
 Gets the current chunk based on position.
 
Vec2 Chunk_GetChunkCenter (EnvironmentChunk *chunk)
 Gets the center of the chunk.
 
Vec2 Chunk_GetRandomTileInRoom (EnvironmentChunk *chunk)
 Gets a random tile in the room.
 
Vec2 Chunk_GetRandomTileCenterInRoom (EnvironmentChunk *chunk)
 Gets a random tile center in the room.
 
bool Chunk_IsValid (Vec2 chunkIndex)
 Checks if a chunk index is valid.
 
bool Chunk_IsOnMainPath (EnvironmentChunk *chunk)
 
Vec2 Chunk_GetRoomTopLeft (EnvironmentChunk *chunk)
 Gets the top-left corner of the current room in the current chunk.
 
Vec2 Chunk_GetRoomBottomRight (EnvironmentChunk *chunk)
 Gets the bottom-right corner of the current room in the current chunk.
 

Detailed Description

Implements environment chunks that form game maps and rooms.

Author
Mango and Darren
Date
2023-03-22

Macro Definition Documentation

◆ CHUNK_SIZE_PIXEL

#define CHUNK_SIZE_PIXEL   (CHUNK_SIZE_TILE * TILE_SIZE_PIXELS)

Size of a chunk in pixels.

◆ CHUNK_SIZE_TILE

#define CHUNK_SIZE_TILE   60

Size of a chunk in tiles.

◆ HALLWAY_END

#define HALLWAY_END   HALLWAY_START + HALLWAY_SIZE_TILE

Ending position of hallway within a chunk.

◆ HALLWAY_SIZE_TILE

#define HALLWAY_SIZE_TILE   6

Width/height of hallway in tiles.

◆ HALLWAY_START

#define HALLWAY_START   (CHUNK_SIZE_TILE - HALLWAY_SIZE_TILE) / 2

Starting position of hallway within a chunk.

◆ ROOM_ENDX

#define ROOM_ENDX (   roomsize)    ROOM_STARTX(roomsize) + (roomsize).x

Ending X position of a room based on its size.

◆ ROOM_ENDY

#define ROOM_ENDY (   roomsize)    ROOM_STARTY(roomsize) + (roomsize).y

Ending Y position of a room based on its size.

◆ ROOM_STARTX

#define ROOM_STARTX (   roomsize)    (CHUNK_SIZE_TILE - (roomsize).x) / 2

Starting X position of a room based on its size.

◆ ROOM_STARTY

#define ROOM_STARTY (   roomsize)    (CHUNK_SIZE_TILE - (roomsize).y) / 2

Starting Y position of a room based on its size.

Enumeration Type Documentation

◆ RoomFloorPattern

Possible floor patterns in a room.

Enumerator
ROOM_FLOOR_PATTERN_1 

Floor pattern 1.

ROOM_FLOOR_PATTERN_RANDOM 

Random floor pattern.

◆ RoomHallways

Possible hallways directions in a room.

Enumerator
HALLWAY_NONE 

No hallway.

HALLWAY_UP 

Hallway up.

HALLWAY_DOWN 

Hallway down.

HALLWAY_LEFT 

Hallway left.

HALLWAY_RIGHT 

Hallway right.

◆ RoomType

enum RoomType

Possible types of rooms.

Enumerator
ROOM_TYPE_START 

Start room.

ROOM_TYPE_NORMAL 

Normal room.

ROOM_TYPE_BOSS 

Boss room.

ROOM_TYPE_END 

End room.

ROOM_TYPE_CRATE 

Crate room.

Function Documentation

◆ Chunk_AddEndTrigger()

void Chunk_AddEndTrigger ( Vec2  startTile,
Vec2  endTile,
EnvironmentChunk *  chunk 
)

Adds an end trigger to a chunk.

Parameters
startTileStarting tile of the end
endtileEnding tile of the end
chunkPointer to the chunk

Adds an end trigger to a chunk.

Creates a trigger zone in the center of the end room that detects when the player has reached the level exit.

Parameters
startTileStarting tile position
endTileEnding tile position
chunkPointer to the chunk

◆ Chunk_AddHallwayTrigger()

void Chunk_AddHallwayTrigger ( Vec2  startTile,
Vec2  endTile,
EnvironmentChunk *  chunk 
)

Adds a hallway trigger to a chunk.

Parameters
startTileStarting tile of the hallway
endtileEnding tile of the hallway
chunkPointer to the chunk

Adds a hallway trigger to a chunk.

Creates a trigger zone that detects when the player is inside a hallway.

Parameters
startTileStarting tile position
endTileEnding tile position
chunkPointer to the chunk

◆ Chunk_AddRoomTrigger()

void Chunk_AddRoomTrigger ( Vec2  startTile,
Vec2  endTile,
EnvironmentChunk *  chunk 
)

Adds a room trigger to a chunk.

Parameters
startTileStarting tile of the room
endtileEnding tile of the room
chunkPointer to the chunk

Adds a room trigger to a chunk.

Creates a trigger zone that detects when the player is inside a room.

Parameters
startTileStarting tile position
endTileEnding tile position
chunkPointer to the chunk

◆ Chunk_AddWallCollider()

void Chunk_AddWallCollider ( Vec2  startTile,
Vec2  endTile,
EnvironmentChunk *  chunk 
)

Adds a wall collider to a chunk.

Parameters
startTileStarting tile of the wall
endtileEnding tile of the wall
chunkPointer to the chunk

Adds a wall collider to a chunk.

Creates a physical collision box for walls at the specified location.

Parameters
startTileStarting tile position of the wall
endTileEnding tile position of the wall
chunkPointer to the chunk

◆ Chunk_GenerateColliders()

void Chunk_GenerateColliders ( EnvironmentChunk *  chunk)

Generates colliders for a chunk.

Parameters
chunkPointer to the chunk

Generates colliders for a chunk.

Creates colliders for walls and hallways, as well as trigger zones for room and hallway detection.

Parameters
chunkPointer to the chunk

◆ Chunk_GenerateFloorTiles()

void Chunk_GenerateFloorTiles ( EnvironmentChunk *  chunk)

Generates floor tiles for a chunk.

Parameters
chunkPointer to the chunk

Generates floor tiles for a chunk.

Creates the base floor tiles for a room based on its size and floor pattern.

Parameters
chunkPointer to the chunk

◆ Chunk_GenerateHallways()

void Chunk_GenerateHallways ( EnvironmentChunk *  chunk)

Generates hallways for a chunk.

Parameters
chunkPointer to the chunk

Generates hallways for a chunk.

Creates floor tiles for hallways based on the room's hallway configuration.

Parameters
chunkPointer to the chunk

◆ Chunk_GenerateHallwayWallTiles()

void Chunk_GenerateHallwayWallTiles ( EnvironmentChunk *  chunk)

Generates hallway wall tiles for a chunk.

Parameters
chunkPointer to the chunk

Generates hallway wall tiles for a chunk.

Creates wall tiles along the sides of hallways with appropriate corner pieces at junctions.

Parameters
chunkPointer to the chunk

◆ Chunk_GenerateTiles()

EnvironmentChunk Chunk_GenerateTiles ( Vec2  position,
RoomType  roomType,
Vec2  roomSize,
RoomFloorPattern  floorPattern,
RoomHallways  hallways 
)

Generates tiles for a chunk.

Parameters
positionPosition of the chunk
roomTypeType of the room
roomSizeSize of the room
floorPatternFloor pattern of the room
hallwaysHallways in the room
Returns
EnvironmentChunk Generated chunk

Generates tiles for a chunk.

Creates a fully-formed environment chunk with all necessary components including floor tiles, walls, hallways, and collision boxes.

Parameters
positionWorld position of the chunk
roomTypeType of room to generate (start, normal, boss, end)
roomSizeSize of the room in tiles
floorPatternPattern to use for floor tiles
hallwaysConfiguration of hallways connected to this room
Returns
EnvironmentChunk The fully generated chunk

◆ Chunk_GenerateTilesButVoid()

void Chunk_GenerateTilesButVoid ( EnvironmentChunk *  chunk)

Generates void tiles for a chunk.

Parameters
chunkPointer to the chunk

Generates void tiles for a chunk.

Clears all existing tiles and colliders from a chunk and regenerates them, useful when hallway configurations change or room state changes.

Parameters
chunkPointer to the chunk to regenerate

◆ Chunk_GenerateWallTiles()

void Chunk_GenerateWallTiles ( EnvironmentChunk *  chunk)

Generates wall tiles for a chunk.

Parameters
chunkPointer to the chunk

Generates wall tiles for a chunk.

Creates wall tiles around the room perimeter using appropriate wall sprites with correct rotations.

Parameters
chunkPointer to the chunk

◆ Chunk_GetChunkCenter()

Vec2 Chunk_GetChunkCenter ( EnvironmentChunk *  chunk)

Gets the center of the chunk.

Parameters
chunkPointer to the chunk
Returns
Vec2 Center of the chunk

◆ Chunk_GetCurrentChunk()

EnvironmentChunk * Chunk_GetCurrentChunk ( Vec2  position)

Gets the current chunk based on position.

Parameters
positionPosition to get the chunk
Returns
EnvironmentChunk* Pointer to the current chunk

Gets the current chunk based on position.

Parameters
positionWorld position to check
Returns
EnvironmentChunk* Pointer to the chunk at that position

◆ Chunk_GetRandomTileCenterInRoom()

Vec2 Chunk_GetRandomTileCenterInRoom ( EnvironmentChunk *  chunk)

Gets a random tile center in the room.

Parameters
chunkPointer to the chunk
Returns
Vec2 Random tile center position

Gets a random tile center in the room.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Random centered tile position in world coordinates

◆ Chunk_GetRandomTileInRoom()

Vec2 Chunk_GetRandomTileInRoom ( EnvironmentChunk *  chunk)

Gets a random tile in the room.

Parameters
chunkPointer to the chunk
Returns
Vec2 Random tile position

Gets a random tile in the room.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Random tile position in world coordinates

◆ Chunk_GetRoomBottomRight()

Vec2 Chunk_GetRoomBottomRight ( EnvironmentChunk *  chunk)

Gets the bottom-right corner of the current room in the current chunk.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Bottom-right corner position in world coordinates

Gets the bottom-right corner of the current room in the current chunk.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Bottom-right corner position in world coordinates

◆ Chunk_GetRoomTopLeft()

Vec2 Chunk_GetRoomTopLeft ( EnvironmentChunk *  chunk)

Gets the top-left corner of the current room in the current chunk.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Top-left corner position in world coordinates

Gets the top-left corner of the current room in the current chunk.

Parameters
chunkPointer to the chunk containing the room
Returns
Vec2 Top-left corner position in world coordinates

◆ Chunk_HandlePlayerInsideEnd()

void Chunk_HandlePlayerInsideEnd ( )

Handles player inside the end.

Handles player inside the end.

Updates player state to indicate they have reached the end of the level, enabling level completion functionality.

◆ Chunk_HandlePlayerInsideHallway()

void Chunk_HandlePlayerInsideHallway ( )

Handles player inside a hallway.

Handles player inside a hallway.

Updates player state to indicate they are inside a hallway, which affects combat and movement.

◆ Chunk_HandlePlayerInsideRoom()

void Chunk_HandlePlayerInsideRoom ( )

Handles player inside a room.

Handles player inside a room.

Updates player state to indicate they are inside a room, which affects combat and other game systems.

◆ Chunk_IsOnMainPath()

bool Chunk_IsOnMainPath ( EnvironmentChunk *  chunk)

◆ Chunk_IsValid()

bool Chunk_IsValid ( Vec2  chunkIndex)

Checks if a chunk index is valid.

Parameters
chunkIndexChunk index to check
Returns
true If the chunk index is valid
false If the chunk index is not valid

Checks if a chunk index is valid.

Parameters
chunkIndexIndex of the chunk to check
Returns
bool True if the chunk is valid, false otherwise

◆ Chunk_Render()

void Chunk_Render ( const EnvironmentChunk *  chunk)

Renders the chunk.

Parameters
chunkPointer to the chunk

◆ Chunk_Start()

void Chunk_Start ( )

Starts the chunk.