]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectMoveAction.cpp
extracted battle logic into a class
[l2e.git] / src / battle / states / SelectMoveAction.cpp
1 #include "SelectMoveAction.h"
2
3 #include "RunState.h"
4 #include "SelectAttackType.h"
5 #include "SwapHeroes.h"
6 #include "../BattleState.h"
7 #include "../MoveMenu.h"
8 #include "../../app/Application.h"
9 #include "../../app/Input.h"
10 #include "../../math/Vector.h"
11
12 using app::Application;
13 using app::Input;
14 using math::Vector;
15
16 namespace battle {
17
18 SelectMoveAction::SelectMoveAction(Battle *battle, BattleState *parent)
19 : battle(battle)
20 , parent(parent) {
21
22 }
23
24
25 void SelectMoveAction::OnEnterState(SDL_Surface *screen) {
26         OnResize(screen->w, screen->h);
27 }
28
29 void SelectMoveAction::OnExitState(SDL_Surface *screen) {
30
31 }
32
33 void SelectMoveAction::OnResumeState(SDL_Surface *screen) {
34
35 }
36
37 void SelectMoveAction::OnPauseState(SDL_Surface *screen) {
38
39 }
40
41
42 void SelectMoveAction::OnResize(int width, int height) {
43         position = parent->ScreenOffset() + Vector<int>(
44                         (parent->Width() - parent->GetMoveMenu().Width()) / 2,
45                         parent->Height() - parent->GetMoveMenu().Height() - parent->GetMoveMenu().Height() / 2);
46 }
47
48
49 void SelectMoveAction::HandleEvents(const Input &input) {
50         if (input.IsDown(Input::PAD_UP)) {
51                 parent->GetMoveMenu().Select(MoveMenu::CHANGE);
52         } else if (input.IsDown(Input::PAD_DOWN)) {
53                 parent->GetMoveMenu().Select(MoveMenu::RUN);
54         } else {
55                 parent->GetMoveMenu().Select(MoveMenu::ATTACK);
56         }
57
58         if (input.JustPressed(Input::ACTION_A)) {
59                 switch (parent->GetMoveMenu().Selected()) {
60                         case MoveMenu::ATTACK:
61                                 Ctrl().ChangeState(new SelectAttackType(battle, parent));
62                                 battle->NextHero();
63                                 break;
64                         case MoveMenu::CHANGE:
65                                 Ctrl().PushState(new SwapHeroes(battle, this));
66                                 break;
67                         case MoveMenu::RUN:
68                                 Ctrl().ChangeState(new RunState(parent));
69                                 break;
70                 }
71         }
72 }
73
74 void SelectMoveAction::UpdateWorld(Uint32 deltaT) {
75
76 }
77
78 void SelectMoveAction::Render(SDL_Surface *screen) {
79         parent->RenderBackground(screen);
80         parent->RenderMonsters(screen);
81         parent->RenderHeroTags(screen);
82         RenderMenu(screen);
83 }
84
85 void SelectMoveAction::RenderMenu(SDL_Surface *screen) {
86         parent->GetMoveMenu().Render(screen, position);
87 }
88
89
90 const Resources &SelectMoveAction::Res() const {
91         return parent->Res();
92 }
93
94 const Vector<int> &SelectMoveAction::ScreenOffset() const {
95         return parent->ScreenOffset();
96 }
97
98 const HeroTag &SelectMoveAction::HeroTagAt(int index) const {
99         return parent->HeroTagAt(index);
100 }
101
102 const Vector<int> &SelectMoveAction::HeroTagPositionAt(int index) const {
103         return parent->HeroTagPositionAt(index);
104 }
105
106 }