From 96163690d49f7856c462378b7ea3771d101f0bba Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 21 Mar 2023 21:31:26 +0100 Subject: [PATCH] calculate spike angle once per frame --- src/game.c | 2 ++ src/game.h | 1 + src/spike.c | 5 ++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/game.c b/src/game.c index 877385a..31ac01b 100644 --- a/src/game.c +++ b/src/game.c @@ -23,6 +23,8 @@ game_deinit(Game *this) void game_update(Game *this) { + extern double tick; + this->spike_angle = tick / 16; if (this->queue_restart_scene > 0) { if (--this->queue_restart_scene == 0) game_restart_scene(this); diff --git a/src/game.h b/src/game.h index 001d467..b8dae9f 100644 --- a/src/game.h +++ b/src/game.h @@ -8,6 +8,7 @@ typedef struct Game { bool queue_next_scene; int queue_restart_scene; int player_dir; + double spike_angle; Entity entities[MAX_ENTITIES]; } Game; diff --git a/src/spike.c b/src/spike.c index 3c5a8d3..f09537f 100644 --- a/src/spike.c +++ b/src/spike.c @@ -7,9 +7,8 @@ IMPL_UPDATE() { } IMPL_END IMPL_DRAW() { - const double angle = tick / 16; - rotrect(this->pos[0], this->pos[1], 10, 10, angle); - rotrect(this->pos[0], this->pos[1], 10, 10, -angle); + rotrect(this->pos[0], this->pos[1], 10, 10, g->spike_angle); + rotrect(this->pos[0], this->pos[1], 10, 10, -g->spike_angle); } IMPL_END IMPL_INIT(spike) {