
#ifndef mosaic_mob_player_hh
#define mosaic_mob_player_hh

#include "mob_main.hh"

struct Mob_player : public Mob {
 public:
        static constexpr int JUMPING = 0x10000;      // 1 if player is jumping
        static constexpr int DOWN    = 0x20000;      // 1 if health is depleted

 private:
        size_t brush_idle;
        size_t brush_walk;
        size_t brush_run;
        size_t brush_jump;
        size_t brush_skid;
        size_t brush_hurt;
        size_t brush_reel;
        size_t brush_attk;
        size_t brush_head;

        MIX_Audio* sound_step;
        MIX_Audio* sound_jump;
        MIX_Audio* sound_land;
        MIX_Audio* sound_skid;
        MIX_Audio* sound_dunk;
        MIX_Audio* sound_hurt;
        MIX_Audio* sound_attk;

        uint8_t rest{0};        // Coyote time for the Body_resting flag
        uint8_t land{0};        // Countdown for landing
        uint8_t jump{0};        // Jump buffer
        uint8_t hurt{0};        // Countdown for invincibility
        uint8_t idle{0};        // Countdown for health recovery
        uint8_t attk{0};        // Countdown for attack
        int8_t health{127};     // Current health
        uint16_t frame{0};      // Current frame.
        uint16_t prev_frame{0}; // Previous frame.

        void update_rest(Scene& sc);
        void update_move(Scene& sc);
        void update_jump(Scene& sc);
        void update_frame(Scene& sc);
        void update_effects(Scene& sc);
        void update_health(Scene& sc);
        void update_attack(Scene& sc);

 public:
        itty::Box hit{INFINITY, INFINITY, INFINITY, INFINITY};

        Mob_player(Mobs& mobs, const itty::Box& box, Place*);
        bool update(Scene& sc);
        void render(Mobs& mobs);
        // press and release jump
        void begin_jump();
        void end_jump();
        // press and release attack
        void begin_attack();
        void end_attack();
        // attempt to harm player
        bool harm(const itty::Box& b);
        // reset player (to restart room)
        void reset();
};

#endif // mosaic_mob_player_hh
