2012-09-09 20:50:15 +00:00
|
|
|
/*
|
|
|
|
* Player.h
|
|
|
|
*
|
|
|
|
* Created on: 21.07.2012
|
|
|
|
* Author: Felix
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DG_PLAYER_H_
|
|
|
|
#define DG_PLAYER_H_
|
|
|
|
|
|
|
|
#include <SFML/System.hpp>
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2012-10-01 07:12:00 +00:00
|
|
|
#include "../Pathfinder.h"
|
2012-09-09 20:50:15 +00:00
|
|
|
#include "../abstract/Actor.h"
|
|
|
|
#include "../abstract/Sprite.h"
|
|
|
|
#include "../items/Weapon.h"
|
|
|
|
#include "../util/Vector.h"
|
|
|
|
|
2012-09-14 18:39:56 +00:00
|
|
|
class Actor;
|
2012-10-01 07:12:00 +00:00
|
|
|
class Pathfinder;
|
2012-09-09 20:50:15 +00:00
|
|
|
class Sprite;
|
2012-09-14 18:39:56 +00:00
|
|
|
class Weapon;
|
2012-09-09 20:50:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Player object.
|
|
|
|
*/
|
|
|
|
class Player : public Sprite, public Actor {
|
2012-09-12 18:10:29 +00:00
|
|
|
// Public types.
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Movement directions that can be set via Player::setDirection().
|
|
|
|
*/
|
2012-10-01 07:41:38 +00:00
|
|
|
enum class Direction : uint8 {
|
|
|
|
RIGHT = 1 << 0,
|
|
|
|
LEFT = 1 << 1,
|
|
|
|
UP = 1 << 2,
|
|
|
|
DOWN = 1 << 3
|
2012-09-12 18:10:29 +00:00
|
|
|
};
|
|
|
|
|
2012-09-09 20:50:15 +00:00
|
|
|
// Public functions.
|
2012-09-12 12:21:57 +00:00
|
|
|
public:
|
2012-10-01 07:12:00 +00:00
|
|
|
Player(b2World& world, Collection& collection, const Vector2f& position, Pathfinder& pathfinder);
|
2012-09-09 20:50:15 +00:00
|
|
|
|
|
|
|
void setCrosshairPosition(const Vector2f& position);
|
|
|
|
void fire();
|
|
|
|
void move(const Vector2f& destination);
|
2012-09-12 18:10:29 +00:00
|
|
|
void setDirection(Direction direction, bool unset);
|
2012-09-09 20:50:15 +00:00
|
|
|
|
2012-09-12 18:10:29 +00:00
|
|
|
// Private functions.
|
|
|
|
private:
|
2012-09-09 20:50:15 +00:00
|
|
|
void onCollide(Physical& other, uint16 category);
|
|
|
|
void onThink(float elapsedTime);
|
|
|
|
|
|
|
|
// Private variables.
|
|
|
|
private:
|
2012-09-12 12:21:57 +00:00
|
|
|
static const float SPEED;
|
2012-09-11 19:12:34 +00:00
|
|
|
static const Vector2i SIZE;
|
2012-10-01 07:12:00 +00:00
|
|
|
/// The distance to a point where it is considered reached.
|
|
|
|
static const float POINT_REACHED_DISTANCE;
|
2012-09-12 12:21:57 +00:00
|
|
|
|
2012-09-09 20:50:15 +00:00
|
|
|
Weapon mWeapon; //< Weapon object used for Player::fire().
|
|
|
|
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
|
2012-10-01 07:12:00 +00:00
|
|
|
|
2012-09-12 18:10:29 +00:00
|
|
|
uint8 mDirection; //< Current movement direction for direct control.
|
2012-10-01 07:12:00 +00:00
|
|
|
|
|
|
|
Pathfinder& mPathfinder;
|
|
|
|
std::vector<Vector2f> mPath;
|
2012-09-09 20:50:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* DG_PLAYER_H_ */
|