movement: generalize; use vectors (#16)

Generalized movement, so that all entities move the same.

Reviewed-on: NotAShelf/rogged#16
Reviewed-by: raf <raf@notashelf.dev>
Co-authored-by: Squirrel Modeller <squirrelmodeller@protonmail.com>
Co-committed-by: Squirrel Modeller <squirrelmodeller@protonmail.com>
This commit is contained in:
Squirrel Modeller 2026-04-09 14:11:46 +00:00 committed by raf
commit 4dfe52ae72
9 changed files with 124 additions and 89 deletions

View file

@ -30,7 +30,8 @@ void render_map(const Map *map) {
}
void render_player(const Player *p) {
Rectangle rect = {(float)(p->x * TILE_SIZE), (float)(p->y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
Rectangle rect = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
(float)TILE_SIZE};
DrawRectangleRec(rect, BLUE);
}
@ -39,8 +40,8 @@ void render_enemies(const Enemy *enemies, int count) {
if (!enemies[i].alive)
continue;
Rectangle rect = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE), (float)TILE_SIZE,
(float)TILE_SIZE};
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
(float)TILE_SIZE, (float)TILE_SIZE};
// Different colors based on enemy type
Color enemy_color;
@ -72,8 +73,8 @@ void render_enemies(const Enemy *enemies, int count) {
bar_color = (Color){200, 180, 40, 255}; // yellow
else
bar_color = (Color){200, 60, 60, 255}; // red
Rectangle hp_bar = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE - 4), (float)hp_pixels,
3};
Rectangle hp_bar = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE - 4),
(float)hp_pixels, 3};
DrawRectangleRec(hp_bar, bar_color);
}
}