From: Daniel Karbach Date: Sun, 2 Dec 2012 16:49:17 +0000 (+0100) Subject: added capsule mockup (battle) X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=e1edc92c4fb834c8061118e89c0d7e239742b030;p=l2e.git added capsule mockup (battle) --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 36b4af5..9830e8c 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -47,6 +47,10 @@ void BattleState::AddHero(const Hero &h) { ++numHeroes; } +void BattleState::SetCapsule(const Capsule &c) { + capsule = c; +} + void BattleState::NextHero() { ++activeHero; while (activeHero < numHeroes && heroes[activeHero].Health() == 0) { @@ -83,6 +87,8 @@ void BattleState::OnEnterState(SDL_Surface *screen) { smallHeroTags[i] = SmallHeroTag(this, i); } + capsule.Position() = heroesLayout->CalculatePosition(4, background->w, background->h); + for (int i(0); i < int(monsters.size()); ++i) { monsters[i].Position() = monstersLayout->CalculatePosition(i, background->w, background->h); } @@ -394,6 +400,15 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { } } +void BattleState::RenderCapsule(SDL_Surface *screen, const Vector &offset) { + if (capsule.Health() <= 0) return; + if (capsule.GetAnimation().Running()) { + capsule.GetAnimation().DrawCenter(screen, capsule.Position() + offset); + } else { + capsule.Sprite()->DrawCenter(screen, capsule.Position() + offset); + } +} + void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) { assert(screen); int tagHeight(attackTypeMenu.Height()); diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 0f51f23..3a9500c 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -3,6 +3,7 @@ #include "fwd.h" #include "AttackTypeMenu.h" +#include "Capsule.h" #include "Hero.h" #include "HeroTag.h" #include "Monster.h" @@ -47,6 +48,7 @@ public: public: void AddMonster(const Monster &); void AddHero(const Hero &); + void SetCapsule(const Capsule &); public: virtual void HandleEvents(const app::Input &); @@ -120,6 +122,7 @@ public: void RenderBackground(SDL_Surface *screen, const geometry::Vector &offset); void RenderMonsters(SDL_Surface *screen, const geometry::Vector &offset); void RenderHeroes(SDL_Surface *screen, const geometry::Vector &offset); + void RenderCapsule(SDL_Surface *screen, const geometry::Vector &offset); void RenderHeroTags(SDL_Surface *screen, const geometry::Vector &offset); void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector &offset); @@ -154,6 +157,7 @@ private: SmallHeroTag smallHeroTags[4]; geometry::Vector heroTagPositions[4]; geometry::Vector smallHeroTagPositions[4]; + Capsule capsule; int numHeroes; int activeHero; int attackCursor; diff --git a/src/battle/Capsule.cpp b/src/battle/Capsule.cpp new file mode 100644 index 0000000..709ef3b --- /dev/null +++ b/src/battle/Capsule.cpp @@ -0,0 +1,31 @@ +#include "Capsule.h" + +namespace battle { + +Capsule::Capsule() +: name(0) + +, maxHealth(0) +, health(0) +, maxMana(0) +, mana(0) + +, level(0) + +, battleSprite(0) +, meleeAnimation(0) +, attackAnimation(0) +, spellAnimation(0) { + +} + + +void Capsule::SubtractHealth(int amount) { + if (amount > health) { + health = 0; + } else { + health -= amount; + } +} + +} diff --git a/src/battle/Capsule.h b/src/battle/Capsule.h new file mode 100644 index 0000000..c16196c --- /dev/null +++ b/src/battle/Capsule.h @@ -0,0 +1,87 @@ +#ifndef BATTLE_CAPSULE_H_ +#define BATTLE_CAPSULE_H_ + +#include "AttackChoice.h" +#include "../common/fwd.h" +#include "../common/Stats.h" +#include "../geometry/Vector.h" +#include "../graphics/Animation.h" +#include "../graphics/fwd.h" +#include "../graphics/Menu.h" + +#include +#include + +namespace battle { + +class Capsule { + +public: + Capsule(); + +public: + const char *Name() const { return name; } + Uint8 Level() const { return level; } + const graphics::Sprite *Sprite() const { return battleSprite; } + + Uint16 MaxHealth() const { return maxHealth; } + Uint16 Health() const { return health; } + int RelativeHealth(int max) const { return Health() * max / MaxHealth(); } + void SubtractHealth(int amount); + + Uint16 MaxMana() const { return maxMana; } + Uint16 Mana() const { return mana; } + int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); } + bool CanUseMagic() const { return MaxMana() > 0; } + + common::Stats &GetStats() { return stats; } + const common::Stats &GetStats() const { return stats; } + + graphics::AnimationRunner &GetAnimation() { return animation; } + const graphics::AnimationRunner &GetAnimation() const { return animation; } + void SetAnimation(const graphics::AnimationRunner &a) { animation = a; } + + const graphics::Animation *MeleeAnimation() const { return meleeAnimation; } + const graphics::Animation *AttackAnimation() const { return attackAnimation; } + const graphics::Animation *SpellAnimation() const { return spellAnimation; } + + geometry::Vector &Position() { return position; } + const geometry::Vector &Position() const { return position; } + + AttackChoice &GetAttackChoice() { return attackChoice; } + const AttackChoice &GetAttackChoice() const { return attackChoice; } + +// temporary setters +public: + void SetName(const char *n) { name = n; } + void SetHealth(int max, int cur) { maxHealth = max; health = cur; } + void SetMana(int max, int cur) { maxMana = max; mana = cur; } + void SetLevel(int l) { level = l; } + void SetBattleSprite(graphics::Sprite *s) { battleSprite = s; } + void SetMeleeAnimation(graphics::Animation *a) { meleeAnimation = a; } + void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; } + void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; } + +private: + const char *name; + + int maxHealth, health; + int maxMana, mana; + + int level; + + graphics::Sprite *battleSprite; + graphics::Animation *meleeAnimation; + graphics::Animation *attackAnimation; + graphics::Animation *spellAnimation; + + graphics::AnimationRunner animation; + geometry::Vector position; + AttackChoice attackChoice; + common::Stats stats; + +}; + +} + +#endif /* BATTLE_CAPSULE_H_ */ diff --git a/src/battle/fwd.h b/src/battle/fwd.h index 73827d8..959b856 100644 --- a/src/battle/fwd.h +++ b/src/battle/fwd.h @@ -6,6 +6,7 @@ namespace battle { class AttackChoice; class AttackTypeMenu; class BattleState; +class Capsule; class Hero; class HeroTag; class Monster; diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 665756f..fac7cdf 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -10,6 +10,7 @@ #include "../BattleState.h" #include "../Hero.h" #include "../Monster.h" +#include "../TargetSelection.h" #include "../../app/Application.h" #include "../../app/Input.h" #include "../../common/Ikari.h" @@ -216,6 +217,7 @@ void PerformAttacks::Render(SDL_Surface *screen) { battle->RenderBackground(screen, offset); battle->RenderMonsters(screen, offset); battle->RenderHeroes(screen, offset); + battle->RenderCapsule(screen, offset); battle->RenderSmallHeroTags(screen, offset); RenderTitleBar(screen, offset); RenderNumbers(screen, offset); diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h index 06ce1b8..b862369 100644 --- a/src/battle/states/PerformAttacks.h +++ b/src/battle/states/PerformAttacks.h @@ -10,7 +10,6 @@ #include "../../app/State.h" -#include "../BattleState.h" #include "../NumberAnimation.h" #include "../../geometry/Vector.h" #include "../../graphics/Animation.h" @@ -19,6 +18,9 @@ namespace battle { +class BattleState; +class TargetSelection; + class PerformAttacks : public app::State { diff --git a/src/main.cpp b/src/main.cpp index 31724d5..5934833 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "app/Arguments.h" #include "app/Input.h" #include "battle/BattleState.h" +#include "battle/Capsule.h" #include "battle/Hero.h" #include "battle/Monster.h" #include "battle/PartyLayout.h" @@ -53,6 +54,7 @@ using app::Application; using app::Arguments; using app::Input; using battle::BattleState; +using battle::Capsule; using battle::Monster; using battle::PartyLayout; using common::GameConfig; @@ -282,11 +284,18 @@ int main(int argc, char **argv) { app::State *state(0); if (battle) { + graphics::Sprite flashSprite(IMG_Load("test-data/flash.png"), 96, 96); + Capsule capsule; + capsule.SetName("Flash"); + capsule.SetHealth(13, 13); + capsule.SetBattleSprite(&flashSprite); + BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout)); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); + battleState->SetCapsule(capsule); battleState->AddHero(gameState.heroes[0]); battleState->AddHero(gameState.heroes[1]); battleState->AddHero(gameState.heroes[2]); diff --git a/test-data/flash.png b/test-data/flash.png new file mode 100644 index 0000000..298ff83 Binary files /dev/null and b/test-data/flash.png differ diff --git a/test-data/test.l2s b/test-data/test.l2s index 8491b37..616249a 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -20,7 +20,8 @@ export PartyLayout heroesLayout { < 48,136>, <128,136>, < 80,152>, - <160,152> + <160,152>, + <216,144> ] }