Level von mcsilver -- braucht Modifikation wegen neuer Physik.
[hackover2013-badge-firmware.git] / badge / jumpnrun / enemies.h
index cb88647..ecb2b4e 100644 (file)
@@ -4,6 +4,7 @@
 #include "../ui/sprite.h"
 #include "../util/rectangle.h"
 
 #include "../ui/sprite.h"
 #include "../util/rectangle.h"
 
+#include "moveable.h"
 #include "tiles.h"
 
 struct jumpnrun_game_state;
 #include "tiles.h"
 
 struct jumpnrun_game_state;
@@ -17,6 +18,8 @@ typedef struct jumpnrun_enemy_type {
   size_t              animation_length;
   badge_sprite const *animation_frames;
 
   size_t              animation_length;
   badge_sprite const *animation_frames;
 
+  vec2d               extent;
+  rectangle           hitbox;
   vec2d               spawn_inertia;
 
   void (*collision_tiles)(struct jumpnrun_enemy             *self,
   vec2d               spawn_inertia;
 
   void (*collision_tiles)(struct jumpnrun_enemy             *self,
@@ -24,29 +27,28 @@ 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_level             *lv,
                          struct jumpnrun_tile_range  const *visible_tiles);
   void (*collision_player)(struct jumpnrun_enemy      *self,
-                          struct jumpnrun_game_state *state);
+                          struct jumpnrun_game_state *state,
+                          vec2d                      *player_inertia_mod);
   void (*game_tick)(struct jumpnrun_enemy            *self,
                    struct jumpnrun_game_state       *state,
                     struct jumpnrun_level            *lv,
   void (*game_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 {
 } 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;
+  unsigned          flags;
 
   jumpnrun_enemy_type const *type;
 } jumpnrun_enemy;
 
 
   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;
-}
+static inline rectangle    const *enemy_box         (jumpnrun_enemy const *enemy) { return &enemy->base.current_box   ; }
+static inline vec2d               enemy_position    (jumpnrun_enemy const *enemy) { return enemy->base.current_box.pos; }
+static inline rectangle           enemy_hitbox      (jumpnrun_enemy const *enemy) { rectangle r = enemy->type->hitbox; rectangle_move_rel(&r, enemy_position(enemy)); return r; }
+static inline badge_sprite const *enemy_sprite      (jumpnrun_enemy const *enemy) { return &enemy->type->animation_frames[enemy->base.anim_frame]; }
+static inline uint8_t             enemy_render_flags(jumpnrun_enemy const *enemy) { return fixed_point_lt(enemy->base.inertia.x, FIXED_POINT(0, 0)) ? 0 : BADGE_BLT_MIRRORED; }
 
 enum {
   JUMPNRUN_ENEMY_SPAWNED     = 1,
 
 enum {
   JUMPNRUN_ENEMY_SPAWNED     = 1,
@@ -56,7 +58,9 @@ enum {
 enum {
   JUMPNRUN_ENEMY_TYPE_CAT,
   JUMPNRUN_ENEMY_TYPE_MUSHROOM,
 enum {
   JUMPNRUN_ENEMY_TYPE_CAT,
   JUMPNRUN_ENEMY_TYPE_MUSHROOM,
-  JUMPNRUN_ENEMY_TYPE_KANINCHEN,
+  JUMPNRUN_ENEMY_TYPE_BUNNY,
+  JUMPNRUN_ENEMY_TYPE_SNAKE,
+  JUMPNRUN_ENEMY_TYPE_SPIRAL,
 
   JUMPNRUN_ENEMY_TYPE_COUNT
 };
 
   JUMPNRUN_ENEMY_TYPE_COUNT
 };
@@ -67,5 +71,6 @@ void jumpnrun_process_enemy(jumpnrun_enemy                   *self,
                            badge_framebuffer                *fb,
                            struct jumpnrun_game_state       *state,
                            struct jumpnrun_level            *lv,
                            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
 #endif
This page took 0.026082 seconds and 4 git commands to generate.