So i am working on an RPG game and currently i am working on potion items right now the only "Potion" i have is an apple. the apple is meant to heal 2 health for the player. and it does this. the player is only able to hold 5 potions at a time. so, as i am a beginner, i made a different item set for each potion item slot the player has.
The potions look like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void Potion1()
{
if(PotionItem1 == 0)
{
PotionName1 = "No Potion";
PotionHP1 = 0;
PotionSTEAM1 = 0;
}
else if(PotionItem1 == 1)
{
PotionName1 = "Apple";
PotionHP1 = 2;
PotionSTEAM1 = 0;
}
}
|
and when the player gets a potion it looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
cout << "Bla bla bla description of an apple tree that you dont care about" << endl;
cout << "Would you like to take an apple?" << endl;
cout << "(1 = Yes, 2 = No) ";
cin >> F;
if(F == 1)
{
if(POTION1 == 0)
{
POTION1 = 1;
PotionItem1 = 1;
Potion1();
}
else if(POTION2 == 0)
{
POTION2 = 1;
PotionItem2 = 1;
Potion2();
}
else if(POTION3 == 0)
{
POTION3 = 1;
PotionItem3 = 1;
Potion3();
}
else if(POTION4 == 0)
{
POTION4 = 1;
PotionItem4 = 1;
Potion4();
}
else if(POTION5 == 0)
{
POTION5 = 1;
PotionItem5 = 1;
Potion5();
}
}
|
and to view the item in the players inventory, and use the potion i have this
the game is a steam punk. thus the steam aspect of the potions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
if(POTION1 > 0)
{
cout << "Potion: " << PotionName1 << endl << endl;
cout << "Health: +" << PotionHP1 << endl;
cout << "Steam: +" << PotionSTEAM1 << endl << endl;
}
if(POTION2 > 0)
{
cout << "Potion: " << PotionName2 << endl << endl;
cout << "Health: +" << PotionHP2 << endl;
cout << "Steam: +" << PotionSTEAM2 << endl << endl;
}
if(POTION3 > 0)
{
cout << "Potion: " << PotionName3 << endl << endl;
cout << "Health: +" << PotionHP3 << endl;
cout << "Steam: +" << PotionSTEAM3 << endl << endl;
}
if(POTION4 > 0)
{
cout << "Potion: " << PotionName4 << endl << endl;
cout << "Health: +" << PotionHP4 << endl;
cout << "Steam: +" << PotionSTEAM4 << endl << endl;
}
if(POTION5 > 0)
{
cout << "Potion: " << PotionName5 << endl << endl;
cout << "Health: +" << PotionHP5 << endl;
cout << "Steam: +" << PotionSTEAM5 << endl << endl;
}
if(POTION1 > 0)
{
cout << "Would you like to use a potion?" << endl;
cout << "(1 = Yes, 2 = No) ";
int UsePotion;
cin >> UsePotion;
if(POTION5 >=1 && UsePotion == 1)
{
HP = HP + PotionHP5;
cout << "Health increased by: " << PotionHP1 << endl;
cout << "Steam increased by: " << PotionSTEAM1 << endl;
PotionItem5 = 0;
Potion5();
if(HP > MaxHP)
{
HP = MaxHP;
}
}
else if(POTION4 >=1 && UsePotion == 1)
{
HP = HP + PotionHP4;
cout << "Health increased by: " << PotionHP1 << endl;
cout << "Steam increased by: " << PotionSTEAM1 << endl;
PotionItem4 = 0;
Potion4();
if(HP > MaxHP)
{
HP = MaxHP;
}
}
else if(POTION3 >=1 && UsePotion == 1)
{
HP = HP + PotionHP3;
cout << "Health increased by: " << PotionHP1 << endl;
cout << "Steam increased by: " << PotionSTEAM1 << endl;
PotionItem3 = 0;
Potion3();
if(HP > MaxHP)
{
HP = MaxHP;
}
}
else if(POTION2 >=1 && UsePotion == 1)
{
HP = HP + PotionHP2;
cout << "Health increased by: " << PotionHP1 << endl;
cout << "Steam increased by: " << PotionSTEAM1 << endl;
PotionItem2 = 0;
Potion2();
if(HP > MaxHP)
{
HP = MaxHP;
}
}
else if(POTION1 >=1 && UsePotion == 1)
{
HP = HP + PotionHP1;
cout << "Health increased by: " << PotionHP1 << endl;
cout << "Steam increased by: " << PotionSTEAM1 << endl;
PotionItem1 = 0;
Potion1();
if(HP > MaxHP)
{
HP = MaxHP;
}
}
}
|
Now the problem i am having is that when the potion is used, it does heal the player as it should, and it is replaced with the No Item placeholder as it should. but when i go back into the world and pick up another apple from the tree, it does not replace the No Item place holder as it should, it leaves the no item and puts the new potion into the next available potion item slot.