Advanced flag setting and branching. Choice made function

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent f77b7f3cf2
commit 320e9bdf30
  1. BIN
      C++ProjectTemplate
  2. 9
      main.cpp
  3. 23
      object.h

Binary file not shown.

@ -171,6 +171,7 @@ int MESSAGE_BOX_DIALOG_CHOICES_MADE=0;
std::vector<std::string> MESSAGE_BOX_CHOICE_LIST={};
bool waitingForChoice=false;
int MESSAGE_BOX_DIALOG_CHOICE_CURSOR=0;
Object*INTERACTING_WITH=nullptr;
/*
[Choice1,Choice2,Choice3]
@ -800,16 +801,19 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
messageBoxMarker++;
int counter=0;
while (messageBoxFinalText[messageBoxMarker]-'0'!=MESSAGE_BOX_DIALOG_CHOICE_CURSOR) {
while(messageBoxFinalText[messageBoxMarker]!='>'&&messageBoxFinalText[messageBoxMarker]!='<') {
while(messageBoxFinalText[messageBoxMarker]!='>'&&messageBoxFinalText[messageBoxMarker]!='<'&&messageBoxFinalText[messageBoxMarker]!='\t') {
messageBoxMarker++;
}
messageBoxMarker++;
}
messageBoxMarker+=2;
}
while (messageBoxFinalText[messageBoxMarker]!='<'&&messageBoxFinalText[messageBoxMarker]!='>') {
while (messageBoxFinalText[messageBoxMarker]!='<'&&messageBoxFinalText[messageBoxMarker]!='>'&&messageBoxFinalText[messageBoxMarker]!='\t') {
responseText+=messageBoxFinalText[messageBoxMarker++];
}
if (INTERACTING_WITH!=nullptr) {
INTERACTING_WITH->ChoiceMade(MESSAGE_BOX_DIALOG_CHOICE_CURSOR);
}
DisplayMessageBox("");
targetText=responseText;
}
@ -1267,6 +1271,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
}
if (closest!=nullptr) {
//Run the Interaction for this object.
INTERACTING_WITH=closest;
Interaction interaction = closest->Interact();
if (interaction.messages.size()>0) {
INTERACTION_MESSAGES=interaction.messages;

@ -58,6 +58,7 @@ class Object{
virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)=0;
//When the player tries to interact with this object.
virtual Interaction Interact()=0;
virtual void ChoiceMade(int choice)=0;
void SetScale(vd2d scale) {
this->scale=scale;
if (spr!=nullptr) {
@ -171,6 +172,7 @@ class Object{
class Standard_Obj : public Object{
DynamicObject(Standard_Obj)
Interaction Interact()override{return {};}
void ChoiceMade(int choice)override{}
};
class TrashCan_Obj : public Object{
@ -178,6 +180,7 @@ class TrashCan_Obj : public Object{
Interaction Interact()override{
frameIndex=1;
return {{"You dig around the trash can.","Nope! Just looks like plain ol' trash."}};}
void ChoiceMade(int choice)override{}
};
extern int MESSAGE_BOX_DIALOG_ANSWER;
@ -191,15 +194,25 @@ class Shopkeeper_Obj : public Object{
>1:What would you like to sell?\
>2:Are you okay?<";
Interaction Interact()override{
if (GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]&&MESSAGE_BOX_DIALOG_ANSWER==2) {
MESSAGE_BOX_DIALOG_ANSWER=0;
if (GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]) {
GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]=false;
return {{"No! Stay away! [Okay,Ignore]\
>0:Yeah I thought so.\
>1:...<"}};
switch (MESSAGE_BOX_DIALOG_ANSWER) {
case 2:{
return {{"No! Stay away! [Okay,Ignore]\
>0:Yeah I thought so.\
>1:...<"}};
}break;
}
} else {
return {{welcomeMessage},flag:Flag::SHOPKEER_BRANCH1};
}
}
void ChoiceMade(int choice)override{
if (GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]) {
if (choice!=2) {
GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]=false;
}
}
}
};
#endif
Loading…
Cancel
Save