Files
factorygame/util/util.h
2025-06-08 17:22:30 +02:00

83 lines
2.1 KiB
C

//
// Created by bruno on 4/24/25.
//
#ifndef FACTORYGAME_UTIL_H
#define FACTORYGAME_UTIL_H
#include <SDL2/SDL.h>
#include "atlas.h"
extern int animationStep;
//The window we'll be rendering to
extern SDL_Window *window;
extern volatile bool running;
//The surface contained by the window
extern SDL_Renderer *mainRenderer;
extern SDL_Rect screenRect;
typedef enum OrientDirection {
ORIENT_LEFT_DOWN,
ORIENT_LEFT,
ORIENT_LEFT_UP,
ORIENT_UP,
ORIENT_RIGHT_UP,
ORIENT_RIGHT,
ORIENT_RIGHT_DOWN,
ORIENT_DOWN,
ORIENT_DIRECTION_COUNT
} OrientDirection;
extern const char OrientStrings[ORIENT_DIRECTION_COUNT][10];
extern bool debugMode;
extern bool itemViewing;
extern bool renderAtlas;
typedef struct Animation {
SDL_Texture *textures[TILE_SIZE];
SDL_Rect atlasRects[TILE_SIZE];
unsigned char frameCount;
unsigned char divisor;
} Animation;
typedef struct OrientedAnimation {
SDL_Texture *textures[ORIENT_DIRECTION_COUNT][TILE_SIZE * 2];
SDL_Rect atlasRects[ORIENT_DIRECTION_COUNT][TILE_SIZE * 2];
unsigned char frameCount;
unsigned char divisor;
} OrientedAnimation;
SDL_Texture *createRotatedTexture(SDL_Renderer *renderer, SDL_Texture *src, double angle);
SDL_Texture *createFlippedTexture(SDL_Renderer *renderer, SDL_Texture *src, SDL_RendererFlip flip);
SDL_Texture *ScaleTexture(SDL_Renderer *renderer, SDL_Texture *src, int newWidth, int newHeight);
void DrawThickRect(SDL_Renderer *renderer, SDL_Rect rect, int thickness);
// Define a function pointer type for your callback
typedef void (*DirEntryCallback)(const char *filename, SDL_Renderer *renderer);
// Helper function to iterate over sorted entries in a directory
void iterateSortedDir(const char *path, DirEntryCallback callback, SDL_Renderer *renderer);
void renderBar(SDL_Renderer *renderer,
int x, int y, int width, int height,
int maxValue, int currentValue,
SDL_Color barColor, int margin);
bool checkCollision(SDL_Rect a, SDL_Rect b);
int compareStrings(const void *a, const void *b);
bool canMoveTo(SDL_Rect newRect);
bool canMoveWithRadius(SDL_Rect centerRect);
#endif //FACTORYGAME_UTIL_H