Fix centering of camera and a bug that occurs when unequipping items from the equip menu while the inventory cursor is hovering over the last inventory item slot

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent c9be7c5c6a
commit 42a1b53592
  1. BIN
      C++ProjectTemplate
  2. 1
      SeasonI.h
  3. 5
      entity.h
  4. 16
      main.cpp

Binary file not shown.

@ -136,6 +136,7 @@ class SeasonI:public PixelGameEngine{
float ReadFloatFromStream(std::ifstream&f); float ReadFloatFromStream(std::ifstream&f);
double ReadDoubleFromStream(std::ifstream&f); double ReadDoubleFromStream(std::ifstream&f);
std::string ReadStringFromStream(std::ifstream&f); std::string ReadStringFromStream(std::ifstream&f);
void CenterCameraOnPlayer();
}; };
extern SeasonI*GAME; extern SeasonI*GAME;
#endif #endif

@ -267,6 +267,7 @@ class Entity{
//Will automatically swap items with current equipment so no need to call remove first. //Will automatically swap items with current equipment so no need to call remove first.
void EquipItem(int index) { void EquipItem(int index) {
int prevPartyInvenSize=PARTY_INVENTORY.size();
Item*equip=nullptr; Item*equip=nullptr;
if (isPlayer) { if (isPlayer) {
equip=PARTY_INVENTORY[index]; equip=PARTY_INVENTORY[index];
@ -291,6 +292,10 @@ class Entity{
RemoveEquip(CurrentEquip->stats.equip,index); RemoveEquip(CurrentEquip->stats.equip,index);
} }
equipment[equip->stats.equip]=equip; equipment[equip->stats.equip]=equip;
if (ITEM_SELECTION_CURSOR>=PARTY_INVENTORY.size()&&prevPartyInvenSize&1&&PARTY_INVENTORY.size()==prevPartyInvenSize-1) {
ITEM_SELECTION_OFFSET-=2;
}
ITEM_SELECTION_CURSOR=std::clamp(ITEM_SELECTION_CURSOR,0,(int)PARTY_INVENTORY.size()-1);
} }
}; };
#endif #endif

@ -478,7 +478,7 @@ void SeasonI::SetupAnimations() {
} }
void SeasonI::SetupObjectInfo() { void SeasonI::SetupObjectInfo() {
CreateObjectInfo(new NPC_Obj(PLAYER,"player",{0,0},nullptr,{2,2},WHITE,16),"player.png",{32,32}); CreateObjectInfo(new NPC_Obj(PLAYER,"player",{0,0},nullptr,{1,1},WHITE,16),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(NESS,"Ness",{0,0},nullptr,{1,1},YELLOW,14),"player.png",{32,32}); CreateObjectInfo(new NPC_Obj(NESS,"Ness",{0,0},nullptr,{1,1},YELLOW,14),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(PAULA,"Paula",{0,0},nullptr,{1,1},MAGENTA,13),"player.png",{32,32}); CreateObjectInfo(new NPC_Obj(PAULA,"Paula",{0,0},nullptr,{1,1},MAGENTA,13),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(JEFF,"Jeff",{0,0},nullptr,{1,1},DARK_GREEN,15),"player.png",{32,32}); CreateObjectInfo(new NPC_Obj(JEFF,"Jeff",{0,0},nullptr,{1,1},DARK_GREEN,15),"player.png",{32,32});
@ -1378,8 +1378,7 @@ void SeasonI::updateGame(){
} }
} }
if (moved) { if (moved) {
const vi2d cameraOffset={WIDTH/2,HEIGHT/2}; CenterCameraOnPlayer();
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()+PARTY_MEMBER_OBJ[0]->originPoint/2-cameraOffset;
} }
if (moved&&BATTLE_ENCOUNTER==nullptr) { if (moved&&BATTLE_ENCOUNTER==nullptr) {
for (int i=0;i<CURRENT_MAP->encounters.size();i++) { for (int i=0;i<CURRENT_MAP->encounters.size();i++) {
@ -3929,14 +3928,12 @@ void SeasonI::HandleCutscenes() {
for (int i=0;i<PARTY_MEMBER_COUNT;i++) { for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(pos); PARTY_MEMBER_OBJ[i]->SetPos(pos);
} }
const vi2d cameraOffset={WIDTH/2,HEIGHT/2}; CenterCameraOnPlayer();
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()-cameraOffset;
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
case ActionType::LOAD_FILE:{ case ActionType::LOAD_FILE:{
LoadGameSaveData(SAVE_FILE_CURSOR); LoadGameSaveData(SAVE_FILE_CURSOR);
const vi2d cameraOffset={WIDTH/2,HEIGHT/2}; CenterCameraOnPlayer();
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()+PARTY_MEMBER_OBJ[0]->originPoint/2-cameraOffset;
GAME_STATE=GameState::GAME_WORLD; GAME_STATE=GameState::GAME_WORLD;
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
@ -5387,6 +5384,11 @@ void SeasonI::LoadGameSaveData(int saveSlot) {
CHAPTER_NUMBER=ReadIntFromStream(file); CHAPTER_NUMBER=ReadIntFromStream(file);
} }
void SeasonI::CenterCameraOnPlayer(){
const vi2d cameraOffset={WIDTH/2,HEIGHT/2};
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()+PARTY_MEMBER_OBJ[0]->originPoint/2-cameraOffset;
}
#ifndef TEST_SUITE #ifndef TEST_SUITE
int main() int main()
{ {

Loading…
Cancel
Save