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-04-25
- Revision:
- 23:5a8f75e93508
- Parent:
- 22:7abf4581bc9b
- Child:
- 27:a1b41626f57c
File content as of revision 23:5a8f75e93508:
#ifndef PLAYER_H
#define PLAYER_H
#include "Entity.h"
#include "Bullets.h"
const int bullets_max = 20;
class Player : public Entity
{
private:
// Member Variables
struct SpriteDisplay {
int width;
int height;
int * sprite;
};
SpriteDisplay hearts;
int fire_rate_counter;
int fire_rate_delay;
int _bullet_speed;
const static int invulnerability_period = 50;
int invulnerability_counter;
public:
// Constructors
Player(float, float);
// Functions
virtual void move(float, float);
virtual int * get_frame();
virtual void take_damage(int);
void buttons(bool, bool, bool, bool);
void update_hearts();
int get_hearts_width();
int get_hearts_height();
int * get_hearts_sprite();
// accessors
int get_bullet_speed();
// variables
Bullets *bullets_array[bullets_max];
bool valid_bullets[bullets_max];
};
// Sprite
const int 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 int 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 int sprite_player [4][4][12][6] = { // Player [Face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