diff --git a/src/background.c b/src/background.c index fc3b1ba..ad9e9ce 100644 --- a/src/background.c +++ b/src/background.c @@ -1,9 +1,10 @@ #include "lzy.h" #include "cfg.h" #include "rotrect.h" +#include "game.h" #include -long tick = 0; +double tick = 0; static void draw_square(double size, double angle) @@ -11,12 +12,20 @@ draw_square(double size, double angle) rotrect(DISPLAY_WIDTH / 2.0, DISPLAY_HEIGHT / 2.0, size, size, angle); } +void +background_update(Game *g) +{ + if (game_entity_count(g, ET_player) > 0) + tick += 1.0; + else + tick += 0.25; +} + void background_draw(void) { - tick += 1; LZY_DrawSetColor(BLACK); - draw_square(300 * sin((double)tick / 50), (double)tick / 40); - draw_square(300 * sin((double)tick / 40), (double)tick / 30); - draw_square(300 * sin((double)tick / 30), (double)tick / 20); + draw_square(300 * sin(tick / 50), tick / 40); + draw_square(300 * sin(tick / 40), tick / 30); + draw_square(300 * sin(tick / 30), tick / 20); } diff --git a/src/background.h b/src/background.h index def5923..c0c078a 100644 --- a/src/background.h +++ b/src/background.h @@ -1,3 +1,5 @@ #pragma once +#include "game.h" +void background_update(Game *g); void background_draw(void); diff --git a/src/game.c b/src/game.c index 615e06e..665363d 100644 --- a/src/game.c +++ b/src/game.c @@ -88,3 +88,12 @@ game_create_entity(Game *this) this->uuid += 1; return e; } + +int +game_entity_count(Game *this, unsigned int type) +{ + int count = 0; + for (int i = 0; i < MAX_ENTITIES; i++) + count += (this->entities[i].type == type); + return count; +} diff --git a/src/game.h b/src/game.h index 96b264f..ebb5c09 100644 --- a/src/game.h +++ b/src/game.h @@ -16,3 +16,4 @@ void game_update(Game *this); void game_draw(Game *this); void game_restart_scene(Game *this); Entity *game_create_entity(Game *this); +int game_entity_count(Game *this, unsigned int type); diff --git a/src/main.c b/src/main.c index f9ae592..ff69d98 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ int main(void) LZY_CycleEvents(); input_update(); game_update(game); + background_update(game); LZY_DrawBegin(); LZY_DrawSetColor(WHITE); diff --git a/src/spike.c b/src/spike.c index 4173729..3c5a8d3 100644 --- a/src/spike.c +++ b/src/spike.c @@ -1,13 +1,13 @@ #include "entityimpl.h" #include "rotrect.h" -extern long tick; +extern double tick; IMPL_UPDATE() { } IMPL_END IMPL_DRAW() { - const double angle = (float)tick / 16; + 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); } IMPL_END