]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/RunState.cpp
cached some of the battle coordinates
[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 math::Vector;
15
16 namespace battle {
17
18 void RunState::OnEnterState(SDL_Surface *screen) {
19         OnResize(screen->w, screen->h);
20 }
21
22 void RunState::OnExitState(SDL_Surface *screen) {
23
24 }
25
26 void RunState::OnResumeState(SDL_Surface *screen) {
27         timer = GraphicsTimers().StartCountdown(2500);
28 }
29
30 void RunState::OnPauseState(SDL_Surface *screen) {
31
32 }
33
34
35 void RunState::OnResize(int width, int height) {
36         framePosition = battle->ScreenOffset();
37         frameSize = Vector<int> (
38                         battle->Width(),
39                         battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
40
41         textPosition = Vector<int>(
42                         (battle->Width() - std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth()) / 2,
43                         battle->Res().titleFrame->BorderHeight());
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(Uint32 deltaT) {
56
57 }
58
59 void RunState::Render(SDL_Surface *screen) {
60         battle->RenderBackground(screen);
61         battle->RenderMonsters(screen);
62         battle->RenderHeroes(screen);
63         battle->RenderSmallHeroTags(screen);
64         RenderTitleBar(screen);
65 }
66
67 void RunState::RenderTitleBar(SDL_Surface *screen) {
68 const Resources &res = battle->Res();
69         res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
70         res.titleFont->DrawString(res.escapeText, screen, textPosition);
71 }
72
73 }