X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FBattleState.cpp;h=57ff3270d170daab546e8c51c461bcb6195b5ba3;hb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;hp=0171e1480f56a7d52b905a86e577525d0a2597a0;hpb=2255d436a0c2acc10b015827366a72b2ece86094;p=l2e.git diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 0171e14..57ff327 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -12,6 +12,7 @@ #include "../common/Spell.h" #include "../graphics/Frame.h" #include "../graphics/Sprite.h" +#include "../math/Vector.h" #include #include @@ -24,7 +25,7 @@ using common::Inventory; using common::Item; using common::Spell; using common::Stats; -using geometry::Vector; +using math::Vector; using graphics::Menu; using std::rand; @@ -72,7 +73,9 @@ void BattleState::SwapHeroes(int lhs, int rhs) { void BattleState::OnResize(int w, int h) { - + offset = Vector( + (w - background->w) / 2, + (h - background->h) / 2); } @@ -110,6 +113,8 @@ void BattleState::OnEnterState(SDL_Surface *screen) { smallHeroTagPositions[2] = Vector(xOffset + tagWidth, yOffset); smallHeroTagPositions[3] = Vector(xOffset + 3 * tagWidth, yOffset); + OnResize(screen->w, screen->h); + itemMenu = *res->itemMenuProperties; LoadInventory(); ClearAllAttacks(); @@ -192,7 +197,7 @@ void BattleState::CalculateAttackOrder() { attackOrder.push_back(Order(Order::MONSTER, i)); MonsterAt(i).GetAttackChoice() = AttackChoice(this); } - if (capsule.Health() > 0) { + if (capsule.Active() && capsule.Health() > 0) { attackOrder.push_back(Order(Order::CAPSULE)); } std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this)); @@ -210,7 +215,7 @@ void BattleState::NextAttack() { } else if (attackOrder[attackCursor].IsHero()) { if (HeroAt(attackOrder[attackCursor].index).Health() > 0) break; } else { - if (capsule.Health() > 0) break; + if (capsule.Active() && capsule.Health() > 0) break; } ++attackCursor; } @@ -389,18 +394,17 @@ void BattleState::HandleEvents(const Input &input) { } -void BattleState::UpdateWorld(float deltaT) { +void BattleState::UpdateWorld(Uint32 deltaT) { } void BattleState::Render(SDL_Surface *screen) { assert(screen); - Vector offset(CalculateScreenOffset(screen)); - RenderBackground(screen, offset); - RenderMonsters(screen, offset); + RenderBackground(screen); + RenderMonsters(screen); } -void BattleState::RenderBackground(SDL_Surface *screen, const Vector &offset) { +void BattleState::RenderBackground(SDL_Surface *screen) { assert(screen); // black for now SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); @@ -412,7 +416,7 @@ void BattleState::RenderBackground(SDL_Surface *screen, const Vector &offse SDL_BlitSurface(background, 0, screen, &destRect); } -void BattleState::RenderMonsters(SDL_Surface *screen, const Vector &offset) { +void BattleState::RenderMonsters(SDL_Surface *screen) { assert(screen); for (vector::size_type i(0), end(monsters.size()); i < end; ++i) { if (MonsterPositionOccupied(i)) { @@ -425,7 +429,7 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector &offset) } } -void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { +void BattleState::RenderHeroes(SDL_Surface *screen) { assert(screen); for (int i(0); i < numHeroes; ++i) { if (heroes[i].GetAnimation().Running()) { @@ -437,8 +441,8 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { } } -void BattleState::RenderCapsule(SDL_Surface *screen, const Vector &offset) { - if (capsule.Health() <= 0) return; +void BattleState::RenderCapsule(SDL_Surface *screen) { + if (!capsule.Active() || capsule.Health() <= 0) return; if (capsule.GetAnimation().Running()) { capsule.GetAnimation().DrawCenter(screen, capsule.Position() + offset); } else { @@ -446,7 +450,7 @@ void BattleState::RenderCapsule(SDL_Surface *screen, const Vector &offset) } } -void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) { +void BattleState::RenderHeroTags(SDL_Surface *screen) { assert(screen); int tagHeight(attackTypeMenu.Height()); int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2); @@ -456,7 +460,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) } } -void BattleState::RenderSmallHeroTags(SDL_Surface *screen, const Vector &offset) { +void BattleState::RenderSmallHeroTags(SDL_Surface *screen) { assert(screen); int tagHeight(res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2); int tagWidth(res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2);