4 * Created on: Aug 10, 2012
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"
20 using app::Application;
22 using geometry::Point;
23 using geometry::Vector;
27 void RunState::EnterState(Application &c, SDL_Surface *screen) {
29 // TODO: push battle animation if enemy is faster
32 void RunState::ExitState(Application &c, SDL_Surface *screen) {
36 void RunState::ResumeState(Application &ctrl, SDL_Surface *screen) {
37 timer = GraphicsTimers().StartCountdown(2500);
40 void RunState::PauseState(Application &ctrl, SDL_Surface *screen) {
45 void RunState::Resize(int width, int height) {
50 void RunState::HandleEvents(const Input &input) {
51 if (timer.Finished()) {
53 ctrl->PopState(); // pop self
58 void RunState::UpdateWorld(float deltaT) {
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);
68 RenderTitleBar(screen, offset);
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->BackgroundWidth(), height);
75 Point<int> textPosition(
76 (battle->BackgroundWidth() - (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);