]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectAttackType.cpp
reworked Application's state stack
[l2e.git] / src / battle / states / SelectAttackType.cpp
1 /*
2  * SelectAttackType.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "SelectAttackType.h"
9
10 #include "../AttackChoice.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14 #include "../../geometry/operators.h"
15
16 #include <stdexcept>
17
18 using app::Application;
19 using app::Input;
20 using geometry::Point;
21 using geometry::Vector;
22
23 namespace battle {
24
25 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
26         ctrl = &c;
27 }
28
29 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
30         ctrl = 0;
31 }
32
33 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
34
35 }
36
37 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
38
39 }
40
41
42 void SelectAttackType::Resize(int width, int height) {
43
44 }
45
46
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);
56         } else {
57                 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
58         }
59
60         if (input.JustPressed(Input::ACTION_A)) {
61                 battle->SetAttackType(battle->GetAttackTypeMenu().Selected());
62                 switch (battle->GetAttackTypeMenu().Selected()) {
63                         case AttackChoice::SWORD:
64                                 battle->NextHero();
65                                 break;
66                         case AttackChoice::MAGIC:
67                                 // TODO: switch to spell select
68                                 break;
69                         case AttackChoice::DEFEND:
70                                 battle->NextHero();
71                                 break;
72                         case AttackChoice::IKARI:
73                                 // TODO: switch to ikari attack select
74                                 break;
75                         case AttackChoice::ITEM:
76                                 // TODO: switch to item select
77                                 break;
78                         default:
79                                 throw std::logic_error("selected invalid attack type");
80                 }
81         }
82
83         if (battle->AttackSelectionDone()) {
84                 // TODO: switch to battle animation instead
85                 ctrl->PopState();
86         }
87 }
88
89 void SelectAttackType::UpdateWorld(float deltaT) {
90
91 }
92
93 void SelectAttackType::Render(SDL_Surface *screen) {
94         Vector<int> offset(battle->CalculateScreenOffset(screen));
95         battle->RenderBackground(screen, offset);
96         battle->RenderMonsters(screen, offset);
97         battle->RenderHeroTags(screen, offset);
98         RenderMenu(screen, offset);
99 }
100
101 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
102         Point<int> position(
103                         (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2,
104                         (battle->BackgroundHeight() * 3 / 4) - (battle->GetAttackTypeMenu().Height() / 2));
105         battle->GetAttackTypeMenu().Render(screen, position + offset);
106 }
107
108 }