summaryrefslogtreecommitdiff
path: root/src/koopatlas/shop.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2013-02-28 05:50:43 +0100
committerTreeki <treeki@gmail.com>2013-02-28 05:50:43 +0100
commitd991dd0b82c3ecb5ed90b1d52be02dc46d8553bc (patch)
tree61e3e192aff0212d1c8067c2d4428a3c46687452 /src/koopatlas/shop.cpp
parent423c46c008361a31d949b213673daacc9edb2818 (diff)
downloadkamek-d991dd0b82c3ecb5ed90b1d52be02dc46d8553bc.tar.gz
kamek-d991dd0b82c3ecb5ed90b1d52be02dc46d8553bc.zip
count down spent coins in the shop
Diffstat (limited to '')
-rw-r--r--src/koopatlas/shop.cpp106
1 files changed, 87 insertions, 19 deletions
diff --git a/src/koopatlas/shop.cpp b/src/koopatlas/shop.cpp
index 27f6077..c8bbdca 100644
--- a/src/koopatlas/shop.cpp
+++ b/src/koopatlas/shop.cpp
@@ -3,6 +3,7 @@
CREATE_STATE(dWMShop_c, Hidden);
CREATE_STATE(dWMShop_c, ShowWait);
CREATE_STATE(dWMShop_c, ButtonActivateWait);
+CREATE_STATE(dWMShop_c, CoinCountdown);
CREATE_STATE(dWMShop_c, Wait);
CREATE_STATE(dWMShop_c, HideWait);
@@ -149,21 +150,24 @@ int dWMShop_c::onCreate() {
"shop_Show.brlan",
"shop_Hide.brlan",
"shop_ActivateButton.brlan",
- "shop_DeactivateButton.brlan"
+ "shop_DeactivateButton.brlan",
+ "shop_CountCoin.brlan"
};
static const char *groupNames[] = {
"BaseGroup", "BaseGroup",
"GBtn00", "GBtn01", "GBtn02", "GBtn03", "GBtn1", "GBtn2",
"GBtn00", "GBtn01", "GBtn02", "GBtn03", "GBtn1", "GBtn2",
+ "GCoinCount"
};
static const int brlanIDs[] = {
0, 1,
2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3,
+ 4,
};
- layout.loadAnimations(brlanNames, 4);
- layout.loadGroups(groupNames, brlanIDs, 14);
+ layout.loadAnimations(brlanNames, 5);
+ layout.loadGroups(groupNames, brlanIDs, 15);
layout.disableAllAnimations();
layout.drawOrder = 1;
@@ -301,7 +305,10 @@ void dWMShop_c::executeState_ShowWait() {
state.setState(&StateID_ButtonActivateWait);
}
}
-void dWMShop_c::endState_ShowWait() { }
+void dWMShop_c::endState_ShowWait() {
+ MapSoundPlayer(SoundRelatedClass, SE_OBJ_CLOUD_BLOCK_TO_JUGEM, 1);
+ timer = 1;
+}
// ButtonActivateWait
void dWMShop_c::beginState_ButtonActivateWait() { }
@@ -309,12 +316,12 @@ void dWMShop_c::executeState_ButtonActivateWait() {
if (!layout.isAnyAnimOn())
state.setState(&StateID_Wait);
}
-void dWMShop_c::endState_ButtonActivateWait() {
- UpdateSelectCursor(Buttons[0], 0, false);
-}
+void dWMShop_c::endState_ButtonActivateWait() { }
// Wait
-void dWMShop_c::beginState_Wait() { timer = 1; MapSoundPlayer(SoundRelatedClass, SE_OBJ_CLOUD_BLOCK_TO_JUGEM, 1); }
+void dWMShop_c::beginState_Wait() {
+ showSelectCursor();
+}
void dWMShop_c::executeState_Wait() {
if (timer < 90) {
scaleEase = -((cos(timer * 3.14 /20)-0.9)/timer*10)+1;
@@ -365,15 +372,12 @@ void dWMShop_c::executeState_Wait() {
layout.enableNonLoopAnim(DEACTIVATE_BUTTON+selected);
layout.enableNonLoopAnim(ACTIVATE_BUTTON+newSelection);
- switch (newSelection) {
- case 4: UpdateSelectCursor(Btn1Base, 0, false); break;
- case 5: UpdateSelectCursor(Btn2Base, 0, false); break;
- default: UpdateSelectCursor(Buttons[newSelection], 0, false);
- }
selected = newSelection;
if (newSelection <= 3)
lastTopRowChoice = newSelection;
+
+ showSelectCursor();
}
}
void dWMShop_c::endState_Wait() { }
@@ -585,7 +589,7 @@ void dWMShop_c::buyItem(int item) {
SaveFile *file = GetSaveFile();
SaveBlock *block = file->GetBlock(file->header.current_file);
- block->spentStarCoins += cost;
+ coinsRemaining = cost;
// Work out what we need to apply
int appliedItems[ITEM_TYPE_COUNT];
@@ -596,7 +600,6 @@ void dWMShop_c::buyItem(int item) {
for (int i = 0; i < invCount; i++)
appliedItems[(int)Inventory[shopKind][invStartIndex+i]]++;
- // TODO: Make this work with hammers
for (int i = 0; i < 8; i++) {
block->powerups_available[i] += appliedItems[i];
@@ -616,9 +619,74 @@ void dWMShop_c::buyItem(int item) {
if (appliedItems[(int)ONE_UP] > 0)
MapSoundPlayer(SoundRelatedClass, SE_SYS_100COIN_ONE_UP, 1);
- // load the coin count
- int scCount = getUnspentStarCoinCount();
- WriteNumberToTextBox(&scCount, CoinCount, false);
- WriteNumberToTextBox(&scCount, CoinCountShadow, false);
+ state.setState(&StateID_CoinCountdown);
+ HideSelectCursor(SelectCursorPointer, 0);
+}
+
+
+void dWMShop_c::beginState_CoinCountdown() {
+ timerForCoinCountdown = 8;
+}
+
+void dWMShop_c::endState_CoinCountdown() { }
+
+void dWMShop_c::executeState_CoinCountdown() {
+ timerForCoinCountdown--;
+ if (timerForCoinCountdown <= 0) {
+
+ SaveBlock *save = GetSaveFile()->GetBlock(-1);
+ save->spentStarCoins++;
+
+ // load the coin count
+ int scCount = getUnspentStarCoinCount();
+ WriteNumberToTextBox(&scCount, CoinCount, false);
+ WriteNumberToTextBox(&scCount, CoinCountShadow, false);
+
+ layout.enableNonLoopAnim(COUNT_COIN);
+ VEC3 efPos = {
+ CoinCount->effectiveMtx[0][3],
+ CoinCount->effectiveMtx[1][3],
+ 0.0f};
+
+ // ARGHHHHHHHHHHHHHHHHh.
+ if (IsWideScreen()) {
+ float div = 5.0f;
+ if (scCount < 100)
+ div = 3.6f;
+ if (scCount < 10)
+ div = 2.7f;
+ efPos.x -= (CoinCount->size.x / div);
+ efPos.y -= (CoinCount->size.y / 2.0f);
+ } else {
+ float div = 5.8f;
+ if (scCount < 100)
+ div = 8.2f;
+ if (scCount < 10)
+ div = 14.5f;
+ efPos.x += (CoinCount->size.x / div);
+ efPos.y -= (CoinCount->size.y / 2.8f);
+ }
+
+ VEC3 efScale = {0.7f, 0.7f, 0.7f};
+ SpawnEffect("Wm_2d_moviecoinvanish", 0, &efPos, 0, &efScale);
+
+ coinsRemaining--;
+ if (coinsRemaining <= 0) {
+ MapSoundPlayer(SoundRelatedClass, SE_PLY_GET_ITEM_AGAIN, 1);
+ state.setState(&StateID_Wait);
+ } else {
+ MapSoundPlayer(SoundRelatedClass, SE_SYS_STAR_COIN_PAY, 1);
+ beginState_CoinCountdown();
+ }
+ }
+}
+
+
+void dWMShop_c::showSelectCursor() {
+ switch (selected) {
+ case 4: UpdateSelectCursor(Btn1Base, 0, false); break;
+ case 5: UpdateSelectCursor(Btn2Base, 0, false); break;
+ default: UpdateSelectCursor(Buttons[selected], 0, false);
+ }
}