Implement map teleport triggers on map

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent f1c347207a
commit cc5ab9ff7a
  1. BIN
      C++ProjectTemplate
  2. 33
      cutscene.h
  3. 74
      main.cpp
  4. 4
      map.cpp
  5. 5
      map.h
  6. 4
      states.h
  7. 3
      trigger.cpp
  8. 34
      trigger.h

Binary file not shown.

@ -18,8 +18,7 @@ enum PriorityDirection{
namespace CutsceneName{ namespace CutsceneName{
enum Cutscene{ enum Cutscene{
TEST_CUTSCENE, TEST_CUTSCENE,
TRANSFER_MAP_TWOSON_CUTSCENE, TRANSFER_MAP_CUTSCENE,
TRANSFER_MAP_ONETT_CUTSCENE,
}; };
} }
@ -38,6 +37,7 @@ enum class ActionType{
MOVE_CUTSCENE_OBJ_ASYNC, MOVE_CUTSCENE_OBJ_ASYNC,
MODIFY_OBJECT, MODIFY_OBJECT,
LOAD_MAP, LOAD_MAP,
MOVE_PLAYER_OBJS,
}; };
class CutsceneAction{ class CutsceneAction{
@ -270,6 +270,24 @@ class LoadMap:public CutsceneAction{
Map*GetTargetMap(){ Map*GetTargetMap(){
return map; return map;
} }
void SetTargetMap(Map*map){
this->map=map;
}
};
class MovePlayerObjects:public CutsceneAction{
protected:
vd2d newPos;
public:
MovePlayerObjects(vd2d newPos)
:newPos(newPos) {}
ActionType GetActionType() override{return ActionType::MOVE_PLAYER_OBJS;}
vd2d GetTargetPos(){
return newPos;
}
void SetTargetPos(vd2d newPos){
this->newPos=newPos;
}
}; };
/* /*
@ -282,11 +300,12 @@ you can advance the action using AdvanceAction().
class Cutscene{ class Cutscene{
private: private:
int actionMarker=0; int actionMarker=0;
std::vector<CutsceneAction*> actions;
bool actionIsActive=false; bool actionIsActive=false;
std::vector<Object*>cutsceneObjs; std::vector<Object*>cutsceneObjs;
Flag storedFlag=Flag::NONE; Flag storedFlag=Flag::NONE;
bool storedVal=true; bool storedVal=true;
protected:
std::vector<CutsceneAction*> actions;
public: public:
template <class T> template <class T>
Cutscene(std::initializer_list<T> actions) { Cutscene(std::initializer_list<T> actions) {
@ -353,11 +372,15 @@ class Cutscene{
class MapTransitionCutscene:public Cutscene{ class MapTransitionCutscene:public Cutscene{
public: public:
MapTransitionCutscene(Map*newmap) MapTransitionCutscene()
:Cutscene({ :Cutscene({
Fade(), Fade(),
LoadMap(newmap), LoadMap(nullptr),
MovePlayerObjects({0,0}),
Fade(true), Fade(true),
}){} }){}
std::vector<CutsceneAction*>GetActions(){
return actions;
}
}; };
#endif #endif

@ -159,6 +159,9 @@ extern std::map<TriggerName::Trigger,std::string> TRIGGERS;
TriggerName::Trigger SELECTED_TRIGGER; TriggerName::Trigger SELECTED_TRIGGER;
int TRIGGER_OFFSET=0; int TRIGGER_OFFSET=0;
int WORLD_DISPLAY_OFFSET=0; int WORLD_DISPLAY_OFFSET=0;
bool SELECTING_A_MAP_FOR_TRIGGER=false;
Trigger*LAST_PLACED_TRIGGER=nullptr;
Map* ORIGINATING_MAP=nullptr;
/* /*
[Choice1,Choice2,Choice3] [Choice1,Choice2,Choice3]
@ -862,7 +865,24 @@ 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;
map->triggers.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},(TriggerName::Trigger)id)); Map*mapTrigger=nullptr;
vd2d triggerCoords;
if (data.find_first_of(';',marker+1)!=std::string::npos) {
//This means there's extra data we should grab. Should be map, and two positional coordinates.
std::stringstream split6(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
int mapVal;
split6>>mapVal;
mapTrigger=MAPS[(MapName::Map)mapVal];
std::stringstream split7(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
split7>>triggerCoords.x;
std::stringstream split8(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
split8>>triggerCoords.y;
printf(" Found extra data.\n");
}
map->triggers.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},(TriggerName::Trigger)id,triggerCoords,mapTrigger));
printf("Trigger %d Loaded.\n",id); printf("Trigger %d Loaded.\n",id);
} }
} else { } else {
@ -989,7 +1009,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())+";"+std::to_string(map->triggers[i]->GetMapPtr()->myID)+";"+std::to_string(map->triggers[i]->GetAdditionalCoordData().x)+";"+std::to_string(map->triggers[i]->GetAdditionalCoordData().y);
for (int j=0;j<trigger.length();j++) { for (int j=0;j<trigger.length();j++) {
f.put(trigger[j]); f.put(trigger[j]);
} }
@ -1325,7 +1345,14 @@ void SeasonI::updateGame(){
CURRENT_MAP->triggers.erase(CURRENT_MAP->triggers.begin()+i--); CURRENT_MAP->triggers.erase(CURRENT_MAP->triggers.begin()+i--);
} }
} }
CURRENT_MAP->triggers.push_back(new Trigger(HIGHLIGHTED_TILE*32,{32,32},SELECTED_TRIGGER)); if (SELECTED_TRIGGER==TriggerName::GOTO_MAP) {
SELECTING_A_MAP_FOR_TRIGGER=true;
GAME_STATE=GameState::MAP_SELECT;
ORIGINATING_MAP=CURRENT_MAP;
LAST_PLACED_TRIGGER=new Trigger(HIGHLIGHTED_TILE*32,{32,32},SELECTED_TRIGGER); //Don't add it to the list of map triggers yet...It'll be wiped out if we do.
} else {
CURRENT_MAP->triggers.push_back(new Trigger(HIGHLIGHTED_TILE*32,{32,32},SELECTED_TRIGGER));
}
} else { } else {
TILE*tile=MAP5[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x]; TILE*tile=MAP5[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x];
tile->tileX=SELECTED_TILE.x; tile->tileX=SELECTED_TILE.x;
@ -2230,6 +2257,13 @@ void SeasonI::keyUpdates() {
GAME_STATE=GameState::OVERWORLD_MENU; GAME_STATE=GameState::OVERWORLD_MENU;
} }
}break; }break;
case GameState::MAP_POSITION_SELECT:{
LAST_PLACED_TRIGGER->SetExtraCoords(HIGHLIGHTED_TILE*32);
CURRENT_MAP=LAST_PLACED_TRIGGER->GetMapPtr();
LoadMap(ORIGINATING_MAP);
CURRENT_MAP->triggers.push_back(LAST_PLACED_TRIGGER);
LAST_PLACED_TRIGGER=nullptr;
}break;
case GameState::EDITOR:{ case GameState::EDITOR:{
if (IsTextEntryEnabled()) { if (IsTextEntryEnabled()) {
return; return;
@ -2315,7 +2349,14 @@ void SeasonI::keyUpdates() {
}break; }break;
case GameState::MAP_SELECT:{ case GameState::MAP_SELECT:{
if (GetKey(ESCAPE).bPressed) { if (GetKey(ESCAPE).bPressed) {
GAME_STATE=GameState::EDITOR; if (SELECTING_A_MAP_FOR_TRIGGER) {
SELECTING_A_MAP_FOR_TRIGGER=false;
LAST_PLACED_TRIGGER->SetMap(CURRENT_MAP);
printf("Trigger Map Location set to %s",CURRENT_MAP->mapname.c_str());
GAME_STATE=GameState::MAP_POSITION_SELECT;
} else {
GAME_STATE=GameState::EDITOR;
}
} }
if ((GetMouseWheel()<0||GetKey(PGDN).bHeld)&&WORLD_DISPLAY_OFFSET+(WIDTH/16)<MAPS.size()) { if ((GetMouseWheel()<0||GetKey(PGDN).bHeld)&&WORLD_DISPLAY_OFFSET+(WIDTH/16)<MAPS.size()) {
WORLD_DISPLAY_OFFSET+=WIDTH/16; WORLD_DISPLAY_OFFSET+=WIDTH/16;
@ -2793,7 +2834,11 @@ void SeasonI::drawGame(){
FillRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),Pixel(255,0,0,64)); FillRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),Pixel(255,0,0,64));
DrawRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),YELLOW); DrawRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),YELLOW);
vi2d textOffset={2,2}; 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}); std::string triggerText=TRIGGERS[(TriggerName::Trigger)trigger->GetID()];
if ((TriggerName::Trigger)trigger->GetID()==TriggerName::GOTO_MAP) {
triggerText="GOTO "+trigger->GetMapPtr()->mapname+"\n"+std::to_string(trigger->GetAdditionalCoordData().x)+"\n"+std::to_string(trigger->GetAdditionalCoordData().y);
}
DrawStringDecal(trigger->GetPos()-cameraPos+textOffset,triggerText,WHITE,{28.f/GetTextSize(triggerText).x,1.f});
} }
} else } else
if (EDITING_LAYER==layer::ENCOUNTER) { if (EDITING_LAYER==layer::ENCOUNTER) {
@ -2815,6 +2860,12 @@ void SeasonI::drawGame(){
DrawStringPropDecal({2,2},"Editing Layer "+std::to_string(EDITING_LAYER)); DrawStringPropDecal({2,2},"Editing Layer "+std::to_string(EDITING_LAYER));
} }
}break; }break;
case GameState::MAP_POSITION_SELECT:{
DrawGameWorld();
SetDrawTarget(layer::INTERFACE);
DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW);
DrawStringPropDecal({2,2},"Select target tile");
}break;
case GameState::TILE_SELECT:{ case GameState::TILE_SELECT:{
//14x14 pixels per tile. //14x14 pixels per tile.
DrawDecal({0,0},SPRITES["terrainmap.png"],{TILEMAP_EDITOR_DRAW_MULT,TILEMAP_EDITOR_DRAW_MULT}); DrawDecal({0,0},SPRITES["terrainmap.png"],{TILEMAP_EDITOR_DRAW_MULT,TILEMAP_EDITOR_DRAW_MULT});
@ -3760,6 +3811,13 @@ void SeasonI::HandleCutscenes() {
LoadMap(map); LoadMap(map);
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
case ActionType::MOVE_PLAYER_OBJS:{
MovePlayerObjects*action=(MovePlayerObjects*)CurrentCutscene->GetAction();
vd2d pos=action->GetTargetPos();
for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(pos);
}
}break;
} }
for (int i=0;i<CUTSCENE_QUEUE.size();i++) { for (int i=0;i<CUTSCENE_QUEUE.size();i++) {
@ -3939,7 +3997,8 @@ void SeasonI::AdvanceMessageBox() {
void SeasonI::cameraUpdate() { void SeasonI::cameraUpdate() {
switch (GAME_STATE) { switch (GAME_STATE) {
case GameState::EDITOR:{ case GameState::EDITOR:
case GameState::MAP_POSITION_SELECT:{
//CAMERA MOVEMENTS MUST BE LAST!!! //CAMERA MOVEMENTS MUST BE LAST!!!
if (UpHeld()) { if (UpHeld()) {
cameraPos.y-=CAMERA_MOVESPD; cameraPos.y-=CAMERA_MOVESPD;
@ -5064,8 +5123,7 @@ void SeasonI::SetupCutscenes(){
This is a test message that lets us trigger straight from a cutscene! Cool!)"), This is a test message that lets us trigger straight from a cutscene! Cool!)"),
ModifyObject(0,ANIMATIONS["player.png"],{5,5},MAGENTA), ModifyObject(0,ANIMATIONS["player.png"],{5,5},MAGENTA),
MoveCutsceneObject(1,{320,64},1),})}, MoveCutsceneObject(1,{320,64},1),})},
{CutsceneName::TRANSFER_MAP_TWOSON_CUTSCENE,new MapTransitionCutscene(MAPS[MapName::TWOSON])}, {CutsceneName::TRANSFER_MAP_CUTSCENE,new MapTransitionCutscene()},
{CutsceneName::TRANSFER_MAP_ONETT_CUTSCENE,new MapTransitionCutscene(MAPS[MapName::ONETT])},
}; };
} }

@ -7,6 +7,6 @@ extern std::map<std::string,Decal*> SPRITES;
int MAP_ENUM_COUNT=0; int MAP_ENUM_COUNT=0;
std::map<MapName::Map,Map*> MAPS={ std::map<MapName::Map,Map*> MAPS={
{(MapName::Map)MAP_ENUM_COUNT++,new Map("map0","map0_2","map0_3","map0_4","map0_5",SPRITES["terrainmap.png"],"Onett")}, {(MapName::Map)MAP_ENUM_COUNT++,new Map("map0","map0_2","map0_3","map0_4","map0_5",SPRITES["terrainmap.png"],"Onett",(MapName::Map)(MAP_ENUM_COUNT-1))},
{(MapName::Map)MAP_ENUM_COUNT++,new Map("newmap","newmap_2","newmap_3","newmap_4","newmap_5",SPRITES["terrainmap.png"],"Twoson")}, {(MapName::Map)MAP_ENUM_COUNT++,new Map("newmap","newmap_2","newmap_3","newmap_4","newmap_5",SPRITES["terrainmap.png"],"Twoson",(MapName::Map)(MAP_ENUM_COUNT-1))},
}; };

@ -24,7 +24,8 @@ class Map{
Decal*tileset; Decal*tileset;
std::vector<Encounter*> encounters; std::vector<Encounter*> encounters;
std::vector<Trigger*> triggers; std::vector<Trigger*> triggers;
Map(std::string fname,std::string layer2_fname,std::string layer3_fname,std::string layer4_fname,std::string layer5_fname,Decal*tileset,std::string mapname) MapName::Map myID;
:filename(fname),l2filename(layer2_fname),l3filename(layer3_fname),l4filename(layer4_fname),l5filename(layer5_fname),mapname(mapname),tileset(tileset) {} Map(std::string fname,std::string layer2_fname,std::string layer3_fname,std::string layer4_fname,std::string layer5_fname,Decal*tileset,std::string mapname,MapName::Map myID)
:filename(fname),l2filename(layer2_fname),l3filename(layer3_fname),l4filename(layer4_fname),l5filename(layer5_fname),mapname(mapname),tileset(tileset),myID(myID) {}
}; };
#endif #endif

@ -22,9 +22,7 @@ namespace GameState{
SHOPKEEPER_CONFIRM_SELL_MENU, SHOPKEEPER_CONFIRM_SELL_MENU,
TRIGGER_SELECT, TRIGGER_SELECT,
MAP_SELECT, MAP_SELECT,
NEW_MAP_INPUT_NAME, MAP_POSITION_SELECT,
NEW_MAP_INPUT_WIDTH,
NEW_MAP_INPUT_HEIGHT,
}; };
} }

@ -5,6 +5,5 @@ int TRIGGER_ENUM_COUNT=1;
std::map<TriggerName::Trigger,std::string> TRIGGERS={ std::map<TriggerName::Trigger,std::string> TRIGGERS={
{(TriggerName::Trigger)TRIGGER_ENUM_COUNT++,"START_CUTSCENE_1"}, {(TriggerName::Trigger)TRIGGER_ENUM_COUNT++,"START_CUTSCENE_1"},
{(TriggerName::Trigger)TRIGGER_ENUM_COUNT++,"Goto Twoson"}, {(TriggerName::Trigger)TRIGGER_ENUM_COUNT++,"Goto"},
{(TriggerName::Trigger)TRIGGER_ENUM_COUNT++,"Goto Onett"},
}; };

@ -12,23 +12,25 @@ namespace TriggerName{
enum Trigger{ enum Trigger{
NONE, NONE,
START_CUTSCENE_1, START_CUTSCENE_1,
GOTO_TWOSON_MAP, GOTO_MAP,
GOTO_ONETT_MAP
}; };
} }
extern void DisplayMessageBox(std::string targetT); extern void DisplayMessageBox(std::string targetT);
extern SeasonI*GAME; extern SeasonI*GAME;
extern std::map<CutsceneName::Cutscene,Cutscene*> CUTSCENES; extern std::map<CutsceneName::Cutscene,Cutscene*> CUTSCENES;
extern Map*CURRENT_MAP;
extern vi2d HIGHLIGHTED_TILE;
class Trigger{ class Trigger{
vi2d pos; vi2d pos;
vi2d size; vi2d size;
TriggerName::Trigger id; TriggerName::Trigger id;
vi2d extraCoords; vi2d extraCoords;
Map*mapChoice;
public: public:
Trigger(vi2d pos,vi2d size,TriggerName::Trigger id,vi2d extraCoords={0,0}) Trigger(vi2d pos,vi2d size,TriggerName::Trigger id,vi2d extraCoords={0,0},Map*mapChoice=nullptr)
:pos(pos),size(size),id(id),extraCoords(extraCoords){} :pos(pos),size(size),id(id),extraCoords(extraCoords),mapChoice(mapChoice){}
bool IsInside(vd2d point) { bool IsInside(vd2d point) {
return point.x>pos.x&&point.x<pos.x+size.x&&point.y>pos.y&&point.y<pos.y+size.y; return point.x>pos.x&&point.x<pos.x+size.x&&point.y>pos.y&&point.y<pos.y+size.y;
} }
@ -40,11 +42,13 @@ class Trigger{
GAME->SetGameFlag(Flag::TEST_FLAG1,true); GAME->SetGameFlag(Flag::TEST_FLAG1,true);
} }
}break; }break;
case TriggerName::GOTO_TWOSON_MAP:{ case TriggerName::GOTO_MAP:{
GAME->StartCutscene(CUTSCENES[CutsceneName::TRANSFER_MAP_TWOSON_CUTSCENE]); MapTransitionCutscene*scene=(MapTransitionCutscene*)CUTSCENES[CutsceneName::TRANSFER_MAP_CUTSCENE];
}break; std::vector<CutsceneAction*>actions=scene->GetActions();
case TriggerName::GOTO_ONETT_MAP:{ LoadMap*mapLoadAction=(LoadMap*)actions[1];
GAME->StartCutscene(CUTSCENES[CutsceneName::TRANSFER_MAP_ONETT_CUTSCENE]); mapLoadAction->SetTargetMap(CURRENT_MAP);
MovePlayerObjects*playerMoveAction=(MovePlayerObjects*)actions[2];
playerMoveAction->SetTargetPos(HIGHLIGHTED_TILE);
}break; }break;
} }
} }
@ -69,5 +73,17 @@ class Trigger{
int GetID() { int GetID() {
return id; return id;
} }
Map*GetMapPtr(){
return mapChoice;
}
vd2d GetAdditionalCoordData(){
return extraCoords;
}
void SetExtraCoords(vd2d coords) {
extraCoords=coords;
}
void SetMap(Map*map) {
mapChoice=map;
}
}; };
#endif #endif
Loading…
Cancel
Save