something
This commit is contained in:
48
player/player.c
Normal file
48
player/player.c
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
16
player/player.h
Normal file
16
player/player.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by bruno on 4/24/25.
|
||||
//
|
||||
|
||||
#ifndef FACTORYGAME_PLAYER_H
|
||||
#define FACTORYGAME_PLAYER_H
|
||||
|
||||
extern int playerX;
|
||||
extern int playerY;
|
||||
|
||||
bool isInbounds(int x, int y);
|
||||
bool isInboundsRect(SDL_Rect rect);
|
||||
bool isInboundsTile(int x, int y);
|
||||
void adjustRect(SDL_Rect * rect);
|
||||
|
||||
#endif //FACTORYGAME_PLAYER_H
|
Reference in New Issue
Block a user