]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/RunState.cpp
removed invalid TODO from spell selection
[l2e.git] / src / battle / states / RunState.cpp
1 /*
2  * RunState.cpp
3  *
4  *  Created on: Aug 10, 2012
5  *      Author: holy
6  */
7
8 #include "RunState.h"
9
10 #include "../BattleState.h"
11 #include "../../app/Application.h"
12 #include "../../app/Input.h"
13 #include "../../geometry/Vector.h"
14 #include "../../graphics/Font.h"
15 #include "../../graphics/Frame.h"
16
17 #include <cstring>
18
19 using app::Application;
20 using app::Input;
21 using geometry::Vector;
22
23 namespace battle {
24
25 void RunState::EnterState(Application &c, SDL_Surface *screen) {
26         ctrl = &c;
27         // TODO: push battle animation if enemy is faster
28 }
29
30 void RunState::ExitState(Application &c, SDL_Surface *screen) {
31         ctrl = 0;
32 }
33
34 void RunState::ResumeState(Application &ctrl, SDL_Surface *screen) {
35         timer = GraphicsTimers().StartCountdown(2500);
36 }
37
38 void RunState::PauseState(Application &ctrl, SDL_Surface *screen) {
39
40 }
41
42
43 void RunState::Resize(int width, int height) {
44
45 }
46
47
48 void RunState::HandleEvents(const Input &input) {
49         if (timer.Finished()) {
50                 battle->SetRunaway();
51                 ctrl->PopState(); // pop self
52         }
53 }
54
55
56 void RunState::UpdateWorld(float deltaT) {
57
58 }
59
60 void RunState::Render(SDL_Surface *screen) {
61         Vector<int> offset(battle->CalculateScreenOffset(screen));
62         battle->RenderBackground(screen, offset);
63         battle->RenderMonsters(screen, offset);
64         battle->RenderHeroes(screen, offset);
65         battle->RenderSmallHeroTags(screen, offset);
66         RenderTitleBar(screen, offset);
67 }
68
69 void RunState::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
70         int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
71         battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
72
73         Vector<int> textPosition(
74                         (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2,
75                         battle->Res().titleFrame->BorderHeight());
76         battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset);
77 }
78
79 }