From a72420a85fdfe85d6a6e67b8c70ed11537d532bd Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 May 2023 20:30:58 +1000 Subject: Work on visual effects; Debris and player bullet impact effects. --- debris.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 debris.c (limited to 'debris.c') diff --git a/debris.c b/debris.c new file mode 100644 index 0000000..cf4a526 --- /dev/null +++ b/debris.c @@ -0,0 +1,96 @@ +#include "components.h" +#include "map.h" +#include "sprite.h" +#include "standard.h" +#include "world.h" + +Entity new_debris( + struct World* world, + int x, + int y, + int vx, + int vy, + Sprite_ID spr +) { + Entity e; + CPosition* pos; + CDebris* debris; + CCollider* col; + CSprite* sprite; + + e = new_entity(world); + add_components( + world, + e, + ctype_moveable | + ctype_collider | + ctype_debris | + ctype_position | + ctype_sprite + ); + + pos = &world->positions[e]; + debris = &world->debris[e]; + col = &world->colliders[e]; + sprite = &world->sprites[e]; + + init_csprite(sprite, spr); + pos->x = x; + pos->y = y; + debris->vx = vx; + debris->vy = vy; + col->x = 0; + col->y = 0; + col->w = sprite->rect.w; + col->h = sprite->rect.h; + + return e; +} + +void debris_system(World* world) { + int i; + unsigned bits; + CPosition* pos; + CDebris* debris; + CSprite* sprite; + Bitmap map_bitmap; + const Bitmap* bmp; + + get_map_bitmap(&world->map, &map_bitmap); + + for (i = 0; i < world->entity_count; i++) { + bits = world->bitmask[i]; + if ( + (bits & ctype_debris) && + (bits & ctype_position) && + (bits & ctype_sprite) + ) { + pos = &world->positions[i]; + debris = &world->debris[i]; + sprite = &world->sprites[i]; + + pos->x += debris->vx; + pos->y += debris->vy; + debris->vx = (debris->vx << fbits) / 600; + debris->vy = (debris->vy << fbits) / 600; + + if (debris->vx == 0 && debris->vy == 0) { + /* Blit the motherfucker straight to the map + * so that we don't have to keep updating it + * when it's just sitting still. We can have + * INFINITE debris now. */ + + bmp = get_bitmap(sprite->id); + blit( + &map_bitmap, + bmp, + pos->x >> fbits, + pos->y >> fbits, + &sprite->rect + ); + + destroy_entity(world, i); + } + } + } +} -- cgit v1.2.3-54-g00ecf