]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectMoveAction.cpp
added numbers animation for monsters' attacks
[l2e.git] / src / battle / states / SelectMoveAction.cpp
1 /*
2  * SelectMoveAction.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "SelectMoveAction.h"
9
10 #include "RunState.h"
11 #include "SelectAttackType.h"
12 #include "SwapHeroes.h"
13 #include "../BattleState.h"
14 #include "../MoveMenu.h"
15 #include "../../app/Application.h"
16 #include "../../app/Input.h"
17 #include "../../geometry/operators.h"
18
19 using app::Application;
20 using app::Input;
21 using geometry::Point;
22 using geometry::Vector;
23
24 namespace battle {
25
26 void SelectMoveAction::EnterState(Application &c, SDL_Surface *screen) {
27         ctrl = &c;
28 }
29
30 void SelectMoveAction::ExitState(Application &c, SDL_Surface *screen) {
31         ctrl = 0;
32 }
33
34 void SelectMoveAction::ResumeState(Application &ctrl, SDL_Surface *screen) {
35
36 }
37
38 void SelectMoveAction::PauseState(Application &ctrl, SDL_Surface *screen) {
39
40 }
41
42
43 void SelectMoveAction::Resize(int width, int height) {
44
45 }
46
47
48 void SelectMoveAction::HandleEvents(const Input &input) {
49         if (input.IsDown(Input::PAD_UP)) {
50                 battle->GetMoveMenu().Select(MoveMenu::CHANGE);
51         } else if (input.IsDown(Input::PAD_DOWN)) {
52                 battle->GetMoveMenu().Select(MoveMenu::RUN);
53         } else {
54                 battle->GetMoveMenu().Select(MoveMenu::ATTACK);
55         }
56
57         if (input.JustPressed(Input::ACTION_A)) {
58                 switch (battle->GetMoveMenu().Selected()) {
59                         case MoveMenu::ATTACK:
60                                 ctrl->ChangeState(new SelectAttackType(battle));
61                                 battle->NextHero();
62                                 break;
63                         case MoveMenu::CHANGE:
64                                 ctrl->PushState(new SwapHeroes(battle, this));
65                                 break;
66                         case MoveMenu::RUN:
67                                 ctrl->ChangeState(new RunState(battle));
68                                 break;
69                 }
70         }
71 }
72
73 void SelectMoveAction::UpdateWorld(float deltaT) {
74
75 }
76
77 void SelectMoveAction::Render(SDL_Surface *screen) {
78         Vector<int> offset(battle->CalculateScreenOffset(screen));
79         battle->RenderBackground(screen, offset);
80         battle->RenderMonsters(screen, offset);
81         battle->RenderHeroTags(screen, offset);
82         RenderMenu(screen, offset);
83 }
84
85 void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
86         Point<int> position(
87                         (battle->Width() - battle->GetMoveMenu().Width()) / 2,
88                         battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
89         battle->GetMoveMenu().Render(screen, position + offset);
90 }
91
92 }