diff options
author | quou <quou@disroot.org> | 2023-05-07 12:53:46 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-07 12:54:06 +1000 |
commit | 5f341eacdf0d75a4b334969a2d8a4701d61e4d9e (patch) | |
tree | ee3a4c44b92e975530e1e6fed18c8852a6f70a93 /spawner.c | |
parent | 5ef6a71e935e2c3d1e5f9828e8cdbd78403a06a0 (diff) |
Add waves and stuff.
Diffstat (limited to 'spawner.c')
-rw-r--r-- | spawner.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spawner.c b/spawner.c new file mode 100644 index 0000000..058a894 --- /dev/null +++ b/spawner.c @@ -0,0 +1,68 @@ +#include "animation.h" +#include "components.h" +#include "enemy.h" +#include "world.h" + +int new_spawner( + World* world, + int x, + int y +) { + Entity e; + CPosition* pos; + CSprite* sprite; + CAnimated* animated; + + e = new_entity(world); + add_components( + world, + e, + ctype_sprite | + ctype_position | + ctype_animated | + ctype_spawner + ); + + pos = &world->positions[e]; + sprite = &world->sprites[e]; + animated = &world->animateds[e]; + + pos->x = x; + pos->y = y; + + sprite->id = asset_id_usr; + sprite->rect = make_rect(0, 0, 16, 16); + + animated->id = animation_spawn; + animated->frame = 0; + animated->timer = 0; + + return e; +} + +void spawner_system(World* world) { + int i; + const CPosition* pos; + const CAnimated* animated; + const Animation* animation; + unsigned bits; + + for (i = 0; i < world->entity_count; i++) { + bits = world->bitmask[i]; + if ( + (bits & ctype_spawner) && + (bits & ctype_position) && + (bits & ctype_animated) + ) { + pos = &world->positions[i]; + animated = &world->animateds[i]; + + animation = get_animation(animated->id); + + if (animated->frame == animation->frame_count - 1) { + new_skull(world, pos->x, pos->y); + destroy_entity(world, i); + } + } + } +} |