Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
tiles.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <vec2.h>
12#include <SDL.h>
13#include <camera.h>
14
19#define TILE_SIZE_PIXELS 20
20
28#define MAX(a, b) ((a) > (b) ? (a) : (b))
29
37#define MIN(a, b) ((a) < (b) ? (a) : (b))
38
64
75
80typedef struct {
81 SDL_Texture* texture;
84
89typedef struct {
90 SDL_Texture* textures[TILE_TYPE_COUNT];
92
97typedef struct {
98 char* texturePaths[TILE_TYPE_COUNT];
100
109
112
116void Tile_Start();
117
125
131
137void Tile_Render(EnvironmentTile tile, Vec2 tilePosition);
138
139/* Utilities */
140
147void Tile_FromPixelPoint(Vec2 pixelPoint, Vec2* chunkIndex, Vec2* tileIndex);
148
154bool Tile_IsValid(Vec2 tileIndex);
155
162
168SDL_Rect Tile_GetRectFromPixel(Vec2 pixelPoint);
169
175Vec2 Tile_GetRandomPixelInRect(SDL_Rect rect);
176
183Vec2 Tile_TileIndexToPixel(Vec2 tileIndex, Vec2 chunkIndex);
184
Provides camera functionality for world-to-screen coordinate conversion.
Configuration for tile resources.
Definition tiles.h:97
Global tile data container.
Definition tiles.h:105
EnvironmentTileResources resources
Loaded tile resources.
Definition tiles.h:106
EnvironmentTileConfig config
Tile configuration.
Definition tiles.h:107
Contains loaded textures for all tile types.
Definition tiles.h:89
Represents a single environment tile.
Definition tiles.h:80
SDL_Texture * texture
Texture for this tile.
Definition tiles.h:81
TileRotation rotation
Rotation applied to this tile.
Definition tiles.h:82
A 2D vector structure.
Definition vec2.h:81
bool Tile_IsValid(Vec2 tileIndex)
Check if a tile index is valid.
Definition tile_utils.c:45
void Tile_FromPixelPoint(Vec2 pixelPoint, Vec2 *chunkIndex, Vec2 *tileIndex)
Convert a pixel coordinate to tile and chunk indices.
Definition tile_utils.c:25
Vec2 Tile_GetPositionFromPixel(Vec2 pixelPoint)
Convert a pixel coordinate to a tile position.
Definition tile_utils.c:55
EnvironmentTile Tile_Create(TileType type, TileRotation rotation)
Create a new environment tile.
Definition tile_start.c:45
Vec2 Tile_TileIndexToPixel(Vec2 tileIndex, Vec2 chunkIndex)
Convert tile and chunk indices to a pixel coordinate.
Definition tile_utils.c:97
void Tile_Render(EnvironmentTile tile, Vec2 tilePosition)
Render a tile at the specified position.
Definition tile_render.c:16
TileRotation
Defines rotation options for tiles.
Definition tiles.h:69
@ TILE_ROTATE_COUNTERCLOCKWISE
90 degrees counterclockwise rotation
Definition tiles.h:72
@ TILE_ROTATE_180
180 degrees rotation
Definition tiles.h:73
@ TILE_ROTATE_CLOCKWISE
90 degrees clockwise rotation
Definition tiles.h:71
@ TILE_ROTATE_NONE
No rotation.
Definition tiles.h:70
Vec2 Tile_GetRandomPixelInRect(SDL_Rect rect)
Get a random pixel coordinate within a rectangle.
Definition tile_utils.c:83
TileType
Defines various types of environment tiles.
Definition tiles.h:43
@ TILE_FLOOR_1
Standard floor type 1.
Definition tiles.h:45
@ TILE_FLOOR_SCRATCHED_2
Scratched floor, variation 2.
Definition tiles.h:52
@ TILE_FLOOR_3
Standard floor type 3.
Definition tiles.h:47
@ TILE_WALL_CORNER_BORDER
Corner wall border.
Definition tiles.h:59
@ TILE_WALL_BOTTOM
Wall bottom section.
Definition tiles.h:57
@ TILE_VOID
Empty/void tile.
Definition tiles.h:44
@ TILE_FLOOR_VENT_3
Floor with vent, variation 3.
Definition tiles.h:50
@ TILE_FLOOR_VENT_1
Floor with vent, variation 1.
Definition tiles.h:48
@ TILE_WALL_SIDE_BORDER
Side wall border.
Definition tiles.h:60
@ TILE_FLOOR_SCRATCHED_3
Scratched floor, variation 3.
Definition tiles.h:53
@ TILE_FLOOR_VENT_2
Floor with vent, variation 2.
Definition tiles.h:49
@ TILE_TYPE_COUNT
Total count of tile types.
Definition tiles.h:62
@ TILE_WALL_TOP
Wall top section.
Definition tiles.h:56
@ TILE_FLOOR_2
Standard floor type 2.
Definition tiles.h:46
@ TILE_FLOOR_SCRATCHED_1
Scratched floor, variation 1.
Definition tiles.h:51
@ TILE_WALL_CORNER_BORDER_SMALL
Small corner wall border.
Definition tiles.h:58
SDL_Rect Tile_GetRectFromPixel(Vec2 pixelPoint)
Get the rectangle of a tile from a pixel coordinate.
Definition tile_utils.c:68
void Tile_Start()
Initialize tile system.
Definition tile_start.c:22
EnvironmentTileData tiles
Global tile data instance.
Definition tile_data.c:14
void Tile_Destroy(EnvironmentTile *tile)
Destroy a tile and free resources.
Provides 2D vector functionality for positions, directions, and transformations.