X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FRunState.cpp;h=f49f36fa0336b9a8e421884085135860f2b56b27;hb=42fea5412a4423e827aac36465b2d9a38968390e;hp=7fdc0665c82b6bd09bc64fa2c31d033ae728ad8c;hpb=923422e6a71f57b8fa24b826d1e2914faa144081;p=l2e.git diff --git a/src/battle/states/RunState.cpp b/src/battle/states/RunState.cpp index 7fdc066..f49f36f 100644 --- a/src/battle/states/RunState.cpp +++ b/src/battle/states/RunState.cpp @@ -1,17 +1,9 @@ -/* - * RunState.cpp - * - * Created on: Aug 10, 2012 - * Author: holy - */ - #include "RunState.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" -#include "../../geometry/operators.h" -#include "../../geometry/Point.h" +#include "../../math/Vector.h" #include "../../graphics/Font.h" #include "../../graphics/Frame.h" @@ -19,63 +11,70 @@ using app::Application; using app::Input; -using geometry::Point; -using geometry::Vector; +using graphics::Font; +using graphics::Frame; +using math::Vector; +using std::strlen; namespace battle { -void RunState::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; - // TODO: push battle animation if enemy is faster +void RunState::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); } -void RunState::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void RunState::OnExitState(SDL_Surface *screen) { + } -void RunState::ResumeState(Application &ctrl, SDL_Surface *screen) { +void RunState::OnResumeState(SDL_Surface *screen) { timer = GraphicsTimers().StartCountdown(2500); } -void RunState::PauseState(Application &ctrl, SDL_Surface *screen) { +void RunState::OnPauseState(SDL_Surface *screen) { } -void RunState::Resize(int width, int height) { +void RunState::OnResize(int width, int height) { + const Resources &res = battle->Res(); + const Frame &frame = *res.titleFrame; + const Font &font = *res.titleFont; + framePosition = battle->ScreenOffset(); + frameSize = Vector ( + battle->Width(), + frame.BorderHeight() * 2 + font.CharHeight()); + + textPosition = Vector( + (battle->Width() - strlen(res.escapeText) * font.CharWidth()) / 2, + frame.BorderHeight()); } void RunState::HandleEvents(const Input &input) { if (timer.Finished()) { - ctrl->PopState(); // pop self - ctrl->PopState(); // pop battle + battle->SetRunaway(); + Ctrl().PopState(); // pop self } } -void RunState::UpdateWorld(float deltaT) { +void RunState::UpdateWorld(Uint32 deltaT) { } void RunState::Render(SDL_Surface *screen) { - Vector offset(battle->CalculateScreenOffset(screen)); - battle->RenderBackground(screen, offset); - battle->RenderMonsters(screen, offset); - battle->RenderHeroes(screen, offset); - // render small tags - RenderTitleBar(screen, offset); + battle->RenderBackground(screen); + battle->RenderMonsters(screen); + battle->RenderHeroes(screen); + battle->RenderSmallHeroTags(screen); + RenderTitleBar(screen); } -void RunState::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { - int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->BackgroundWidth(), height); - - Point textPosition( - (battle->BackgroundWidth() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2, - battle->Res().titleFrame->BorderHeight()); - battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset); +void RunState::RenderTitleBar(SDL_Surface *screen) { + const Resources &res = battle->Res(); + res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y()); + res.titleFont->DrawString(res.escapeText, screen, textPosition); } }