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/Font.h"
21 #include "../../graphics/Frame.h"
25 using app::Application;
27 using geometry::Point;
28 using geometry::Vector;
32 void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
34 // TODO: push battle animation if enemy is faster
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 < (int)battle->Monsters().size() && !battle->MonsterPositionOccupied(cursor)) {
64 if (cursor >= (int)battle->Monsters().size()) {
65 battle->ClearAllAttacks();
69 titleBarText = battle->MonsterAt(cursor).Name();
75 if (cursor == battle->NumHeroes()) {
80 const AttackChoice &ac(battle->AttackChoiceAt(cursor));
81 switch (ac.GetType()) {
82 case AttackChoice::SWORD:
83 titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
85 case AttackChoice::MAGIC:
86 titleBarText = ac.GetSpell()->Name();
88 case AttackChoice::DEFEND:
89 titleBarText = "Defends.";
91 case AttackChoice::IKARI:
92 titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
94 case AttackChoice::ITEM:
95 titleBarText = ac.GetItem()->Name();
97 case AttackChoice::UNDECIDED:
98 titleBarText = "WTF???";
107 void PerformAttacks::UpdateWorld(float deltaT) {
111 void PerformAttacks::Render(SDL_Surface *screen) {
112 Vector<int> offset(battle->CalculateScreenOffset(screen));
113 battle->RenderBackground(screen, offset);
114 battle->RenderMonsters(screen, offset);
115 battle->RenderHeroes(screen, offset);
117 RenderTitleBar(screen, offset);
120 void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
121 if (!titleBarText) return;
123 int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
124 battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
126 Point<int> textPosition(
127 (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
128 battle->Res().titleFrame->BorderHeight());
129 battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);