4 #include "../battle/fwd.h"
5 #include "../battle/Monster.h"
6 #include "../geometry/Vector.h"
7 #include "../graphics/fwd.h"
8 #include "../graphics/Animation.h"
15 /// An entity that can be placed on a map, moved around, animated, and possibly
16 /// interact with the player.
20 static const int TYPE_ID = 605;
28 ORIENTATION_NORTH = 0,
30 ORIENTATION_SOUTH = 2,
34 FLAG_NONBLOCKING = 0x01,
36 FLAG_FIXED_ORIENTATION = 0x04,
40 /// Pixel resolved position of the entity's top left corner on the map.
41 geometry::Vector<float> &Position() { return position; }
42 const geometry::Vector<float> &Position() const { return position; }
44 /// Velocity of the entity in pixels per second.
45 geometry::Vector<float> &Velocity() { return velocity; }
46 const geometry::Vector<float> &Velocity() const { return velocity; }
48 /// Offset of the entity's sprite's to left corner relative to Position().
49 geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
50 const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
52 /// Reset the entity to the stored tile coordinates (usually set when
53 /// loading game data).
54 void ResetPosition(const geometry::Vector<int> &tileSize) { position = tilePosition * tileSize; }
56 /// Set the animation to use for animated entities.
57 /// For orientable entities, the animation should have north, south, east,
58 /// and west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively.
59 /// If the entity can carry, row offset 2 is used.
60 /// If the entity can push, row offset 4 is used.
61 void SetAnimation(const graphics::Animation *a);
62 /// Start the animation on a global timer.
63 void StartAnimation(app::Application &ctrl);
64 /// Start the animation on a state timer.
65 void StartAnimation(app::State &ctrl);
66 /// Stop the animation.
68 /// Check if an animation is running.
69 bool AnimationRunning() const { return runner.Running(); }
71 /// Set the sprite used for the non-animated state.
72 /// For orientable entities, the sprite should have north, south, east, and
73 /// west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively.
74 void SetSprite(const graphics::Sprite *s) { sprite = s; }
76 /// Change the entity's orientation to given one.
77 /// If the entity is moving, velocity is changed accordingly.
78 void SetOrientation(Orientation);
79 Orientation GetOrientation() const { return orientation; }
80 /// Set the entity's speed in pixels per second.
81 /// This speed is then combined with the orientation to form a velocity.
84 /// Change to a natural, relaxed animation state (row offset 0).
86 /// Change animation to represent a carrying thingamabob (row offset 2).
88 /// Set a pushy animation state (row offset 4).
91 /// Set some basic boolean properties.
92 /// Parameter should be a combination from the Flags enum.
93 void SetFlags(int f) { flags = f; }
94 /// Check if the entity is blocking other entities from occupying its tile.
95 bool Blocking() const { return !(flags & FLAG_NONBLOCKING); }
96 /// Check if a battle should be launched when stepping onto a neighboring
98 bool Hostile() const { return partyLayout && numMonsters > 0; }
99 /// Check if this entity can be pushed around.
100 bool Pushable() const { return flags & FLAG_PUSHABLE; }
101 /// Check if the entity's orientation has any effect on the column rendered
102 /// from the animation or sprite.
103 bool CanTurn() const { return !(flags & FLAG_FIXED_ORIENTATION); }
105 /// Set a layout in battle for the party described by SetMonsters().
106 void SetPartyLayout(battle::PartyLayout *l) { partyLayout = l; }
107 /// Get the layout in battle for the party described by
108 /// Monsters{Begin,End}().
109 battle::PartyLayout *PartyLayout() { return partyLayout; }
111 /// Add monsters. This will cause the entity to be Hostile() and result in a
112 /// battle scene with given monsters when touched.
113 void SetMonsters(battle::Monster **m, int num) { monsters = m; numMonsters = num; }
114 battle::Monster **MonstersBegin() { return monsters; }
115 battle::Monster **MonstersEnd() { return monsters + numMonsters; }
117 /// Get an entity that should follow in this one's steps or 0 if none.
118 Entity *Follower() { return follower; }
119 const Entity *Follower() const { return follower; }
120 /// Add an entity that follows this one.
121 /// If this already has a follower, it is added to that one instead.
122 void AddFollower(Entity *);
123 /// Remove given entity from this entity or its follower.
124 void RemoveFollower(Entity *);
126 /// Check if position locks into grid defined by given tileSize.
127 bool TileLock(const geometry::Vector<int> &tileSize) const;
129 /// Integrate this entity's physical properties over given time interval.
130 void Update(float deltaT);
132 void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
134 static void CreateTypeDescription();
135 static void Construct(void *);
136 static void Load(void *);
139 void UpdateVelocity();
143 const graphics::Animation *animation;
144 const graphics::Sprite *sprite;
145 battle::PartyLayout *partyLayout;
146 battle::Monster **monsters;
148 graphics::AnimationRunner runner;
149 geometry::Vector<int> spriteOffset;
150 geometry::Vector<int> tilePosition;
151 geometry::Vector<float> position;
152 geometry::Vector<float> velocity;
153 Orientation orientation;
161 #endif /* MAP_ENTITY_H_ */