aboutsummaryrefslogtreecommitdiff
path: root/projectile.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-08 19:56:08 +1100
committerquou <quou@disroot.org>2024-10-08 19:56:08 +1100
commit9add408984464bd6b3cc018bb14c3d69ad0a2898 (patch)
treedde2af5525fd076d03c5c8e14067a4502aa1051e /projectile.c
parentb5c69695c9c97c09f7ffa4d5a600d88cc06ee6da (diff)
New flying enemy that drops arrows
Diffstat (limited to 'projectile.c')
-rw-r--r--projectile.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/projectile.c b/projectile.c
new file mode 100644
index 0000000..ce68e8f
--- /dev/null
+++ b/projectile.c
@@ -0,0 +1,59 @@
+#include "animation.h"
+#include "asset.h"
+#include "maths.h"
+#include "obj.h"
+#include "physics.h"
+#include "render.h"
+#include "world.h"
+
+void init_projectile(
+ Projectile* p,
+ int x,
+ int y,
+ const Rect* r,
+ int anim
+) {
+ p->r = *r;
+ p->frame = 0;
+ p->anim = anim;
+ p->x = x;
+ p->y = y;
+ p->vx = 0;
+ p->vy = 0;
+ p->s.x = 0;
+ p->s.y = 0;
+ p->s.w = 0;
+ p->s.h = 0;
+}
+
+int update_projectile(
+ Projectile* p,
+ const World* w
+) {
+ Rect r = p->r;
+ int grounded = 1, headbutted = 1, on_ramp = 0;
+ const Animation* a = get_animation(p->anim);
+ r.x <<= fbits;
+ r.y <<= fbits;
+ r.w <<= fbits;
+ r.h <<= fbits;
+ update_body(
+ &w->map,
+ &p->x,
+ &p->y,
+ &p->vx,
+ &p->vy,
+ &grounded,
+ &headbutted,
+ &on_ramp,
+ &r
+ );
+ update_anim(a, &p->frame, &p->s);
+ return !grounded;
+}
+
+void ren_projectile(const Projectile* p, Renderer* r) {
+ const Bitmap* bm = get_bitmap(asset_id_arms_img);
+ ren_map(r, p->x >> fbits, p->y >> fbits, &p->s, bm);
+}
+