aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--effect.c40
-rw-r--r--obj.h13
-rw-r--r--world.c20
-rw-r--r--world.h12
5 files changed, 85 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 06f7573..65f4b5d 100644
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,7 @@ sources = \
animation.c \
asset.c \
deathzone.c \
+ effect.c \
enemy.c \
hud.c \
map.c \
diff --git a/effect.c b/effect.c
new file mode 100644
index 0000000..9db1608
--- /dev/null
+++ b/effect.c
@@ -0,0 +1,40 @@
+#include "config.h"
+#include "maths.h"
+#include "obj.h"
+#include "random.h"
+#include "render.h"
+
+void init_effect(Effect* e, int x, int y, int vx, int vy, int c) {
+ int i;
+ e->c = c;
+ for (i = 0; i < c; i++) {
+ const int a = get_r() & 0xff;
+ const int sa = sin_table[a];
+ const int ca = cos_table[a];
+ e->x[i] = x;
+ e->y[i] = y;
+ e->vx[i] = vx + ca - sa + get_rf();
+ e->vy[i] = vy + sa + ca + get_rf();
+ }
+ e->life = 100;
+}
+
+int update_effect(Effect* e) {
+ int i;
+ for (i = 0; i < e->c; i++) {
+ e->vy[i] += main_gravity;
+ e->x[i] += e->vx[i];
+ e->y[i] += e->vy[i];
+ }
+ return !(e->life--);
+}
+
+void ren_effect(const Effect* e, Renderer* r) {
+ Rect re = { 0, 0, 1, 1 };
+ int i;
+ for (i = 0; i < e->c; i++) {
+ re.x = e->x[i] >> fbits;
+ re.y = e->y[i] >> fbits;
+ ren_rect(r, &re);
+ }
+}
diff --git a/obj.h b/obj.h
index ad7098c..f29d5a4 100644
--- a/obj.h
+++ b/obj.h
@@ -65,6 +65,19 @@ void init_particle(Particle* p, int x, int y, int anim, int bmp);
int update_particle(Particle* p);
void ren_particle(const Particle* p, struct Renderer* r);
+#define effect_max 32
+typedef struct {
+ int x[effect_max];
+ int y[effect_max];
+ int vx[effect_max];
+ int vy[effect_max];
+ int c, life;
+} Effect;
+
+void init_effect(Effect* e, int x, int y, int vx, int vy, int c);
+int update_effect(Effect* e);
+void ren_effect(const Effect* e, struct Renderer* r);
+
typedef enum {
enemy_demon
} Enemy_Type;
diff --git a/world.c b/world.c
index b1f73ec..1881df2 100644
--- a/world.c
+++ b/world.c
@@ -54,6 +54,21 @@ Deathzone* inst_deathzone(
return d;
}
+Effect* inst_effect(
+ World* w,
+ int x,
+ int y,
+ int vx,
+ int vy,
+ int c
+) {
+ Effect* e;
+ assert(w->effect_count < max_effects);
+ e = &w->effects[w->effect_count++];
+ init_effect(e, x, y, vx, vy, c);
+ return e;
+}
+
void update_world(World* w, const App* a) {
int i;
if (w->laser.life)
@@ -69,6 +84,9 @@ void update_world(World* w, const App* a) {
for (i = w->particle_count - 1; i >= 0; i--)
if (update_particle(&w->particles[i]))
w->particles[i] = w->particles[--w->particle_count];
+ for (i = w->effect_count - 1; i >= 0; i--)
+ if (update_effect(&w->effects[i]))
+ w->effects[i] = w->effects[--w->effect_count];
for (i = w->enemy_count - 1; i >= 0; i--)
if (update_enemy(&w->enemies[i], w))
w->enemies[i] = w->enemies[--w->enemy_count];
@@ -81,6 +99,8 @@ void ren_world(const World* w, struct Renderer* r) {
render_map(&w->map, r);
for (i = 0; i < w->particle_count; i++)
ren_particle(&w->particles[i], r);
+ for (i = 0; i < w->effect_count; i++)
+ ren_effect(&w->effects[i], r);
for (i = 0; i < w->enemy_count; i++)
ren_enemy(&w->enemies[i], r);
if (w->laser.life)
diff --git a/world.h b/world.h
index 05372ae..81feb6f 100644
--- a/world.h
+++ b/world.h
@@ -7,6 +7,7 @@
#define max_particles 32
#define max_enemies 16
#define max_deathzones 16
+#define max_effects 16
struct Renderer;
@@ -14,7 +15,8 @@ typedef struct World {
Particle particles[max_particles];
Enemy enemies[max_enemies];
Deathzone deathzones[max_deathzones];
- int particle_count, enemy_count;
+ Effect effects[max_effects];
+ int particle_count, enemy_count, effect_count;
int deathzone_count;
Player player;
Laser laser;
@@ -45,6 +47,14 @@ Deathzone* inst_deathzone(
int life,
int friendly
);
+Effect* inst_effect(
+ World* w,
+ int x,
+ int y,
+ int vx,
+ int vy,
+ int c
+);
void update_world(World* w, const struct App* a);
void ren_world(const World* w, struct Renderer* r);