slowdown on death

This commit is contained in:
kdx 2023-03-19 04:49:14 +00:00
parent 06e5d62f32
commit 21f07a88c2
6 changed files with 29 additions and 7 deletions

View File

@ -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)
@ -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);
}

View File

@ -1,3 +1,5 @@
#pragma once
#include "game.h"
void background_update(Game *g);
void background_draw(void);

View File

@ -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;
}

View File

@ -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);

View File

@ -27,6 +27,7 @@ int main(void)
LZY_CycleEvents();
input_update();
game_update(game);
background_update(game);
LZY_DrawBegin();
LZY_DrawSetColor(WHITE);

View File

@ -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