diff options
Diffstat (limited to 'projectile.c')
-rw-r--r-- | projectile.c | 59 |
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); +} + |