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