4 * Created on: Aug 7, 2012
8 #include "SelectAttackType.h"
10 #include "../AttackChoice.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14 #include "../../geometry/operators.h"
18 using app::Application;
20 using geometry::Point;
21 using geometry::Vector;
25 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
29 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
33 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
37 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
42 void SelectAttackType::Resize(int width, int height) {
47 void SelectAttackType::HandleInput(const Input &input) {
48 if (input.IsDown(Input::PAD_UP)) {
49 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
50 } else if (input.IsDown(Input::PAD_RIGHT)) {
51 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
52 } else if (input.IsDown(Input::PAD_DOWN)) {
53 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
54 } else if (input.IsDown(Input::PAD_LEFT)) {
55 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
57 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
60 if (input.JustPressed(Input::ACTION_A)) {
61 battle->SetAttackType(battle->GetAttackTypeMenu().Selected());
62 switch (battle->GetAttackTypeMenu().Selected()) {
63 case AttackChoice::SWORD:
64 // TODO: switch to target select
67 case AttackChoice::MAGIC:
68 // TODO: switch to spell select
71 case AttackChoice::DEFEND:
74 case AttackChoice::IKARI:
75 // TODO: switch to ikari attack select
78 case AttackChoice::ITEM:
79 // TODO: switch to item select
83 throw std::logic_error("selected invalid attack type");
87 if (battle->AttackSelectionDone()) {
88 // TODO: switch to battle animation instead
93 void SelectAttackType::UpdateWorld(float deltaT) {
97 void SelectAttackType::Render(SDL_Surface *screen) {
98 Vector<int> offset(battle->CalculateScreenOffset(screen));
99 battle->RenderBackground(screen, offset);
100 battle->RenderMonsters(screen, offset);
101 battle->RenderHeroTags(screen, offset);
102 RenderMenu(screen, offset);
105 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
107 (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2,
108 battle->BackgroundHeight() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
109 battle->GetAttackTypeMenu().Render(screen, position + offset);