generated from sigonasr2/CPlusPlusProjectTemplate
Implement a custom object with Interaction
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
fcdfc8065b
commit
46b113d3bb
Binary file not shown.
@ -69,6 +69,7 @@ OBJECT256.000000;192.000000;8
|
||||
OBJECT288.000000;192.000000;8
|
||||
OBJECT224.000000;192.000000;8
|
||||
OBJECT192.000000;192.000000;7
|
||||
OBJECT352.000000;192.000000;159
|
||||
OBJECT192.000000;224.000000;8
|
||||
OBJECT160.000000;224.000000;8
|
||||
OBJECT288.000000;224.000000;8
|
||||
@ -79,9 +80,9 @@ OBJECT256.000000;256.000000;8
|
||||
OBJECT224.000000;256.000000;8
|
||||
OBJECT192.000000;256.000000;8
|
||||
OBJECT160.000000;256.000000;8
|
||||
OBJECT322.000000;255.000000;0
|
||||
OBJECT256.000000;288.000000;90
|
||||
OBJECT128.000000;288.000000;90
|
||||
OBJECT322.000000;288.000000;0
|
||||
OBJECT192.000000;320.000000;90
|
||||
OBJECT96.000000;320.000000;90
|
||||
OBJECT160.000000;384.000000;90
|
||||
|
58
main.cpp
58
main.cpp
@ -149,6 +149,8 @@ public:
|
||||
std::vector<Item*> BATTLE_SPOILS_LIST;
|
||||
std::wstring BATTLE_SPOILS_MESSAGE;
|
||||
int OVERWORLD_MENU_SELECTION=0;
|
||||
std::vector<std::string> INTERACTION_MESSAGES;
|
||||
bool CLOSE_OVERWORLD_WINDOW=false; //When set to true, should cause the overworld menu to close as well once the dialog box is closed.
|
||||
|
||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||
|
||||
@ -299,6 +301,10 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
|
||||
messageBoxLoad=true;
|
||||
} else {
|
||||
messageBoxVisible=false;
|
||||
if (CLOSE_OVERWORLD_WINDOW) {
|
||||
GAME_STATE=GameState::GAME_WORLD;
|
||||
}
|
||||
CLOSE_OVERWORLD_WINDOW=false;
|
||||
}
|
||||
} else {
|
||||
while (messageBoxMarker<messageBoxFinalText.length()) {
|
||||
@ -322,6 +328,11 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerCanMove()&&INTERACTION_MESSAGES.size()>0) {
|
||||
DisplayMessageBox(INTERACTION_MESSAGES.front());
|
||||
INTERACTION_MESSAGES.erase(INTERACTION_MESSAGES.begin());
|
||||
}
|
||||
|
||||
for (int i=0;i<DAMAGE_NUMBERS.size();i++) {
|
||||
DamageNumber*numb=DAMAGE_NUMBERS[i];
|
||||
if (numb->timer>0) {
|
||||
@ -1031,6 +1042,53 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
|
||||
OVERWORLD_MENU_SELECTION+=5;
|
||||
}
|
||||
}
|
||||
if (ACTIONKEYPRESSED) {
|
||||
switch (OVERWORLD_MENU_SELECTION) {
|
||||
case 0:{//Check is selected.
|
||||
Object*closest=nullptr;
|
||||
float closestDist=999999;
|
||||
for (int i=0;i<OBJECTS.size();i++) {
|
||||
float dist;
|
||||
for (int j=0;j<PARTY_MEMBER_COUNT;j++) {
|
||||
if (OBJECTS[i]==PARTY_MEMBER_OBJ[j]) {
|
||||
goto next;
|
||||
}
|
||||
} //Make sure it's not a party member.
|
||||
dist = abs(PARTY_MEMBER_OBJ[0]->GetPos().x-OBJECTS[i]->GetPos().x)+abs(PARTY_MEMBER_OBJ[0]->GetPos().y-OBJECTS[i]->GetPos().y);
|
||||
if (dist<closestDist) {
|
||||
closestDist=dist;
|
||||
closest=OBJECTS[i];
|
||||
}
|
||||
next:
|
||||
continue;
|
||||
}
|
||||
if (closest!=nullptr) {
|
||||
//Run the Interaction for this object.
|
||||
Interaction interaction = closest->Interact();
|
||||
if (interaction.messages.size()>0) {
|
||||
INTERACTION_MESSAGES=interaction.messages;
|
||||
DisplayMessageBox(INTERACTION_MESSAGES.front());
|
||||
INTERACTION_MESSAGES.erase(INTERACTION_MESSAGES.begin());
|
||||
} else {
|
||||
DisplayMessageBox("No problem here.");
|
||||
}
|
||||
CLOSE_OVERWORLD_WINDOW=true;
|
||||
}
|
||||
}break;
|
||||
case 1:{//Power is selected.
|
||||
|
||||
}break;
|
||||
case 2:{//Items is selected.
|
||||
|
||||
}break;
|
||||
case 3:{//Equip is selected.
|
||||
|
||||
}break;
|
||||
case 4:{//Status is selected.
|
||||
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case GameState::EDITOR:{
|
||||
if (IsTextEntryEnabled()) {
|
||||
|
16
object.h
16
object.h
@ -5,8 +5,15 @@
|
||||
#include "animation.h"
|
||||
#include "defines.h"
|
||||
#include "layers.h"
|
||||
#include "item.h"
|
||||
using namespace olc;
|
||||
|
||||
struct Interaction{
|
||||
std::vector<std::string> messages={};
|
||||
Item*item=nullptr;
|
||||
Flag flag=Flag::NONE;
|
||||
};
|
||||
|
||||
class Object{
|
||||
private:
|
||||
vd2d scale={1,1};
|
||||
@ -49,7 +56,8 @@ class Object{
|
||||
this->temp=temp;
|
||||
}
|
||||
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;
|
||||
virtual bool Interact()=0;
|
||||
//When the player tries to interact with this object.
|
||||
virtual Interaction Interact()=0;
|
||||
void SetScale(vd2d scale) {
|
||||
this->scale=scale;
|
||||
if (spr!=nullptr) {
|
||||
@ -162,11 +170,13 @@ class Object{
|
||||
|
||||
class Standard_Obj : public Object{
|
||||
DynamicObject(Standard_Obj)
|
||||
bool Interact()override{return false;}
|
||||
Interaction Interact()override{return {};}
|
||||
};
|
||||
|
||||
class TrashCan_Obj : public Object{
|
||||
DynamicObject(TrashCan_Obj)
|
||||
bool Interact()override{return false;}
|
||||
Interaction Interact()override{
|
||||
frameIndex=1;
|
||||
return {{"You dig around the trash can.","Nope! Just looks like good ol' trash."}};}
|
||||
};
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user