Files
factorygame/player/player.c
2025-04-24 20:04:41 +02:00

48 lines
1.1 KiB
C

//
// Created by bruno on 4/24/25.
//
#include <SDL2/SDL_rect.h>
#include "player.h"
#include "../tiles/tile.h"
int playerX = (MAP_WIDTH / 2) * 16;
int playerY = (MAP_HEIGHT / 2) * 16;
void adjustRect(SDL_Rect * rect) {
rect->x -= playerX;
rect->y -= playerY;
rect->x += DISPLAY_WIDTH / 2;
rect->y += DISPLAY_HEIGHT / 2;
}
bool isInboundsTile(int x, int y) {
return (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2) < x && (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2) < y &&
(playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2) > x && (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2) > y;
}
bool isInbounds(int x, int y) {
return x > 0 && y > 0 && x < DISPLAY_WIDTH && y < DISPLAY_HEIGHT;
}
bool isInboundsRect(SDL_Rect rect) {
if (isInbounds(rect.x, rect.y)) {
return true;
}
if (rect.x < 0) {
rect.x += rect.w;
}
if (rect.y < 0) {
rect.y += rect.h;
}
if (isInbounds(rect.x, rect.y)) {
return true;
}
if (rect.x > DISPLAY_WIDTH) {
rect.x -= rect.w;
}
if (rect.y > DISPLAY_HEIGHT) {
rect.y -= rect.h;
}
return isInbounds(rect.x, rect.y);
}