Hopefully last commit
This commit is contained in:
53
util/util.c
53
util/util.c
@@ -9,6 +9,8 @@
|
||||
//#include "font.h"
|
||||
|
||||
|
||||
ScreenType screenType = SCREEN_MENU;
|
||||
|
||||
//The window we'll be rendering to
|
||||
SDL_Window *window = NULL;
|
||||
volatile bool running = true;
|
||||
@@ -136,7 +138,8 @@ void renderBar(SDL_Renderer *renderer,
|
||||
char barString[20];
|
||||
sprintf(barString, "%d/%d", currentValue, maxValue);
|
||||
|
||||
renderText(mainRenderer, fonts[1], barString, x + (width / 2 - (fonts[2].size * strlen(barString))), y - fonts[2].size - barRect.h);
|
||||
renderText(mainRenderer, fonts[1], barString, x + (width / 2 - (fonts[2].size * strlen(barString))),
|
||||
y - fonts[2].size - barRect.h);
|
||||
}
|
||||
|
||||
int cmpstringp(const void *p1, const void *p2) {
|
||||
@@ -226,14 +229,14 @@ bool checkCollision(SDL_Rect a, SDL_Rect b) {
|
||||
|
||||
bool canMoveTo(SDL_Rect newRect) {
|
||||
// Round down to get all tiles the rect overlaps
|
||||
int left = newRect.x / TILE_SIZE;
|
||||
int right = (newRect.x + newRect.w - 1) / TILE_SIZE;
|
||||
int top = newRect.y / TILE_SIZE;
|
||||
int left = newRect.x / TILE_SIZE;
|
||||
int right = (newRect.x + newRect.w - 1) / TILE_SIZE;
|
||||
int top = newRect.y / TILE_SIZE;
|
||||
int bottom = (newRect.y + newRect.h - 1) / TILE_SIZE;
|
||||
|
||||
for (int tx = left; tx <= right; ++tx) {
|
||||
for (int ty = top; ty <= bottom; ++ty) {
|
||||
MiniRect tile = { tx, ty };
|
||||
MiniRect tile = {tx, ty};
|
||||
if (!isWalkable(tile)) {
|
||||
return false;
|
||||
}
|
||||
@@ -265,7 +268,7 @@ bool canMoveWithRadius(SDL_Rect centerRect) {
|
||||
int tileTop = y * TILE_SIZE;
|
||||
int tileBottom = tileTop + TILE_SIZE;
|
||||
|
||||
// Bounding box of the player
|
||||
// Bounding box of the mainPlayer
|
||||
int playerLeft = centerRect.x - radius;
|
||||
int playerRight = centerRect.x + radius;
|
||||
int playerTop = centerRect.y - radius;
|
||||
@@ -287,4 +290,40 @@ int compareStrings(const void *a, const void *b) {
|
||||
const char *strA = *(const char **) a;
|
||||
const char *strB = *(const char **) b;
|
||||
return strcmp(strA, strB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double angle_between_points_deg(double x1, double y1, double x2, double y2) {
|
||||
double dx = x2 - x1;
|
||||
double dy = y2 - y1;
|
||||
double angle_rad = atan2(dy, dx);
|
||||
double angle_deg = angle_rad * (180.0 / M_PI);
|
||||
|
||||
// Normalize to 0–360 degrees (optional, depending on use case)
|
||||
if (angle_deg < 0) {
|
||||
angle_deg += 360.0;
|
||||
}
|
||||
|
||||
return angle_deg;
|
||||
}
|
||||
|
||||
#define TICKS_PER_SECOND 60
|
||||
|
||||
void initWaveInfo(WaveInfo *info) {
|
||||
info->waveCounter = 0;
|
||||
info->waveTimer = 200 * TICKS_PER_SECOND; // 200 seconds before first wave
|
||||
info->waveRunning = false;
|
||||
info->totalWaves = MAX_WAVES;
|
||||
|
||||
for (int i = 0; i < MAX_WAVES; i++) {
|
||||
int flyerCount = 1 + i * 2; // Each wave increases flyer count
|
||||
|
||||
info->waves[i].enemyCount = 1;
|
||||
info->waves[i].enemies[0] = (EnemyEntry) {ENEMY_TYPE_FLYER, flyerCount};
|
||||
|
||||
// Reduce time between waves gradually (but not below 5 seconds)
|
||||
int secondsBetween = 15 - (i / 5);
|
||||
if (secondsBetween < 5) secondsBetween = 5;
|
||||
info->waves[i].timeUntilNext = secondsBetween * TICKS_PER_SECOND;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user