Files
factorygame/tiles/tile.h

179 lines
3.4 KiB
C

//
// Created by bruno on 4/24/25.
//
#ifndef FACTORYGAME_TILE_H
#define FACTORYGAME_TILE_H
#include "../util/util.h"
#include "../items/item.h"
#include "tilecallbacks.h"
#define MAP_WIDTH 200
#define MAP_HEIGHT 200
extern uint16_t DISPLAY_MAP_WIDTH;
extern uint16_t DISPLAY_MAP_HEIGHT;
extern uint16_t DISPLAY_WIDTH;
extern uint16_t DISPLAY_HEIGHT;
#define TILE_SIZE 32
#define MAX_TILES MAP_WIDTH * MAP_HEIGHT
typedef struct {
MiniRect tiles[MAX_TILES];
int activeCount;
} TileArray;
extern TileArray neededUpdates;
void remove_tile(TileArray *arr, int index);
int add_tile(TileArray *arr, MiniRect t);
extern SDL_Texture *tilesTexture;
extern SDL_Texture *itemsTexture;
extern SDL_Texture *backgroundTexture;
extern int scrollFrame;
extern unsigned long beltFrames;
#define ItemSlotCount 4
typedef enum BackgroundType {
BGType_WATER_SHALLOW,
BGType_WATER_DEEP,
BGType_GRASS_FLOWER0,
BGType_GRASS_FLOWER1,
BGType_GRASS_FLOWER2,
BGType_GRASS0,
BGType_GRASS1,
BGType_GRASS2,
BGType_SAND0,
BGType_SAND1,
BGType_SAND2,
BGType_SAND3,
BGType_SAND4,
BGType_SAND5,
BGType_SAND6,
BGType_SAND7,
BGType_TILES0,
BGType_TILES1,
BGType_TILES2,
BGType_TILES3,
BGType_COBBLE0,
BGType_COBBLE1,
BGType_COBBLE2,
BGType_COBBLE3,
BGType_IRON_ORE,
BGType_SILVER_ORE,
BGType_GOLD_ORE,
BGType_PLATINUM_ORE,
BGType_ENEMY_FLOOR,
BGType_END
} BackgroundType;
#define MAX_BASE_NAMES 512
#define MAX_ANIMATION_FRAMES 32
extern MiniRect enemySpawn;
extern MiniRect playerCore;
typedef void (*UpdateTileCallback)(struct Tile *tile);
typedef struct TileTypeReg {
ItemType type;
char name[20];
OrientedAnimation animation;
uint16_t breakTime;
bool itemMoves;
bool allowedInItems[ItemSlotCount][ITEMREGISTRY_SIZE];
bool outputLane[ItemSlotCount];
bool needsTicks;
bool walkable;
bool allDir;
uint16_t maxHealth;
UpdateTileCallback updateTileCallback;
} TileTypeReg;
bool isWalkable(MiniRect tileCoords);
typedef struct BackgroundTileType {
ItemType type;
char name[20];
Animation animation;
bool walkable;
} BackgroundTileType;
#define TILEREGISTRY_SIZE 64
extern BackgroundTileType BackgroundTileRegistry[TILEREGISTRY_SIZE];
extern TileTypeReg TileRegistry[TILEREGISTRY_SIZE];
void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect);
void updateTiles();
typedef struct PathFindDat {
int gCost;
int hCost;
struct PathFindDat* parent;
bool closed;
bool open;
uint32_t version;
} PathFindDat;
typedef struct BackgroundTile {
BackgroundType type;
PathFindDat pathFind;
} BackgroundTile;
typedef struct Tile {
OrientDirection direction;
ItemType type;
int miscVal;
ItemOnBelt items[ItemSlotCount];
uint16_t audioCh;
MiniRect rect;
int neededUpdateIndex;
char fixedFrame;
PathFindDat pathFind;
int16_t health;
} Tile;
extern Tile tileMap[MAP_HEIGHT][MAP_WIDTH];
extern BackgroundTile backgroundMap[MAP_HEIGHT][MAP_WIDTH];
void setupTiles();
void preSetupTiles();
void generateTestMap();
void loadBackgroundTiles(SDL_Renderer *renderer);
void loadTiles(SDL_Renderer *renderer);
extern uint16_t tileTypeIndex;
extern uint16_t backgroundTileTypeIndex;
uint16_t getBreakTime(int type);
void initTiles();
void genInitMap();
void setTileView(uint16_t w, uint16_t h);
extern SDL_Rect viewport;
#endif //FACTORYGAME_TILE_H