]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/RunState.cpp
relocate scripts
[l2e.git] / src / battle / states / RunState.cpp
1 #include "RunState.h"
2
3 #include "../BattleState.h"
4 #include "../../app/Application.h"
5 #include "../../app/Input.h"
6 #include "../../math/Vector.h"
7 #include "../../graphics/Font.h"
8 #include "../../graphics/Frame.h"
9
10 #include <cstring>
11
12 using app::Application;
13 using app::Input;
14 using graphics::Font;
15 using graphics::Frame;
16 using math::Vector;
17 using std::strlen;
18
19 namespace battle {
20
21 void RunState::OnEnterState(SDL_Surface *screen) {
22         OnResize(screen->w, screen->h);
23 }
24
25 void RunState::OnExitState(SDL_Surface *screen) {
26
27 }
28
29 void RunState::OnResumeState(SDL_Surface *screen) {
30         timer = GraphicsTimers().StartCountdown(2500);
31 }
32
33 void RunState::OnPauseState(SDL_Surface *screen) {
34
35 }
36
37
38 void RunState::OnResize(int width, int height) {
39         const Resources &res = battle->Res();
40         const Frame &frame = *res.titleFrame;
41         const Font &font = *res.titleFont;
42
43         framePosition = battle->ScreenOffset();
44         frameSize = Vector<int> (
45                         battle->Width(),
46                         frame.BorderHeight() * 2 + font.CharHeight());
47
48         textPosition = Vector<int>(
49                         (battle->Width() - strlen(res.escapeText) * font.CharWidth()) / 2,
50                         frame.BorderHeight());
51 }
52
53
54 void RunState::HandleEvents(const Input &input) {
55         if (timer.Finished()) {
56                 battle->SetRunaway();
57                 Ctrl().PopState(); // pop self
58         }
59 }
60
61
62 void RunState::UpdateWorld(Uint32 deltaT) {
63
64 }
65
66 void RunState::Render(SDL_Surface *screen) {
67         battle->RenderBackground(screen);
68         battle->RenderMonsters(screen);
69         battle->RenderHeroes(screen);
70         battle->RenderSmallHeroTags(screen);
71         RenderTitleBar(screen);
72 }
73
74 void RunState::RenderTitleBar(SDL_Surface *screen) {
75         const Resources &res = battle->Res();
76         res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
77         res.titleFont->DrawString(res.escapeText, screen, textPosition);
78 }
79
80 }