Trigger implementation

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 23d50ad3c2
commit b85db76ee5
  1. BIN
      C++ProjectTemplate
  2. 14
      assets/maps/map0
  3. 85
      main.cpp
  4. 1
      states.h
  5. 8
      trigger.cpp
  6. 26
      trigger.h

Binary file not shown.

@ -5,12 +5,12 @@
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????91:1;1?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????91:1;1??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????92:2;2?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????92:2;2??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????92:2;2?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??00????????????????????92:2;2??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??66????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????66????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??66????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
@ -75,13 +75,13 @@ OBJECT160.000000;224.000000;8
OBJECT288.000000;224.000000;8 OBJECT288.000000;224.000000;8
OBJECT224.000000;224.000000;8 OBJECT224.000000;224.000000;8
OBJECT256.000000;224.000000;7 OBJECT256.000000;224.000000;7
OBJECT328.000000;215.000000;0
OBJECT288.000000;256.000000;8 OBJECT288.000000;256.000000;8
OBJECT256.000000;256.000000;8 OBJECT256.000000;256.000000;8
OBJECT224.000000;256.000000;8 OBJECT224.000000;256.000000;8
OBJECT192.000000;256.000000;8 OBJECT192.000000;256.000000;8
OBJECT160.000000;256.000000;8 OBJECT160.000000;256.000000;8
OBJECT512.000000;288.000000;158 OBJECT512.000000;288.000000;158
OBJECT333.000000;286.000000;0
OBJECT256.000000;288.000000;90 OBJECT256.000000;288.000000;90
OBJECT128.000000;288.000000;90 OBJECT128.000000;288.000000;90
OBJECT192.000000;320.000000;90 OBJECT192.000000;320.000000;90
@ -91,3 +91,7 @@ OBJECT96.000000;416.000000;159
ENCOUNTER64.000000;512.000000;90;2 ENCOUNTER64.000000;512.000000;90;2
ENCOUNTER192.000000;352.000000;100;1 ENCOUNTER192.000000;352.000000;100;1
ENCOUNTER480.000000;160.000000;100;3 ENCOUNTER480.000000;160.000000;100;3
TRIGGER32;288;1;32;32
TRIGGER96;352;1;32;32
TRIGGER32;384;1;32;32
TRIGGER32;288;1;32;32

@ -156,6 +156,8 @@ int MONEY=0;
int ENEMY_MONEY_SUM=0; int ENEMY_MONEY_SUM=0;
int SHOP_MENU_CURSOR=0; int SHOP_MENU_CURSOR=0;
Object*SHOPKEEPER_INTERACTING_WITH=nullptr; Object*SHOPKEEPER_INTERACTING_WITH=nullptr;
extern std::map<TriggerName::Trigger,std::string> TRIGGERS;
TriggerName::Trigger SELECTED_TRIGGER;
/* /*
[Choice1,Choice2,Choice3] [Choice1,Choice2,Choice3]
@ -191,8 +193,6 @@ std::vector<std::vector<TILE*>> MAP2={};
std::vector<std::vector<TILE*>> MAP3={}; std::vector<std::vector<TILE*>> MAP3={};
std::vector<std::vector<TILE*>> MAP4={}; std::vector<std::vector<TILE*>> MAP4={};
std::vector<std::vector<TILE*>> MAP5={}; //Collision Layer std::vector<std::vector<TILE*>> MAP5={}; //Collision Layer
std::vector<Trigger*> TRIGGERS={};
std::map<TriggerName::Trigger,Trigger*> Trigger::TRIGGERLIST={};
std::map<std::string,Decal*> SPRITES; std::map<std::string,Decal*> SPRITES;
std::map<std::string,Animation*> ANIMATIONS={}; std::map<std::string,Animation*> ANIMATIONS={};
std::map<int,Object*> OBJ_INFO={}; std::map<int,Object*> OBJ_INFO={};
@ -793,7 +793,6 @@ void SeasonI::LoadMap(Map*map) {
delete OBJECTS[i]; delete OBJECTS[i];
} }
OBJECTS.clear(); OBJECTS.clear();
TRIGGERS.clear();
for (int i=0;i<4;i++) { for (int i=0;i<4;i++) {
PARTY_MEMBER_OBJ[i]=nullptr; PARTY_MEMBER_OBJ[i]=nullptr;
PARTY_MEMBER_ID[i]=0; PARTY_MEMBER_ID[i]=0;
@ -848,7 +847,6 @@ void SeasonI::LoadMap(Map*map) {
lastMarker=marker; lastMarker=marker;
int pct=id; int pct=id;
split4>>id; split4>>id;
LoadEncounter(map,{x,y},pct,id,rand()%100<pct); LoadEncounter(map,{x,y},pct,id,rand()%100<pct);
printf("Encounter %d (%d%c) Loaded.\n",id,pct,'%'); printf("Encounter %d (%d%c) Loaded.\n",id,pct,'%');
@ -862,8 +860,7 @@ void SeasonI::LoadMap(Map*map) {
std::stringstream split5(data.substr(lastMarker+1,marker-lastMarker-1)); std::stringstream split5(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker; lastMarker=marker;
split5>>size_y; split5>>size_y;
TRIGGERS.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},id)); map->triggers.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},(TriggerName::Trigger)id));
map->triggers.push_back(Trigger::TRIGGERLIST[(TriggerName::Trigger)id]);
printf("Trigger %d Loaded.\n",id); printf("Trigger %d Loaded.\n",id);
} }
} else { } else {
@ -989,7 +986,7 @@ void SeasonI::SaveMap(Map*map) {
for (int i=0;i<map->triggers.size();i++) { for (int i=0;i<map->triggers.size();i++) {
f.put('\n'); f.put('\n');
const std::string trigger="TRIGGER"+std::to_string(map->triggers[i]->GetPosX())+";"+std::to_string(map->triggers[i]->GetPosY())+";"+";"+std::to_string(map->triggers[i]->GetID())+std::to_string(map->triggers[i]->GetSizeX())+";"+std::to_string(map->triggers[i]->GetSizeY()); const std::string trigger="TRIGGER"+std::to_string(map->triggers[i]->GetPosX())+";"+std::to_string(map->triggers[i]->GetPosY())+";"+std::to_string(map->triggers[i]->GetID())+";"+std::to_string(map->triggers[i]->GetSizeX())+";"+std::to_string(map->triggers[i]->GetSizeY());
for (int j=0;j<trigger.length();j++) { for (int j=0;j<trigger.length();j++) {
f.put(trigger[j]); f.put(trigger[j]);
} }
@ -1226,6 +1223,11 @@ void SeasonI::updateGame(){
GAME_STATE=GameState::EDITOR; GAME_STATE=GameState::EDITOR;
} }
}break; }break;
case GameState::TRIGGER_SELECT:{
if (!GetKey(CTRL).bHeld) {
GAME_STATE=GameState::EDITOR;
}
}break;
case GameState::GAME_WORLD:{ case GameState::GAME_WORLD:{
if (PlayerCanMove()) { if (PlayerCanMove()) {
bool moved=false; bool moved=false;
@ -1245,6 +1247,11 @@ void SeasonI::updateGame(){
if (movementComponents.mag()>0) { if (movementComponents.mag()>0) {
if (PARTY_MEMBER_OBJ[0]->SmoothMove(movementComponents)) { if (PARTY_MEMBER_OBJ[0]->SmoothMove(movementComponents)) {
UpdatePlayerTrail(movementComponents); UpdatePlayerTrail(movementComponents);
for (int i=0;i<CURRENT_MAP->triggers.size();i++) {
if (CURRENT_MAP->triggers[i]->IsInside(PARTY_MEMBER_OBJ[0]->GetPosWithOrigin())) {
CURRENT_MAP->triggers[i]->Interact();
}
}
moved=true; moved=true;
} }
} }
@ -1274,6 +1281,10 @@ void SeasonI::updateGame(){
if (GetKey(SHIFT).bHeld) { if (GetKey(SHIFT).bHeld) {
GAME_STATE=GameState::ENCOUNTER_SELECT; GAME_STATE=GameState::ENCOUNTER_SELECT;
} }
if (GetKey(CTRL).bHeld) {
GAME_STATE=GameState::TRIGGER_SELECT;
SELECTED_TRIGGER=TriggerName::NONE;
}
if (PlayerCanMove()) { if (PlayerCanMove()) {
if (GetKey(I).bHeld) { if (GetKey(I).bHeld) {
if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) { if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) {
@ -1304,9 +1315,19 @@ void SeasonI::updateGame(){
if (GetMouse(0).bHeld) { if (GetMouse(0).bHeld) {
switch (EDITING_LAYER) { switch (EDITING_LAYER) {
case layer::COLLISION:{ case layer::COLLISION:{
TILE*tile=MAP5[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x]; if (EDITING_LAYER==layer::COLLISION&&SELECTED_TRIGGER!=TriggerName::NONE) {
tile->tileX=SELECTED_TILE.x; for (int i=0;i<CURRENT_MAP->triggers.size();i++) {
tile->tileY=SELECTED_TILE.y; if (CURRENT_MAP->triggers[i]->GetPos()==HIGHLIGHTED_TILE*32) {
delete CURRENT_MAP->triggers[i];
CURRENT_MAP->triggers.erase(CURRENT_MAP->triggers.begin()+i--);
}
}
CURRENT_MAP->triggers.push_back(new Trigger(HIGHLIGHTED_TILE*32,{32,32},SELECTED_TRIGGER));
} else {
TILE*tile=MAP5[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x];
tile->tileX=SELECTED_TILE.x;
tile->tileY=SELECTED_TILE.y;
}
}break; }break;
case layer::HIGH:{ case layer::HIGH:{
TILE*tile=MAP[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x]; TILE*tile=MAP[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x];
@ -2487,7 +2508,6 @@ void SeasonI::drawGame(){
bool underAttack=false; bool underAttack=false;
if (BATTLE_ENCOUNTER!=nullptr) { if (BATTLE_ENCOUNTER!=nullptr) {
std::vector<Entity*> attackedAllies; std::vector<Entity*> attackedAllies;
if (CURRENT_TURN>=0&&BATTLE_STATE==BattleState::WAIT_ANIMATION&&BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget<0) { if (CURRENT_TURN>=0&&BATTLE_STATE==BattleState::WAIT_ANIMATION&&BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget<0) {
attackedAllies=GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->channelPos,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove); attackedAllies=GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->channelPos,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove);
} }
@ -2728,6 +2748,15 @@ void SeasonI::drawGame(){
DrawGameWorld(); DrawGameWorld();
SetDrawTarget(nullptr); SetDrawTarget(nullptr);
DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW); DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW);
if (EDITING_LAYER==layer::COLLISION&&SELECTED_TRIGGER!=TriggerName::NONE) {
DrawStringPropDecal({2,2},Wrap("Editing Triggers - Selected "+TRIGGERS[SELECTED_TRIGGER],WIDTH-4,true,{1,1}));
for (auto&trigger:CURRENT_MAP->triggers) {
FillRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),Pixel(255,0,0,64));
DrawRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),YELLOW);
vi2d textOffset={2,2};
DrawStringDecal(trigger->GetPos()-cameraPos+textOffset,TRIGGERS[(TriggerName::Trigger)trigger->GetID()],WHITE,{28.f/GetTextSize(TRIGGERS[(TriggerName::Trigger)trigger->GetID()]).x,1.f});
}
} else
if (EDITING_LAYER==layer::ENCOUNTER) { if (EDITING_LAYER==layer::ENCOUNTER) {
if (IsTextEntryEnabled()) { if (IsTextEntryEnabled()) {
DrawStringPropDecal({2,2},"Input Chance: "+TextEntryGetString()+"%",YELLOW); DrawStringPropDecal({2,2},"Input Chance: "+TextEntryGetString()+"%",YELLOW);
@ -2827,6 +2856,40 @@ void SeasonI::drawGame(){
counter++; counter++;
} }
}break; }break;
case GameState::TRIGGER_SELECT:{
vd2d drawpos={0,0};
int counter=0;
for (std::map<TriggerName::Trigger,std::string>::const_iterator it = TRIGGERS.cbegin();it!=TRIGGERS.cend();++it){
if (counter<OBJ_DISPLAY_OFFSET) {
counter++;
continue;
}
if (drawpos.y>HEIGHT) {
break;
}
TriggerName::Trigger trigger = it->first;
if (GetMouse(0).bHeld&&
GetMousePos().x>=drawpos.x&&
GetMousePos().x<drawpos.x+16&&
GetMousePos().y>=drawpos.y&&
GetMousePos().y<drawpos.y+24) {
SELECTED_TRIGGER=trigger;
EDITING_LAYER=layer::COLLISION;
EnableLayer(layer::COLLISION,false);
}
FillRectDecal(drawpos,{16,24},VERY_DARK_GREY);
DrawStringDecal({(float)(drawpos.x+2),(float)(drawpos.y)},it->second,WHITE,{(float)(12.0/GetTextSize(it->second).x),1.0});
if (SELECTED_TRIGGER==it->first) {
DrawRectDecal(drawpos,{16,24},YELLOW);
}
drawpos.x+=16;
if (drawpos.x>=WIDTH) {
drawpos.x=0;
drawpos.y+=24;
}
counter++;
}
}break;
} }
if (BATTLE_ENCOUNTER!=nullptr&&BATTLE_STATE==BattleState::TARGET_SELECT||GAME_STATE==GameState::OVERWORLD_TARGET_MENU) { if (BATTLE_ENCOUNTER!=nullptr&&BATTLE_STATE==BattleState::TARGET_SELECT||GAME_STATE==GameState::OVERWORLD_TARGET_MENU) {
SetDrawTarget(layer::GROUND); SetDrawTarget(layer::GROUND);

@ -20,6 +20,7 @@ namespace GameState{
SHOPKEEPER_MENU, SHOPKEEPER_MENU,
SHOPKEEPER_SELL_MENU, SHOPKEEPER_SELL_MENU,
SHOPKEEPER_CONFIRM_SELL_MENU, SHOPKEEPER_CONFIRM_SELL_MENU,
TRIGGER_SELECT,
}; };
} }

@ -0,0 +1,8 @@
#include "pixelGameEngine.h"
#include "trigger.h"
int i=1;
std::map<TriggerName::Trigger,std::string> TRIGGERS={
{(TriggerName::Trigger)i++,"START_CUTSCENE_1"},
};

@ -1,22 +1,41 @@
#ifndef TRIGGER_H
#define TRIGGER_H
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
#include "flags.h"
#include "SeasonI.h"
using namespace olc; using namespace olc;
namespace TriggerName{ namespace TriggerName{
//When adding new triggers to the list, you will have to add a new line to trigger.cpp to get it to appear in the editor.
enum Trigger{ enum Trigger{
NONE,
START_CUTSCENE_1 START_CUTSCENE_1
}; };
} }
extern void DisplayMessageBox(std::string targetT);
extern SeasonI*GAME;
class Trigger{ class Trigger{
vi2d pos; vi2d pos;
vi2d size; vi2d size;
int id; TriggerName::Trigger id;
public: public:
Trigger(vi2d pos,vi2d size,int id) Trigger(vi2d pos,vi2d size,TriggerName::Trigger id)
:pos(pos),size(size),id(id){} :pos(pos),size(size),id(id){}
bool IsInside(vd2d point) { bool IsInside(vd2d point) {
return point>pos&&point<pos+size; return point.x>pos.x&&point.x<pos.x+size.x&&point.y>pos.y&&point.y<pos.y+size.y;
}
void Interact() {
switch (id) {
case TriggerName::START_CUTSCENE_1:{
if (!GAME->GetGameFlag(Flag::TEST_FLAG1)) {
DisplayMessageBox("You have triggered this scene.");
GAME->SetGameFlag(Flag::TEST_FLAG1,true);
}
}break;
}
} }
vi2d GetPos() { vi2d GetPos() {
return pos; return pos;
@ -40,3 +59,4 @@ class Trigger{
return id; return id;
} }
}; };
#endif
Loading…
Cancel
Save