Separate engine and game
This commit is contained in:
1
game/world/layer.c
Normal file
1
game/world/layer.c
Normal file
@@ -0,0 +1 @@
|
||||
#include "layer.h"
|
||||
4
game/world/layer.h
Normal file
4
game/world/layer.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef PIXELDEFENSE_LAYER_H
|
||||
#define PIXELDEFENSE_LAYER_H
|
||||
|
||||
#endif //PIXELDEFENSE_LAYER_H
|
||||
1
game/world/map.c
Normal file
1
game/world/map.c
Normal file
@@ -0,0 +1 @@
|
||||
#include "map.h"
|
||||
4
game/world/map.h
Normal file
4
game/world/map.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef PIXELDEFENSE_MAP_H
|
||||
#define PIXELDEFENSE_MAP_H
|
||||
|
||||
#endif //PIXELDEFENSE_MAP_H
|
||||
52
game/world/tileset.c
Normal file
52
game/world/tileset.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "tileset.h"
|
||||
|
||||
Tileset TILESET_INVALID = {.isValid = false};
|
||||
|
||||
Tileset tilesetCreate(const TilesetDesc *desc) {
|
||||
Tileset tileset = {};
|
||||
cute_tiled_tileset_t *source = desc->source;
|
||||
|
||||
char pathBuffer[256];
|
||||
// auto terminates
|
||||
snprintf(pathBuffer, sizeof(pathBuffer), "%s%s%s",
|
||||
desc->assetDir ? desc->assetDir : "",
|
||||
desc->assetDir ? "/" : "",
|
||||
source->image.ptr);
|
||||
|
||||
tileset.tiles = LoadTexture(pathBuffer);
|
||||
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;
|
||||
|
||||
if (tileset.tiles.width != source->imagewidth ||
|
||||
tileset.tiles.height != source->imageheight) {
|
||||
tilesetDestroy(&tileset);
|
||||
return TILESET_INVALID;
|
||||
}
|
||||
|
||||
tileset.isValid = true;
|
||||
return tileset;
|
||||
}
|
||||
|
||||
Rectangle tilesetGetTileRegion(Tileset *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 tilesetDestroy(Tileset *tileset) {
|
||||
UnloadTexture(tileset->tiles);
|
||||
*tileset = TILESET_INVALID;
|
||||
}
|
||||
|
||||
36
game/world/tileset.h
Normal file
36
game/world/tileset.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef PIXELDEFENSE_TILESET_H
|
||||
#define PIXELDEFENSE_TILESET_H
|
||||
|
||||
#include <raylib.h>
|
||||
#include <cute_tiled.h>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
typedef struct TilesetDesc {
|
||||
cute_tiled_tileset_t *source;
|
||||
const char *assetDir;
|
||||
} TilesetDesc;
|
||||
|
||||
typedef struct Tileset {
|
||||
Texture2D tiles;
|
||||
int startID;
|
||||
int tileWidth;
|
||||
int tileHeight;
|
||||
int width;
|
||||
int height;
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
bool isValid;
|
||||
} Tileset;
|
||||
|
||||
extern Tileset TILESET_INVALID;
|
||||
|
||||
Tileset tilesetCreate(const TilesetDesc *desc);
|
||||
|
||||
Rectangle tilesetGetTileRegion(Tileset *tileset, int tileID);
|
||||
|
||||
void tilesetDestroy(Tileset *tileset);
|
||||
|
||||
|
||||
|
||||
#endif //PIXELDEFENSE_TILESET_H
|
||||
Reference in New Issue
Block a user