something
This commit is contained in:
67
tiles/tile.c
Normal file
67
tiles/tile.c
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Created by bruno on 4/24/25.
|
||||
//
|
||||
|
||||
#include <dirent.h>
|
||||
#include "tile.h"
|
||||
#include "../player/player.h"
|
||||
#include "../util/util.h"
|
||||
|
||||
Tile tileMap[MAP_HEIGHT][MAP_WIDTH];
|
||||
|
||||
uint16_t tileTypeIndex = 0;
|
||||
|
||||
TileType TileRegistry[TILEREGISTRY_SIZE];
|
||||
|
||||
void generateTestMap() {
|
||||
for (int y = 0; y < DISPLAY_MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < DISPLAY_MAP_WIDTH; x++) {
|
||||
Tile tile = {0};
|
||||
tile.x = x;
|
||||
tile.y = y;
|
||||
tileMap[y][x] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2);
|
||||
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2); x += 1) {
|
||||
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2);
|
||||
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2); y += 1) {
|
||||
|
||||
tileMap[y][x].type = TYPE_BELT;
|
||||
tileMap[y][x].frameOffset = 0;
|
||||
//tileMap[y][x].direction = ((x + y) % 4 * 2) + 1;
|
||||
tileMap[y][x].direction = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void registerTile(char name[20], SDL_Renderer *renderer) {
|
||||
const char *dot = strchr(name, '.');
|
||||
memcpy(TileRegistry[tileTypeIndex].name, name, dot - name);
|
||||
char texturePath[80];
|
||||
snprintf(texturePath, 80, "./assets/tiles/%s", name);
|
||||
SDL_Texture * texture = IMG_LoadTexture(renderer, texturePath);
|
||||
TileRegistry[tileTypeIndex].textures[ORIENT_LEFT] = texture;
|
||||
TileRegistry[tileTypeIndex].textures[ORIENT_RIGHT] = createFlippedTexture(renderer, texture, SDL_FLIP_HORIZONTAL);
|
||||
TileRegistry[tileTypeIndex].textures[ORIENT_UP] = createRotatedTexture(renderer, texture, 90);
|
||||
TileRegistry[tileTypeIndex].textures[ORIENT_DOWN] = createRotatedTexture(renderer, texture, 270);
|
||||
TileRegistry[tileTypeIndex].type = tileTypeIndex;
|
||||
|
||||
tileTypeIndex++;
|
||||
}
|
||||
|
||||
|
||||
void loadTiles(SDL_Renderer *renderer) {
|
||||
DIR *dir = opendir("./assets/tiles");
|
||||
if (dir) {
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (entry->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
registerTile(entry->d_name, renderer);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user