X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/8a947d16e5132fd133d67c76468c6323881de221..05db94c84b6f7e4ee91fd67d6e1a8d97a2b97f2e:/badge/jumpnrun/enemies.h?ds=inline diff --git a/badge/jumpnrun/enemies.h b/badge/jumpnrun/enemies.h index 394cf45..c66a28e 100644 --- a/badge/jumpnrun/enemies.h +++ b/badge/jumpnrun/enemies.h @@ -1,9 +1,10 @@ #ifndef INCLUDED_JUMPNRUN_ENEMIES_H #define INCLUDED_JUMPNRUN_ENEMIES_H -#include -#include +#include "../ui/sprite.h" +#include "../util/rectangle.h" +#include "moveable.h" #include "tiles.h" struct jumpnrun_game_state; @@ -13,10 +14,11 @@ struct jumpnrun_tile_range; struct jumpnrun_enemy; typedef struct jumpnrun_enemy_type { - unsigned animation_ticks_per_frame; - size_t animation_length; + uint8_t animation_ticks_per_frame; + uint8_t animation_length; badge_sprite const *animation_frames; + rectangle hitbox; vec2d spawn_inertia; void (*collision_tiles)(struct jumpnrun_enemy *self, @@ -24,37 +26,49 @@ typedef struct jumpnrun_enemy_type { struct jumpnrun_level *lv, struct jumpnrun_tile_range const *visible_tiles); void (*collision_player)(struct jumpnrun_enemy *self, - struct jumpnrun_game_state *state); - void (*game_tick)(struct jumpnrun_enemy *self, + struct jumpnrun_game_state *state, + vec2d *player_inertia_mod); + void (*collision_shots)(struct jumpnrun_enemy *self, + struct jumpnrun_game_state *state); + + void (*move_tick)(struct jumpnrun_enemy *self, struct jumpnrun_game_state *state, struct jumpnrun_level *lv, - struct jumpnrun_tile_range const *visible_tiles); + struct jumpnrun_tile_range const *visible_tiles, + vec2d *player_inertia_mod); } jumpnrun_enemy_type; typedef struct jumpnrun_enemy { - vec2d spawn_pos; - vec2d current_pos; - vec2d inertia; - unsigned flags; - unsigned tick_counter; - unsigned current_frame; + jumpnrun_moveable base; + vec2d spawn_pos; jumpnrun_enemy_type const *type; } jumpnrun_enemy; -static inline rectangle rect_from_enemy(jumpnrun_enemy const *enemy) { - badge_sprite const *cur_sprite = &enemy->type->animation_frames[(enemy->tick_counter / enemy->type->animation_ticks_per_frame) % enemy->type->animation_length]; - rectangle r = { enemy->current_pos, { FIXED_POINT(cur_sprite->width, 0), FIXED_POINT(cur_sprite->height, 0) } }; - return r; -} - enum { - JUMPNRUN_ENEMY_SPAWNED = 1, - JUMPNRUN_ENEMY_UNAVAILABLE = 2 +// Do not collide with JUMPNRUN_MOVEABLE_* flags + JUMPNRUN_ENEMY_SPAWNED = 128, + JUMPNRUN_ENEMY_UNAVAILABLE = 64, + JUMPNRUN_ENEMY_MOVING = 32, + JUMPNRUN_ENEMY_EVENT_TRIGGER1 = 16 }; +static inline rectangle const *enemy_hitbox(jumpnrun_enemy const *enemy) { return &enemy->base.hitbox; } +void jumpnrun_enemy_despawn(jumpnrun_enemy *self); +void jumpnrun_enemy_reset (jumpnrun_enemy *self); + enum { JUMPNRUN_ENEMY_TYPE_CAT, + JUMPNRUN_ENEMY_TYPE_MUSHROOM, + JUMPNRUN_ENEMY_TYPE_BUNNY, + JUMPNRUN_ENEMY_TYPE_SNAKE, + JUMPNRUN_ENEMY_TYPE_SPIRAL, + JUMPNRUN_ENEMY_TYPE_ROTOR, + JUMPNRUN_ENEMY_TYPE_DOG, + JUMPNRUN_ENEMY_TYPE_GIRAFFE, + JUMPNRUN_ENEMY_TYPE_BIRD, + JUMPNRUN_ENEMY_TYPE_BIRD_STRAIGHT, + JUMPNRUN_ENEMY_TYPE_BIRD_DIP, JUMPNRUN_ENEMY_TYPE_COUNT }; @@ -65,5 +79,6 @@ void jumpnrun_process_enemy(jumpnrun_enemy *self, badge_framebuffer *fb, struct jumpnrun_game_state *state, struct jumpnrun_level *lv, - struct jumpnrun_tile_range const *visible_tiles); + struct jumpnrun_tile_range const *visible_tiles, + vec2d *player_inertia_mod); #endif