#include "../common/GameState.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
+#include "../math/Vector.h"
using app::Input;
using common::Capsule;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
void CapsuleFeedMenu::OnEnterState(SDL_Surface *) {
menu.SetSelected();
+ menu.StartAnimation(Ctrl());
itemMenu.SetActive();
+ itemMenu.StartAnimation(Ctrl());
}
void CapsuleFeedMenu::LoadInventory() {
} 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::UpdateWorld(float deltaT) {
+void CapsuleFeedMenu::FeedSelected() {
+ if (itemMenu.Selected()) {
+ // TODO: feed and grow animations
+ if (GetCapsule().IsHungry()) {
+ GetCapsule().Feed(itemMenu.Selected());
+ parent->Game().state->inventory.Remove(itemMenu.Selected(), 1);
+ LoadInventory();
+ } else if (itemMenu.Selected() == GetCapsule().UpgradeItem()) {
+ GetCapsule().UpgradeSpecial();
+ parent->Game().state->inventory.Remove(itemMenu.Selected(), 1);
+ LoadInventory();
+ } else {
+ // error beep
+ }
+ } else {
+ // also beep
+ }
+}
+
+
+void CapsuleFeedMenu::UpdateWorld(Uint32 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();
}