diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-17 11:33:08 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-17 11:33:08 +0100 |
commit | 46aa297e363bcc1aff30bd4c6870b8f0b1a54b39 (patch) | |
tree | 5780a29f955fed5220341733f20238c9d9945fe3 | |
parent | 19983764a79acfa3f74a730a90e21cdb9813309c (diff) | |
download | hyperultra-46aa297e363bcc1aff30bd4c6870b8f0b1a54b39.tar.gz |
cool bug
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | build.sh | 3 | ||||
-rw-r--r-- | src/background.c | 50 | ||||
-rw-r--r-- | src/background.h | 3 | ||||
-rw-r--r-- | src/main.c | 2 |
5 files changed, 59 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 28424ad..19bb98b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ include(Fxconv) find_package(Gint 2.9 REQUIRED) set(SOURCES + src/background.c + src/entity.c src/game.c src/lzy.c src/main.c @@ -1,2 +1,3 @@ #!/bin/sh -gcc -std=c99 -Wall -Wextra -o hyperultra src/*.c -lSDL2 -lSDL2_image -lSDL2_mixer +gcc -std=c99 -Wall -Wextra -o hyperultra src/*.c \ + -lm -lSDL2 -lSDL2_image -lSDL2_mixer diff --git a/src/background.c b/src/background.c new file mode 100644 index 0000000..2b32c49 --- /dev/null +++ b/src/background.c @@ -0,0 +1,50 @@ +#include "lzy.h" +#include "cfg.h" +#include <math.h> + +static long tick = 0; +static const int center_x = DISPLAY_WIDTH / 2; +static const int center_y = DISPLAY_HEIGHT / 2; + +static void +rotate(double *x, double *y, double angle) +{ + const int ox = *x; + *x = *x * cos(angle) + *y * sin(angle); + *y = *y * cos(angle) + ox * sin(angle); +} + +static void +draw_square(int size, double angle) +{ + double x0 = size / 2.0; + double y0 = size / 2.0; + double x1 = size / 2.0; + double y1 = -size / 2.0; + rotate(&x0, &y0, angle); + rotate(&x1, &y1, angle); + double x2 = 0 - x0; + double y2 = 0 - y0; + double x3 = 0 - x0; + double y3 = 0 - y0; + x0 += center_x; + y0 += center_y; + x1 += center_x; + y1 += center_y; + x2 += center_x; + y2 += center_y; + x3 += center_x; + y3 += center_y; + LZY_DrawLine(x0, y0, x1, y1); + LZY_DrawLine(x1, y1, x2, y2); + LZY_DrawLine(x2, y2, x3, y3); + LZY_DrawLine(x3, y3, x0, y0); +} + +void +background_draw(void) +{ + tick += 1; + LZY_DrawSetColor(0, 0, 0); + draw_square(tick % 128, (double)tick / 10); +} diff --git a/src/background.h b/src/background.h new file mode 100644 index 0000000..def5923 --- /dev/null +++ b/src/background.h @@ -0,0 +1,3 @@ +#pragma once + +void background_draw(void); @@ -1,6 +1,7 @@ #include "lzy.h" #include "game.h" #include "player.h" +#include "background.h" #include <stdio.h> #include <stdlib.h> @@ -28,6 +29,7 @@ int main(void) LZY_DrawBegin(); LZY_DrawSetColor(255, 255, 255); LZY_DrawClear(); + background_draw(); game_draw(game); LZY_DrawEnd(); } |