4 * Created on: Aug 7, 2012
8 #include "SelectAttackType.h"
10 #include "SelectMoveAction.h"
11 #include "SelectSpell.h"
12 #include "../AttackChoice.h"
13 #include "../BattleState.h"
14 #include "../../app/Application.h"
15 #include "../../app/Input.h"
16 #include "../../geometry/operators.h"
20 using app::Application;
22 using geometry::Point;
23 using geometry::Vector;
27 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
31 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
35 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
36 if (battle->AttackSelectionDone()) {
42 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
47 void SelectAttackType::Resize(int width, int height) {
52 void SelectAttackType::HandleInput(const Input &input) {
53 if (input.IsDown(Input::PAD_UP)) {
54 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
55 } else if (input.IsDown(Input::PAD_RIGHT)) {
56 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
57 } else if (input.IsDown(Input::PAD_DOWN)) {
58 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
59 } else if (input.IsDown(Input::PAD_LEFT)) {
60 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
62 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
65 if (input.JustPressed(Input::ACTION_A)) {
66 battle->SetAttackType(battle->GetAttackTypeMenu().Selected());
67 switch (battle->GetAttackTypeMenu().Selected()) {
68 case AttackChoice::SWORD:
69 // TODO: switch to target select
72 case AttackChoice::MAGIC:
73 if (battle->ActiveHero().CanUseMagic()) {
74 ctrl->PushState(new SelectSpell(battle, this));
77 case AttackChoice::DEFEND:
80 case AttackChoice::IKARI:
81 // TODO: switch to ikari attack select
84 case AttackChoice::ITEM:
85 // TODO: switch to item select
89 throw std::logic_error("selected invalid attack type");
91 } else if (input.JustPressed(Input::ACTION_B)) {
92 battle->SetAttackType(AttackChoice::UNDECIDED);
93 battle->PreviousHero();
94 if (battle->BeforeFirstHero()) {
95 ctrl->ChangeState(new SelectMoveAction(battle));
99 if (battle->AttackSelectionDone()) {
100 // TODO: switch to battle animation instead
105 void SelectAttackType::UpdateWorld(float deltaT) {
109 void SelectAttackType::Render(SDL_Surface *screen) {
110 Vector<int> offset(battle->CalculateScreenOffset(screen));
111 battle->RenderBackground(screen, offset);
112 battle->RenderMonsters(screen, offset);
113 battle->RenderHeroTags(screen, offset);
114 RenderMenu(screen, offset);
117 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
119 (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2,
120 battle->BackgroundHeight() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
121 battle->GetAttackTypeMenu().Render(screen, position + offset);