134 lines
3.2 KiB
C
134 lines
3.2 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_Rect atlasRects[TILE_SIZE];
|
|
unsigned char frameCount;
|
|
unsigned char divisor;
|
|
} Animation;
|
|
|
|
|
|
typedef struct MiniRect {
|
|
int x;
|
|
int y;
|
|
} MiniRect;
|
|
|
|
#define MAX_ENEMIES_PER_WAVE 16
|
|
#define MAX_WAVES 128
|
|
|
|
// Define enemy types (expand as needed)
|
|
typedef enum EnemyType {
|
|
ENEMY_TYPE_NONE = 0,
|
|
ENEMY_TYPE_FLYER,
|
|
// Add more enemy types here
|
|
} EnemyType;
|
|
|
|
typedef struct EnemyEntry {
|
|
EnemyType type;
|
|
int count;
|
|
} EnemyEntry;
|
|
|
|
|
|
typedef struct Wave {
|
|
EnemyEntry enemies[MAX_ENEMIES_PER_WAVE];
|
|
int enemyCount; // Number of different enemy types in this wave
|
|
int timeUntilNext; // Time until the next wave (in ticks, ms, etc.)
|
|
} Wave;
|
|
|
|
typedef struct WaveInfo {
|
|
int waveCounter; // Current wave number (index)
|
|
int waveTimer; // Countdown until next wave starts
|
|
bool waveRunning; // Whether a wave is currently running
|
|
Wave waves[MAX_WAVES]; // List of all waves
|
|
int totalWaves; // Total number of defined waves
|
|
} WaveInfo;
|
|
|
|
typedef enum ScreenType {
|
|
SCREEN_MENU,
|
|
SCREEN_CREDITS,
|
|
SCREEN_GAME,
|
|
SCREEN_FONTS,
|
|
SCREEN_ATLAS,
|
|
} ScreenType;
|
|
|
|
extern ScreenType screenType;
|
|
|
|
extern WaveInfo waveInfo;
|
|
|
|
void initWaveInfo(WaveInfo *info);
|
|
|
|
|
|
typedef struct OrientedAnimation {
|
|
SDL_Rect atlasRects[ORIENT_DIRECTION_COUNT][TILE_SIZE * 2];
|
|
unsigned char frameCount;
|
|
unsigned char divisor;
|
|
char startFrame;
|
|
} 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);
|
|
|
|
double angle_between_points_deg(double x1, double y1, double x2, double y2);
|
|
|
|
#endif //FACTORYGAME_UTIL_H
|