generated from sigonasr2/CPlusPlusProjectTemplate
Setup encounter detection
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
c102ef41a0
commit
34a3e916bc
Binary file not shown.
35
main.cpp
35
main.cpp
@ -267,6 +267,7 @@ class Entity{
|
|||||||
int damageReduction=0; //A percentage of how much damage to reduce.
|
int damageReduction=0; //A percentage of how much damage to reduce.
|
||||||
bool smart=false;
|
bool smart=false;
|
||||||
bool dumb=false;
|
bool dumb=false;
|
||||||
|
int atb=0; //When this value reaches 1000, it's this entity's turn.
|
||||||
Object* obj;
|
Object* obj;
|
||||||
std::vector<Battle::Move*> moveSet;
|
std::vector<Battle::Move*> moveSet;
|
||||||
//Used for initializing players.
|
//Used for initializing players.
|
||||||
@ -299,6 +300,18 @@ class Encounter{
|
|||||||
int id;
|
int id;
|
||||||
Encounter(int id,vd2d pos,std::array<vd2d,4> playerPos,std::vector<Entity*>objs,int chance=25)
|
Encounter(int id,vd2d pos,std::array<vd2d,4> playerPos,std::vector<Entity*>objs,int chance=25)
|
||||||
:id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){}
|
:id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){}
|
||||||
|
bool IsEncounterAlive() {
|
||||||
|
for (int i=0;i<objs.size();i++) {
|
||||||
|
if (objs[i]->HP>0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool IsInRange(vd2d pos) {
|
||||||
|
vd2d diff=pos-this->pos;
|
||||||
|
return diff.x>=0&&diff.x<=WIDTH&&diff.y>=0&&diff.y<=HEIGHT;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -369,6 +382,8 @@ public:
|
|||||||
int ENCOUNTER_OFFSET = 0;
|
int ENCOUNTER_OFFSET = 0;
|
||||||
std::vector<Encounter*>ENCOUNTER_LIST;
|
std::vector<Encounter*>ENCOUNTER_LIST;
|
||||||
Encounter*EDITING_ENCOUNTER=nullptr;
|
Encounter*EDITING_ENCOUNTER=nullptr;
|
||||||
|
Encounter*BATTLE_ENCOUNTER=nullptr;
|
||||||
|
int BATTLE_STATE=BattleState::MOVE_CAMERA;
|
||||||
|
|
||||||
|
|
||||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||||
@ -644,24 +659,42 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
}break;
|
}break;
|
||||||
case GameState::GAME_WORLD:{
|
case GameState::GAME_WORLD:{
|
||||||
if (PlayerCanMove()) {
|
if (PlayerCanMove()) {
|
||||||
|
bool moved=false;
|
||||||
if (UpHeld()) {
|
if (UpHeld()) {
|
||||||
if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) {
|
if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) {
|
||||||
UpdatePlayerTrail({0,-1});
|
UpdatePlayerTrail({0,-1});
|
||||||
|
moved=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DownHeld()) {
|
if (DownHeld()) {
|
||||||
if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,1})) {
|
if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,1})) {
|
||||||
UpdatePlayerTrail({0,1});
|
UpdatePlayerTrail({0,1});
|
||||||
|
moved=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (LeftHeld()) {
|
if (LeftHeld()) {
|
||||||
if (PARTY_MEMBER_OBJ[0]->SmoothMove({-1,0})) {
|
if (PARTY_MEMBER_OBJ[0]->SmoothMove({-1,0})) {
|
||||||
UpdatePlayerTrail({-1,0});
|
UpdatePlayerTrail({-1,0});
|
||||||
|
moved=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (RightHeld()) {
|
if (RightHeld()) {
|
||||||
if (PARTY_MEMBER_OBJ[0]->SmoothMove({1,0})) {
|
if (PARTY_MEMBER_OBJ[0]->SmoothMove({1,0})) {
|
||||||
UpdatePlayerTrail({1,0});
|
UpdatePlayerTrail({1,0});
|
||||||
|
moved=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (moved) {
|
||||||
|
vi2d cameraOffset={WIDTH/2,HEIGHT/2};
|
||||||
|
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()-cameraOffset;
|
||||||
|
}
|
||||||
|
if (moved&&BATTLE_ENCOUNTER==nullptr) {
|
||||||
|
for (int i=0;i<CURRENT_MAP->encounters.size();i++) {
|
||||||
|
if (CURRENT_MAP->encounters[i]->IsEncounterAlive()&&CURRENT_MAP->encounters[i]->IsInRange(PARTY_MEMBER_OBJ[0]->GetPos())) {
|
||||||
|
BATTLE_STATE=BattleState::MOVE_CAMERA;
|
||||||
|
BATTLE_ENCOUNTER=CURRENT_MAP->encounters[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1716,7 +1749,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerCanMove(){
|
bool PlayerCanMove(){
|
||||||
return !IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr;
|
return BATTLE_ENCOUNTER==nullptr&&!IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayMessageBox(std::string targetText) {
|
void DisplayMessageBox(std::string targetText) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user