Move world files to engine
This commit is contained in:
@@ -23,6 +23,10 @@ set(BreezeSources
|
||||
breeze/core/module_system.c
|
||||
|
||||
breeze/utils/tokenizer.c
|
||||
|
||||
breeze/world/layer.c
|
||||
breeze/world/map.c
|
||||
breeze/world/tileset.c
|
||||
)
|
||||
|
||||
set(BreezeHeaders
|
||||
@@ -33,6 +37,10 @@ set(BreezeHeaders
|
||||
|
||||
breeze/utils/tokenizer.h
|
||||
|
||||
breeze/world/layer.h
|
||||
breeze/world/map.h
|
||||
breeze/world/tileset.h
|
||||
|
||||
breeze/defines.h
|
||||
breeze/game.h
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
#include "breeze/utils/tokenizer.h"
|
||||
|
||||
#include "breeze/world/layer.h"
|
||||
#include "breeze/world/map.h"
|
||||
#include "breeze/world/tileset.h"
|
||||
|
||||
#include "breeze/defines.h"
|
||||
#include "breeze/game.h"
|
||||
|
||||
|
||||
1
engine/breeze/world/layer.c
Normal file
1
engine/breeze/world/layer.c
Normal file
@@ -0,0 +1 @@
|
||||
#include "layer.h"
|
||||
4
engine/breeze/world/layer.h
Normal file
4
engine/breeze/world/layer.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef BREEZE_LAYER_H
|
||||
#define BREEZE_LAYER_H
|
||||
|
||||
#endif //BREEZE_LAYER_H
|
||||
1
engine/breeze/world/map.c
Normal file
1
engine/breeze/world/map.c
Normal file
@@ -0,0 +1 @@
|
||||
#include "map.h"
|
||||
4
engine/breeze/world/map.h
Normal file
4
engine/breeze/world/map.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef BREEZE_MAP_H
|
||||
#define BREEZE_MAP_H
|
||||
|
||||
#endif //BREEZE_MAP_H
|
||||
49
engine/breeze/world/tileset.c
Normal file
49
engine/breeze/world/tileset.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cute_tiled.h>
|
||||
|
||||
#include "tileset.h"
|
||||
|
||||
BzTileset BZ_TILESET_INVALID = {.isValid = false};
|
||||
|
||||
BzTileset bzTilesetCreate(const BzTilesetDesc *desc) {
|
||||
BzTileset tileset = {};
|
||||
cute_tiled_tileset_t *source = cute_tiled_load_external_tileset(desc->path, NULL);
|
||||
|
||||
tileset.tiles = LoadTexture(desc->texturePath);
|
||||
tileset.startID = source->firstgid;
|
||||
tileset.tileWidth = source->tilewidth;
|
||||
tileset.tileHeight = source->tileheight;
|
||||
|
||||
tileset.offsetX = source->tileoffset_x;
|
||||
tileset.offsetY = source->tileoffset_y;
|
||||
|
||||
tileset.width = tileset.tiles.width / tileset.tileWidth;
|
||||
tileset.height = tileset.tiles.height / tileset.tileHeight;
|
||||
|
||||
cute_tiled_free_external_tileset(source);
|
||||
|
||||
if (tileset.tiles.width != source->imagewidth ||
|
||||
tileset.tiles.height != source->imageheight) {
|
||||
bzTilesetDestroy(&tileset);
|
||||
return BZ_TILESET_INVALID;
|
||||
}
|
||||
|
||||
tileset.isValid = true;
|
||||
return tileset;
|
||||
}
|
||||
|
||||
Rectangle bzTilesetGetTileRegion(BzTileset *tileset, int tileID) {
|
||||
tileID = tileID - tileset->startID;
|
||||
int posX = tileID % tileset->width;
|
||||
int posY = tileID / tileset->width;
|
||||
return (Rectangle) {posX * tileset->tileWidth, posY * tileset->tileHeight,
|
||||
tileset->tileWidth, tileset->tileHeight};
|
||||
}
|
||||
|
||||
void bzTilesetDestroy(BzTileset *tileset) {
|
||||
UnloadTexture(tileset->tiles);
|
||||
*tileset = BZ_TILESET_INVALID;
|
||||
}
|
||||
|
||||
33
engine/breeze/world/tileset.h
Normal file
33
engine/breeze/world/tileset.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef BREEZE_TILESET_H
|
||||
#define BREEZE_TILESET_H
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
typedef struct BzTilesetDesc {
|
||||
const char *path;
|
||||
const char *texturePath;
|
||||
} BzTilesetDesc;
|
||||
|
||||
typedef struct BzTileset {
|
||||
Texture2D tiles;
|
||||
int startID;
|
||||
int tileWidth;
|
||||
int tileHeight;
|
||||
int width;
|
||||
int height;
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
bool isValid;
|
||||
} BzTileset;
|
||||
|
||||
extern BzTileset BZ_TILESET_INVALID;
|
||||
|
||||
BzTileset bzTilesetCreate(const BzTilesetDesc *desc);
|
||||
|
||||
Rectangle bzTilesetGetTileRegion(BzTileset *tileset, int tileID);
|
||||
|
||||
void bzTilesetDestroy(BzTileset *tileset);
|
||||
|
||||
|
||||
|
||||
#endif //BREEZE_TILESET_H
|
||||
Reference in New Issue
Block a user