summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-18 23:40:10 +0100
committerkdx <kikoodx@paranoici.org>2023-03-18 23:41:16 +0100
commitb796e0bea418cc541257e17274b6fb14d4cb5ee8 (patch)
treed87ce38493e6af3e5c75a3171981310a20b46920
parent297ee77f926197504f8e0d7d6fcf0bf602cccd66 (diff)
downloadhyperultra-b796e0bea418cc541257e17274b6fb14d4cb5ee8.tar.gz
death particles
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/deathpart.c29
-rw-r--r--src/deathpart.h2
-rw-r--r--src/entity.c9
-rw-r--r--src/entity.h5
-rw-r--r--src/entityimpl.h8
-rw-r--r--src/exit.c12
-rw-r--r--src/exit.h2
-rw-r--r--src/game.c6
-rw-r--r--src/game.h4
-rw-r--r--src/player.c33
-rw-r--r--src/player.h5
12 files changed, 78 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 807d626..1cc5221 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,7 @@ find_package(Gint 2.9 REQUIRED)
set(SOURCES
src/background.c
+ src/deathpart.c
src/entity.c
src/exit.c
src/input.c
diff --git a/src/deathpart.c b/src/deathpart.c
index e7a9dab..e08f25b 100644
--- a/src/deathpart.c
+++ b/src/deathpart.c
@@ -1,14 +1,25 @@
+#include "entity.h"
+#include "player.h"
#include "entityimpl.h"
+#include <stdlib.h>
-IMPL_UPDATE()
-}
+IMPL_UPDATE() {
+ this->vel[1] *= AIR_RESISTANCE;
+ this->vel[1] += GRAVITY;
+ entity_move(this, g);
+} IMPL_END
-IMPL_DRAW()
+IMPL_DRAW() {
LZY_DrawSetColor(BLACK);
- LZY_DrawRect(this->pos[0] - this->width / 2,
- this->pos[1] - this->height / 2,
- this->width, this->height);
-}
+ LZY_DrawRect(this->pos[0], this->pos[1], this->width, this->height);
+} IMPL_END
-IMPL_INIT(deathpart)
-}
+IMPL_INIT(deathpart) {
+ this->ignore_solids = true;
+ this->vel[0] = (float)(rand() % 1024) / 1024;
+ this->vel[1] = -(float)(rand() % 1024) / 512;
+ this->vel[0] *= this->vel[0];
+ if (rand() % 2)
+ this->vel[0] *= -1;
+ this->height = this->width = 1 + rand() % 2;
+} IMPL_END
diff --git a/src/deathpart.h b/src/deathpart.h
index fa6c432..dab4dcb 100644
--- a/src/deathpart.h
+++ b/src/deathpart.h
@@ -7,4 +7,4 @@ typedef struct {
struct Entity;
struct Game;
-void deathpart_init(struct Entity *this, int x, int y);
+struct Entity *deathpart_init(struct Entity *this, int x, int y);
diff --git a/src/entity.c b/src/entity.c
index ef295a7..53ee9d3 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -48,6 +48,15 @@ void
entity_move(Entity *this, Game *g)
{
this->bonk_ceiling = false;
+ if (this->ignore_solids) {
+ for (int a = 0; a < 2; a++) {
+ const double sum = this->vel[a] + this->rem[a];
+ int spd = (int)sum;
+ this->rem[a] = sum - spd;
+ this->pos[a] += spd;
+ }
+ return;
+ }
if (entity_collide(this, g, 0, 0)) {
this->vel[0] = 0.0;
this->vel[1] = 0.0;
diff --git a/src/entity.h b/src/entity.h
index e7def38..f1b0e86 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -16,8 +16,8 @@ enum {
typedef struct Entity Entity;
struct Entity {
unsigned long uuid;
- void (*update)(Entity *this, struct Game *g);
- void (*draw)(Entity *this, struct Game *g);
+ Entity *(*update)(Entity *this, struct Game *g);
+ Entity *(*draw)(Entity *this, struct Game *g);
unsigned int type;
int id;
int pos[2];
@@ -25,6 +25,7 @@ struct Entity {
double rem[2];
int width;
int height;
+ bool ignore_solids;
bool bonk_ceiling;
union {
Player player;
diff --git a/src/entityimpl.h b/src/entityimpl.h
index 2a866a0..63aa91f 100644
--- a/src/entityimpl.h
+++ b/src/entityimpl.h
@@ -4,9 +4,9 @@
#include "lzy.h"
#include <string.h>
-#define IMPL_UPDATE() static void update(Entity*this,Game*g){(void)this,(void)g;
-#define IMPL_DRAW() static void draw(Entity*this,Game*g){(void)this,(void)g;
-#define IMPL_INIT(X) void X##_init(Entity *this, int x, int y) { do { \
+#define IMPL_UPDATE() static Entity*update(Entity*this,Game*g){(void)this,(void)g;
+#define IMPL_DRAW() static Entity*draw(Entity*this,Game*g){(void)this,(void)g;
+#define IMPL_INIT(X) Entity *X##_init(Entity *this, int x, int y) { do { \
memset(this, 0, sizeof(*this)); \
this->update = update; \
this->draw = draw; \
@@ -14,3 +14,5 @@
this->pos[1] = y; \
this->type = ET_##X; \
} while(0);
+#define IMPL_INIT_END
+#define IMPL_END return this; }
diff --git a/src/exit.c b/src/exit.c
index 71256a5..1e23908 100644
--- a/src/exit.c
+++ b/src/exit.c
@@ -1,16 +1,16 @@
#include "entityimpl.h"
-IMPL_UPDATE()
-}
+IMPL_UPDATE() {
+} IMPL_END
-IMPL_DRAW()
+IMPL_DRAW() {
LZY_DrawSetColor(BLACK);
LZY_DrawRect(this->pos[0] - this->width / 2,
this->pos[1] - this->height / 2,
this->width, this->height);
-}
+} IMPL_END
-IMPL_INIT(exit)
+IMPL_INIT(exit) {
this->width = 12;
this->height = 12;
-}
+} IMPL_END
diff --git a/src/exit.h b/src/exit.h
index 8b4ed04..633fe47 100644
--- a/src/exit.h
+++ b/src/exit.h
@@ -7,4 +7,4 @@ typedef struct {
struct Entity;
struct Game;
-void exit_init(struct Entity *this, int x, int y);
+struct Entity *exit_init(struct Entity *this, int x, int y);
diff --git a/src/game.c b/src/game.c
index 6ca8db0..c7159ae 100644
--- a/src/game.c
+++ b/src/game.c
@@ -21,9 +21,9 @@ game_deinit(Game *this)
void
game_update(Game *this)
{
- if (this->queue_restart_scene) {
- this->queue_restart_scene = false;
- game_restart_scene(this);
+ if (this->queue_restart_scene > 0) {
+ if (--this->queue_restart_scene == 0)
+ game_restart_scene(this);
}
if (this->queue_next_scene) {
this->queue_next_scene = false;
diff --git a/src/game.h b/src/game.h
index edbd689..96b264f 100644
--- a/src/game.h
+++ b/src/game.h
@@ -1,12 +1,12 @@
#pragma once
#include "entity.h"
-enum { MAX_ENTITIES = 64 };
+enum { MAX_ENTITIES = 128 };
typedef struct Game {
unsigned int uuid;
bool queue_next_scene;
- bool queue_restart_scene;
+ int queue_restart_scene;
Entity entities[MAX_ENTITIES];
} Game;
diff --git a/src/player.c b/src/player.c
index 24d61b0..f5a824f 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1,13 +1,15 @@
+#include "deathpart.h"
#include "entityimpl.h"
+#include "game.h"
#include "input.h"
#include <math.h>
-IMPL_UPDATE()
+IMPL_UPDATE() {
const int on_ground = entity_collide(this, g, 0, 1);
this->vel[0] = 2.0 * this->player.dirx;
- this->vel[1] *= 0.99;
- this->vel[1] += 0.2;
+ this->vel[1] *= AIR_RESISTANCE;
+ this->vel[1] += GRAVITY;
this->player.scale_x += 0.1 * (1.0 - this->player.scale_x);
this->player.scale_y += 0.1 * (1.0 - this->player.scale_y);
if (fabs(this->player.scale_x - 1.0) < 0.05) this->player.scale_x = 1.01;
@@ -42,14 +44,25 @@ IMPL_UPDATE()
if (this->vel[0] == 0.0 && this->vel[1] >= -0.0)
this->player.dirx *= -1;
- if (this->bonk_ceiling)
- g->queue_restart_scene = true;
+ if (this->bonk_ceiling) {
+ int dy = this->pos[1] - 6;
+ for (int y = 0; y < 7; y++) {
+ int dx = this->pos[0] - 6;
+ for (int x = 0; x < 7; x++) {
+ deathpart_init(game_create_entity(g), dx, dy);
+ dx += 2;
+ }
+ dy += 2;
+ }
+ this->type = ET_NONE;
+ g->queue_restart_scene = 30;
+ }
if (entity_place_meeting(this, g, ET_exit) != NULL)
g->queue_next_scene = true;
-}
+} IMPL_END
-IMPL_DRAW()
+IMPL_DRAW() {
LZY_DrawSetColor(BLACK);
int width = (int)(this->width / 2) * this->player.scale_x;
int height = (int)(this->height / 2) * this->player.scale_y;
@@ -58,12 +71,12 @@ IMPL_DRAW()
LZY_DrawRect(this->pos[0] - width / 2,
this->pos[1] - height / 2,
width, height);
-}
+} IMPL_END
-IMPL_INIT(player)
+IMPL_INIT(player) {
this->width = 12;
this->height = 12;
this->player.scale_x = 1.0;
this->player.scale_y = 1.0;
this->player.dirx = 1;
-}
+} IMPL_END
diff --git a/src/player.h b/src/player.h
index a492354..1e25883 100644
--- a/src/player.h
+++ b/src/player.h
@@ -1,5 +1,8 @@
#pragma once
+#define AIR_RESISTANCE 0.99
+#define GRAVITY 0.2
+
typedef struct {
double scale_x;
double scale_y;
@@ -9,4 +12,4 @@ typedef struct {
struct Entity;
struct Game;
-void player_init(struct Entity *this, int x, int y);
+struct Entity *player_init(struct Entity *this, int x, int y);