Item list implementation

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent e6fe560810
commit 14002a3c14
  1. BIN
      C++ProjectTemplate
  2. 65
      main.cpp

Binary file not shown.

@ -165,6 +165,7 @@ public:
int POWER_SELECTION_CURSOR[4]={0,0,0,0};
int POWER_GRADE_CURSOR[4]={0,0,0,0};
int ITEM_SELECTION_CURSOR=0;
int ITEM_SELECTION_OFFSET=0;
int TARGET_SELECTION_CURSOR=0;
bool ANYKEYPRESSED=false;
bool ACTIONKEYPRESSED=false;
@ -258,9 +259,12 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
ModifyObject(0,ANIMATIONS["player.png"],{5,5},MAGENTA),
MoveCutsceneObject(1,{320,64},1),});
AddItemToPlayerInventory(ItemName::COOKIE);
AddItemToPlayerInventory(ItemName::COOKIE);
AddItemToPlayerInventory(ItemName::COOKIE);
for (int i=0;i<20;i++) {
AddItemToPlayerInventory(ItemName::COOKIE);
}
for (int i=0;i<8;i++) {
AddItemToPlayerInventory(ItemName::PIZZA);
}
AddItemToPlayerInventory(ItemName::CRACKED_BAT);
return true;
@ -683,6 +687,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
}break;
case 2:{ //Items selected.
BATTLE_STATE=BattleState::ITEM_SELECT;
ITEM_SELECTION_CURSOR=0;
}break;
case 3:{ //Defend selected.
//DisplayMessageBox("Not implemented yet.");
@ -956,23 +961,52 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
}break;
case BattleState::ITEM_SELECT:{
if (LeftPressed()||RightPressed()) {
if (LeftPressed()&&!(ITEM_SELECTION_CURSOR&1)) {
BATTLE_STATE=BattleState::SELECT_ACTION;
}
ITEM_SELECTION_CURSOR+=ITEM_SELECTION_CURSOR&1?-1:1;
if (ITEM_SELECTION_CURSOR>=PARTY_INVENTORY.size()) {
ITEM_SELECTION_CURSOR--;
}
}
if (UpPressed()) {
ITEM_SELECTION_CURSOR-=2;
if (ITEM_SELECTION_CURSOR<0) {
ITEM_SELECTION_CURSOR+=PARTY_INVENTORY.size();
if (PARTY_INVENTORY.size()&1) {
ITEM_SELECTION_CURSOR+=PARTY_INVENTORY.size()+1;
if (ITEM_SELECTION_CURSOR>=PARTY_INVENTORY.size()) {
ITEM_SELECTION_CURSOR-=2;
}
ITEM_SELECTION_OFFSET=std::clamp((int)PARTY_INVENTORY.size()/2*2-18+2,0,(int)PARTY_INVENTORY.size()-1);
} else {
ITEM_SELECTION_CURSOR+=PARTY_INVENTORY.size();
ITEM_SELECTION_OFFSET=std::clamp((int)PARTY_INVENTORY.size()/2*2-18,0,(int)PARTY_INVENTORY.size()-1);
}
}
if (ITEM_SELECTION_CURSOR<ITEM_SELECTION_OFFSET) {
ITEM_SELECTION_OFFSET=ITEM_SELECTION_CURSOR/2*2;
}
}
if (DownPressed()) {
ITEM_SELECTION_CURSOR+=2;
if (ITEM_SELECTION_CURSOR<0) {
ITEM_SELECTION_CURSOR+=PARTY_INVENTORY.size();
if (ITEM_SELECTION_CURSOR>=PARTY_INVENTORY.size()) {
if (PARTY_INVENTORY.size()&1) {
if (ITEM_SELECTION_CURSOR&1) {
ITEM_SELECTION_CURSOR--;
} else {
ITEM_SELECTION_CURSOR-=PARTY_INVENTORY.size()+1;
}
} else {
ITEM_SELECTION_CURSOR-=PARTY_INVENTORY.size();
}
ITEM_SELECTION_OFFSET=0;
}
if (ITEM_SELECTION_CURSOR>=ITEM_SELECTION_OFFSET+18) {
ITEM_SELECTION_OFFSET=ITEM_SELECTION_CURSOR/2*2-16;
}
}
if (ITEM_SELECTION_CURSOR>=PARTY_INVENTORY.size()) {
ITEM_SELECTION_CURSOR=PARTY_INVENTORY.size()-1;
}
printf("%d %d\n",ITEM_SELECTION_OFFSET,ITEM_SELECTION_CURSOR);
}break;
}
}
@ -1311,8 +1345,19 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
}
if (BATTLE_STATE==BattleState::ITEM_SELECT) {
SetDrawTarget(layer::INTERFACE);
DrawDecal({static_cast<float>(8+ITEM_SELECTION_CURSOR*(WIDTH-8)/2),static_cast<float>(12*(POWER_SELECTION_CURSOR[-CURRENT_TURN-1]-POWER_SELECTION_OFFSET[-CURRENT_TURN-1])+8)},SPRITES["cursor.png"]);
DrawDecal({static_cast<float>(8+(ITEM_SELECTION_CURSOR)%2*(WIDTH-8)/2),static_cast<float>(12*((ITEM_SELECTION_CURSOR-ITEM_SELECTION_OFFSET)/2)+8)},SPRITES["cursor.png"]);
DrawDialogBox({4,4},{(int)(WIDTH-8),(int)(HEIGHT/2)},Pixel(70, 33, 105,128),Pixel(62, 54, 69,128),Pixel(185, 148, 255,128));
for (int i=0;i<18;i++) {
if (ITEM_SELECTION_OFFSET+i<PARTY_INVENTORY.size()) {
DrawStringDecal({static_cast<float>(16+i%2*(WIDTH-8)/2),static_cast<float>(12*(i/2)+8)},PARTY_INVENTORY[ITEM_SELECTION_OFFSET+i]->name);
}
}
if (ITEM_SELECTION_OFFSET>0) {
DrawRotatedDecal({WIDTH-20,8},SPRITES["cursor.png"],-M_PI_2,{4,4});
}
if (ITEM_SELECTION_OFFSET+18<PARTY_INVENTORY.size()) {
DrawRotatedDecal({WIDTH-20,4+HEIGHT/2-4},SPRITES["cursor.png"],M_PI_2,{4,4});
}
}
if (BATTLE_STATE==BattleState::TARGET_SELECT) {
SetDrawTarget(layer::GROUND);

Loading…
Cancel
Save