Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MotionSensor
Entity/Player/Player.h
- Committer:
- el17sm
- Date:
- 2019-05-07
- Revision:
- 38:09832e662803
- Parent:
- 34:1d5b4da3935e
File content as of revision 38:09832e662803:
#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, char * map, bool * doorways);
void move_bullets();
void increment_frames(float mapped_x, float mapped_y);
char * get_frame();
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, char * map, bool * doorways);
virtual void take_damage(int damage);
virtual void draw(N5110 &lcd);
bool update_bullets(char * 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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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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