4 * Created on: Aug 10, 2012
8 #include "PerformAttacks.h"
10 #include "../BattleState.h"
12 #include "../Monster.h"
13 #include "../../app/Application.h"
14 #include "../../app/Input.h"
15 #include "../../common/Ikari.h"
16 #include "../../common/Item.h"
17 #include "../../common/Spell.h"
18 #include "../../geometry/operators.h"
19 #include "../../geometry/Point.h"
20 #include "../../graphics/Animation.h"
21 #include "../../graphics/Font.h"
22 #include "../../graphics/Frame.h"
26 using app::Application;
28 using geometry::Point;
29 using geometry::Vector;
33 void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
37 void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
41 void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) {
42 fakeMoveTimer = GraphicsTimers().StartCountdown(850);
45 void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) {
50 void PerformAttacks::Resize(int width, int height) {
55 void PerformAttacks::HandleEvents(const Input &input) {
56 if (fakeMoveTimer.JustHit()) {
61 while (cursor < battle->MaxMonsters() && !battle->MonsterPositionOccupied(cursor)) {
64 if (cursor >= battle->MaxMonsters()) {
65 battle->ClearAllAttacks();
70 if (battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()) {
71 battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()->Stop();
73 if (battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()) {
74 battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()->Stop();
77 titleBarText = battle->MonsterAt(cursor).Name();
80 const AttackChoice &ac(battle->AttackChoiceAt(cursor));
84 switch (ac.GetType()) {
85 case AttackChoice::SWORD:
86 if (battle->HeroAt(cursor).AttackAnimation()) {
87 battle->HeroAt(cursor).AttackAnimation()->Start(*this);
90 case AttackChoice::MAGIC:
91 if (battle->HeroAt(cursor).SpellAnimation()) {
92 battle->HeroAt(cursor).SpellAnimation()->Start(*this);
95 case AttackChoice::DEFEND:
97 case AttackChoice::IKARI:
98 if (ac.GetItem()->HasIkari()) {
99 if (ac.GetItem()->GetIkari()->IsMagical()) {
100 if (battle->HeroAt(cursor).SpellAnimation()) {
101 battle->HeroAt(cursor).SpellAnimation()->Start(*this);
104 if (battle->HeroAt(cursor).AttackAnimation()) {
105 battle->HeroAt(cursor).AttackAnimation()->Start(*this);
110 case AttackChoice::ITEM:
112 case AttackChoice::UNDECIDED:
117 if (cursor == battle->NumHeroes()) {
123 if (battle->HeroAt(cursor - 1).AttackAnimation()) {
124 battle->HeroAt(cursor - 1).AttackAnimation()->Stop();
126 if (battle->HeroAt(cursor - 1).SpellAnimation()) {
127 battle->HeroAt(cursor - 1).SpellAnimation()->Stop();
130 switch (ac.GetType()) {
131 case AttackChoice::SWORD:
132 titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
134 case AttackChoice::MAGIC:
135 titleBarText = ac.GetSpell()->Name();
137 case AttackChoice::DEFEND:
138 titleBarText = "Defends.";
140 case AttackChoice::IKARI:
141 titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
143 case AttackChoice::ITEM:
144 titleBarText = ac.GetItem()->Name();
146 case AttackChoice::UNDECIDED:
147 titleBarText = "WTF???";
156 void PerformAttacks::UpdateWorld(float deltaT) {
160 void PerformAttacks::Render(SDL_Surface *screen) {
161 Vector<int> offset(battle->CalculateScreenOffset(screen));
162 battle->RenderBackground(screen, offset);
163 battle->RenderMonsters(screen, offset);
164 battle->RenderHeroes(screen, offset);
165 battle->RenderSmallHeroTags(screen, offset);
166 RenderTitleBar(screen, offset);
169 void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
170 if (!titleBarText) return;
172 int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
173 battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
175 Point<int> textPosition(
176 (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
177 battle->Res().titleFrame->BorderHeight());
178 battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);