Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Entity/Player/Player.h

Committer:
el17sm
Date:
2019-05-06
Revision:
33:4f3948dcd2f7
Parent:
32:fe6359ef9916
Child:
34:1d5b4da3935e

File content as of revision 33:4f3948dcd2f7:

#ifndef PLAYER_H
#define PLAYER_H
#include "Entity.h"
#include "Bullets.h"
#define INVULNERABILITY_PERIOD 50

const int bullets_max = 20;

class Player : public Entity
{
private:

    // Member Variables
    int fire_rate_counter;
    int fire_rate_delay;
    int _bullet_speed;
    int invulnerability_counter;
    
    // Private Functions
    void move_player(float mapped_x, float mapped_y, int * map, bool * doorways);
    void move_bullets();
    void increment_frames(float mapped_x, float mapped_y);
    char * get_frame();
    void draw_player(N5110 &lcd);
    void draw_bullets(N5110 &lcd);
    
public:
    // Constructors
    Player(float pos_x, float pos_y);
    // Deconstructors
    ~Player();

    // Accessors
    int get_bullet_speed();
    int get_hearts_width();
    int get_hearts_height();
    char * get_hearts_sprite();
    
    // Functions
    virtual void move(float, float, int * map, bool * doorways);
    virtual void take_damage(int damage);
    virtual void draw(N5110 &lcd);
    bool update_bullets(int * map, bool * doorways);
    void delete_bullets();
    void buttons(bool button_A, bool button_B, bool button_Y, bool button_X);

    // Variables
    Bullets *bullets_array[bullets_max];
    bool valid_bullets[bullets_max];
    
};

// Sprite
const char sprite_heart[9][9] = {
    {0,1,1,0,0,0,1,1,0,},
    {1,1,1,1,0,1,1,1,1,},
    {1,2,1,1,1,1,1,1,1,},
    {1,2,1,1,1,1,1,1,1,},
    {1,2,1,1,1,1,1,1,1,},
    {0,1,2,1,1,1,1,1,0,},
    {0,0,1,1,1,1,1,0,0,},
    {0,0,0,1,1,1,0,0,0,},
    {0,0,0,0,1,0,0,0,0,}
};

const char sprite_dying_player [5][12][12] = { // sprite_dying_player [Frame][Size_Y][Size_X]
    {
        {0,1,1,1,1,0,0,0,0,0,0,0,},
        {1,1,1,1,1,1,0,0,0,0,0,0,},
        {1,2,1,1,1,1,0,0,0,0,0,0,},
        {1,1,1,1,1,1,0,0,0,0,0,0,},
        {0,1,1,1,1,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
        {0,0,0,1,0,0,0,0,0,0,0,0,},
        {0,0,0,1,0,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
    },
    {
        {0,0,0,0,1,1,1,0,0,0,0,0,},
        {0,0,0,1,2,1,1,1,0,0,0,0,},
        {0,0,0,1,1,1,1,1,0,0,0,0,},
        {0,0,0,1,1,1,1,1,0,0,0,0,},
        {0,0,0,0,1,1,1,0,0,0,0,0,},
        {0,1,1,1,1,0,0,0,0,0,0,0,},
        {0,0,1,1,1,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
        {0,1,1,1,0,0,0,0,0,0,0,0,},
        {0,1,0,1,0,0,0,0,0,0,0,0,},
        {1,0,0,1,0,0,0,0,0,0,0,0,},
        {0,0,1,1,0,0,0,0,0,0,0,0,},
    },
    {
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,1,0,0,0,1,1,1,0,},
        {0,0,0,0,0,1,0,1,1,2,1,1,},
        {0,0,0,0,0,1,1,1,1,1,1,1,},
        {0,0,0,1,1,1,1,1,1,1,1,1,},
        {0,1,1,1,1,1,1,0,1,1,1,0,},
        {1,0,0,1,1,0,0,0,0,0,0,0,},
        {0,0,1,0,0,0,0,0,0,0,0,0,},
        {0,1,0,0,0,0,0,0,0,0,0,0,},
    },
    {
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {1,0,0,0,1,0,0,0,1,1,1,0,},
        {0,1,1,0,0,1,1,1,1,2,1,1,},
        {1,0,0,1,1,1,1,1,1,1,1,1,},
        {1,1,1,1,1,1,1,1,1,1,1,1,},
    },
    {
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,0,0,0,0,},
        {0,0,0,0,0,0,0,0,1,1,1,0,},
        {0,0,0,0,0,0,0,1,1,1,1,1,},
        {1,0,0,1,1,1,1,1,1,1,1,1,},
        {1,1,1,1,1,1,1,1,1,1,1,1,},
    }
};
    

const char sprite_transparent_player[12][6] = {
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,},
    {0,0,0,0,0,0,}
};

const char sprite_player [4][4][12][6] = {   // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
    {
        // Up
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,1,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,1,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,0,0,0,1,0,}
        }
    },
    {
        // Right
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,2,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,0,0,0,},
            {0,0,1,0,0,0,},
            {0,0,1,1,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,2,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,0,1,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,0,1,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,2,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,0,0,0,},
            {0,0,1,0,0,0,},
            {0,0,1,1,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,1,1,1,2,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,0,1,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,0,1,}
        }
    },
    {
        // Down
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,2,1,},
            {1,1,2,2,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,1,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,2,1,},
            {1,1,2,2,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,2,1,},
            {1,1,2,2,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,1,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,1,0,0,1,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,2,1,},
            {1,1,2,2,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,1,1,1,1,0,},
            {1,0,1,1,0,1,},
            {1,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,1,0,0,1,0,},
            {0,0,0,0,1,0,}
        }
    },
    {
        // Left
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,0,1,0,0,},
            {0,0,0,1,0,0,},
            {0,0,1,1,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,1,0,1,0,0,},
            {0,1,0,0,1,0,},
            {1,0,0,0,1,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,0,1,0,0,},
            {0,0,0,1,0,0,},
            {0,0,1,1,0,0,}
        },
        {
            {0,1,1,1,1,0,},
            {1,1,1,1,1,1,},
            {1,2,1,1,1,1,},
            {1,1,1,1,1,1,},
            {0,1,1,1,1,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,0,1,1,0,0,},
            {0,1,0,1,0,0,},
            {0,1,0,0,1,0,},
            {1,0,0,0,1,0,}
        }
    }
};

#endif