]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/RunState.cpp
moved TODOs to tracker
[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 }
28
29 void RunState::ExitState(Application &c, SDL_Surface *screen) {
30         ctrl = 0;
31 }
32
33 void RunState::ResumeState(Application &ctrl, SDL_Surface *screen) {
34         timer = GraphicsTimers().StartCountdown(2500);
35 }
36
37 void RunState::PauseState(Application &ctrl, SDL_Surface *screen) {
38
39 }
40
41
42 void RunState::Resize(int width, int height) {
43
44 }
45
46
47 void RunState::HandleEvents(const Input &input) {
48         if (timer.Finished()) {
49                 battle->SetRunaway();
50                 ctrl->PopState(); // pop self
51         }
52 }
53
54
55 void RunState::UpdateWorld(float deltaT) {
56
57 }
58
59 void RunState::Render(SDL_Surface *screen) {
60         Vector<int> offset(battle->CalculateScreenOffset(screen));
61         battle->RenderBackground(screen, offset);
62         battle->RenderMonsters(screen, offset);
63         battle->RenderHeroes(screen, offset);
64         battle->RenderSmallHeroTags(screen, offset);
65         RenderTitleBar(screen, offset);
66 }
67
68 void RunState::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
69         int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
70         battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
71
72         Vector<int> textPosition(
73                         (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2,
74                         battle->Res().titleFrame->BorderHeight());
75         battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset);
76 }
77
78 }