}
+int Capsule::HungerEmpty() const {
+ return HungerTotal() - HungerFull();
+}
+
+int Capsule::HungerTotal() const {
+ return GetClass().hunger;
+}
+
+int Capsule::HungerFull() const {
+ return GetClass().hungerFull;
+}
+
+bool Capsule::IsHungry() const {
+ return HungerEmpty();
+}
+
+void Capsule::Feed(const common::Item *) {
+ // TODO: find out how to calculate an item's feed value
+ // TODO: an item the capsule favors (changes on every feed and after every
+ // battle) doubles the value
+ int value = 1;
+ GetClass().hungerFull += value;
+ if (GetClass().hungerFull >= GetClass().hunger) {
+ GetClass().hungerFull = GetClass().hunger;
+ UpgradeClass();
+ }
+}
+
+
Capsule::Class::Class()
: name(0)
, tribe(0)
, attackAnimation(0)
, spellAnimation(0)
+, hunger(32)
+, hungerFull(0)
+
, healthBoost(0) {
attacks[0] = 0;
attacks[1] = 0;
td.AddField("attackAnimation", FieldDescription(((char *)&c.attackAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
td.AddField("spellAnimation", FieldDescription(((char *)&c.spellAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
+ td.AddField("hunger", FieldDescription(((char *)&c.hunger) - ((char *)&c), Interpreter::NUMBER_ID));
+
td.AddField("healthBoost", FieldDescription(((char *)&c.healthBoost) - ((char *)&c), Interpreter::NUMBER_ID));
td.AddField("statBoost", FieldDescription(((char *)&c.statBoost) - ((char *)&c), Stats::TYPE_ID));
}
#ifndef COMMON_CAPSULE_H_
#define COMMON_CAPSULE_H_
+namespace common {
+ class Item;
+}
namespace graphics {
class Animation;
class Sprite;
int ClassIndex() const { return curClass; }
void SetClass(int index);
+ int HungerEmpty() const;
+ int HungerTotal() const;
+ int HungerFull() const;
+ bool IsHungry() const;
+ void Feed(const common::Item *);
+
Uint16 MaxHealth() const;
Stats GetStats() const;
graphics::Animation *attackAnimation;
graphics::Animation *spellAnimation;
+ int hunger;
+ int hungerFull;
+
int healthBoost;
Stats statBoost;
};
gameState.heroes[0].AddSpell(valorSpell);
gameState.heroes[1].AddSpell(valorSpell);
- gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
+ gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
gameState.inventory.Add(caster.GetItem("powerRingItem"));
gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
} else if (itemMenu.SelectedIndex() == itemMenu.SecondaryIndex()) {
switch (menu.Selected()) {
case CHOICE_SELECT:
- if (true /* can feed */) {
- // TODO: implement capsule feeding
- }
+ FeedSelected();
itemMenu.SetActive();
break;
case CHOICE_SORT:
}
}
+void CapsuleFeedMenu::FeedSelected() {
+ if (itemMenu.Selected()) {
+ // TODO: feed and grow animations
+ GetCapsule().Feed(itemMenu.Selected());
+ parent->Game().state->inventory.Remove(itemMenu.Selected(), 1);
+ LoadInventory();
+ } else {
+ // beep
+ }
+}
+
+
void CapsuleFeedMenu::UpdateWorld(float deltaT) {
}
const Vector<int> spriteOffset(
3 * font.CharWidth() + font.CharWidth() * 3 / 4,
4 * font.CharHeight() + font.CharHeight() / 4);
+ const Vector<int> growthOffset(
+ 13 * font.CharWidth(),
+ 7 * font.CharHeight() + font.CharHeight() / 4);
const Vector<int> hungerOffset(
13 * font.CharWidth(),
9 * font.CharHeight() + font.CharHeight() / 8);
parent->RenderBackground(screen);
RenderName(screen, offset + nameOffset);
RenderSprite(screen, offset + spriteOffset);
+ if (GetCapsule().IsHungry()) {
+ RenderGrowth(screen, offset + growthOffset);
+ }
RenderHunger(screen, offset + hungerOffset);
RenderMenu(screen, offset + menuOffset);
RenderItems(screen, offset + itemsOffset);
GetCapsule().BattleSprite()->Draw(screen, offset);
}
+void CapsuleFeedMenu::RenderGrowth(SDL_Surface *screen, const Vector<int> &offset) const {
+ Vector<int> cursor(offset);
+ parent->Res().capsuleGrowthLabel->Draw(screen, offset);
+ cursor.X() += parent->Res().capsuleGrowthLabel->Width();
+
+ for (int i = 0; i < GetCapsule().HungerFull(); ++i) {
+ parent->Res().capsuleGrowthBarFilled->Draw(screen, cursor);
+ cursor.X() += parent->Res().capsuleGrowthBarFilled->Width();
+ }
+
+ for (int i = 0; i < GetCapsule().HungerEmpty(); ++i) {
+ parent->Res().capsuleGrowthBar->Draw(screen, cursor);
+ cursor.X() += parent->Res().capsuleGrowthBar->Width();
+ }
+}
+
void CapsuleFeedMenu::RenderHunger(SDL_Surface *screen, const Vector<int> &offset) const {
const Font &font(*parent->Res().normalFont);
const Frame &frame(*parent->Res().statusFrame);
return parent->Height();
}
+Capsule &CapsuleFeedMenu::GetCapsule() {
+ return parent->GetCapsule();
+}
+
const Capsule &CapsuleFeedMenu::GetCapsule() const {
return parent->GetCapsule();
}
virtual void OnResize(int width, int height);
+ common::Capsule &GetCapsule();
const common::Capsule &GetCapsule() const;
void LoadInventory();
+ void FeedSelected();
void RenderName(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
void RenderSprite(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderGrowth(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
void RenderHunger(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
void RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
, capsuleAlignmentWheel(0)
, capsuleAlignmentCursor(0)
+, capsuleGrowthLabel(0)
+, capsuleGrowthBar(0)
+, capsuleGrowthBarFilled(0)
+
{ }
td.AddField("capsuleAlignmentWheel", FieldDescription(((char *)&r.capsuleAlignmentWheel) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
td.AddField("capsuleAlignmentCursor", FieldDescription(((char *)&r.capsuleAlignmentCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+
+ td.AddField("capsuleGrowthLabel", FieldDescription(((char *)&r.capsuleGrowthLabel) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+ td.AddField("capsuleGrowthBar", FieldDescription(((char *)&r.capsuleGrowthBar) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+ td.AddField("capsuleGrowthBarFilled", FieldDescription(((char *)&r.capsuleGrowthBarFilled) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
}
void Resources::Construct(void *data) {
graphics::Sprite *capsuleAlignmentWheel;
graphics::Sprite *capsuleAlignmentCursor;
+ graphics::Sprite *capsuleGrowthLabel;
+ graphics::Sprite *capsuleGrowthBar;
+ graphics::Sprite *capsuleGrowthBarFilled;
+
Resources();
static void CreateTypeDescription();
{ column: 0, row: 0, disposition: < 0, -16> }
]
},
+ hunger: 0,
healthBoost: 208,
statBoost: Stats {
atp: 38,
image: :"capsule-sprites.png",
size: <32, 32>,
offset: <128, 128>
+ },
+ capsuleGrowthLabel: Sprite {
+ image: :"capsule-feed.png",
+ size: <32, 10>
+ },
+ capsuleGrowthBar: Sprite {
+ image: :"capsule-feed.png",
+ size: <8, 10>,
+ offset: <8, 10>
+ },
+ capsuleGrowthBarFilled: Sprite {
+ image: :"capsule-feed.png",
+ size: <8, 10>,
+ offset: <0, 10>
}
}