summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx.42@42l.fr>2023-03-19 04:49:14 +0000
committerkdx <kdx.42@42l.fr>2023-03-19 04:49:14 +0000
commit21f07a88c22388d754e3a47a8f7cf9ed7dd5747a (patch)
tree34e656a3d4f5b0e492b48bc15344a2fd8f47ef18
parent06e5d62f325ec956fd018956a47902a4adc37033 (diff)
downloadhyperultra-21f07a88c22388d754e3a47a8f7cf9ed7dd5747a.tar.gz
slowdown on death
-rw-r--r--src/background.c19
-rw-r--r--src/background.h2
-rw-r--r--src/game.c9
-rw-r--r--src/game.h1
-rw-r--r--src/main.c1
-rw-r--r--src/spike.c4
6 files changed, 29 insertions, 7 deletions
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 <math.h>
-long tick = 0;
+double tick = 0;
static void
draw_square(double size, double angle)
@@ -12,11 +13,19 @@ draw_square(double size, double 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