Dynamic Map transitions now completed

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent cc5ab9ff7a
commit 345217571a
  1. BIN
      C++ProjectTemplate
  2. 2
      SeasonI.h
  3. 14
      assets/maps/map0
  4. 2
      assets/maps/newmap
  5. 112
      main.cpp
  6. 12
      map.cpp
  7. 3
      test/test.cpp
  8. 5
      trigger.h

Binary file not shown.

@ -33,6 +33,7 @@ class SeasonI:public PixelGameEngine{
void SetupEncounters(); void SetupEncounters();
void SetupBattleProperties(); void SetupBattleProperties();
void SetupCutscenes(); void SetupCutscenes();
void SetupMapList();
void SetGameFlag(Flag flag,bool val); void SetGameFlag(Flag flag,bool val);
void LoadMap(Map*map); void LoadMap(Map*map);
void SaveMap(Map*map); void SaveMap(Map*map);
@ -127,6 +128,7 @@ class SeasonI:public PixelGameEngine{
void DrawInventory(); void DrawInventory();
void ChoiceMade(int choice); void ChoiceMade(int choice);
void StartCutscene(Cutscene*cutscene); void StartCutscene(Cutscene*cutscene);
void DrawTriggers();
}; };
extern SeasonI*GAME; extern SeasonI*GAME;
#endif #endif

@ -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
OBJECT429.000000;276.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,8 +91,10 @@ 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 TRIGGER128;224;1;32;32
TRIGGER96;352;1;32;32 TRIGGER96;224;1;32;32
TRIGGER32;384;1;32;32 TRIGGER64;224;1;32;32
TRIGGER32;288;1;32;32 TRIGGER64;256;1;32;32
TRIGGER416;256;2;32;32 TRIGGER96;256;1;32;32
TRIGGER128;256;1;32;32
TRIGGER416;256;2;32;32;1;160.000000;256.000000

@ -69,4 +69,4 @@ TRIGGER96;352;1;32;32
TRIGGER96;384;1;32;32 TRIGGER96;384;1;32;32
TRIGGER64;384;1;32;32 TRIGGER64;384;1;32;32
TRIGGER32;384;1;32;32 TRIGGER32;384;1;32;32
TRIGGER416;256;3;32;32 TRIGGER416;256;2;32;32;0;256.000000;96.000000

@ -54,7 +54,7 @@ const float TARGET_RATE = 1/60.0;
int MAP_WIDTH=-1; int MAP_WIDTH=-1;
int MAP_HEIGHT=-1; int MAP_HEIGHT=-1;
Map*CURRENT_MAP=nullptr; Map*CURRENT_MAP=nullptr;
extern std::map<MapName::Map,Map*> MAPS; std::map<MapName::Map,Map*> MAPS;
int GAME_STATE = GameState::EDITOR; int GAME_STATE = GameState::EDITOR;
vi2d SELECTED_TILE={0,0}; vi2d SELECTED_TILE={0,0};
vi2d HIGHLIGHTED_TILE={0,0}; vi2d HIGHLIGHTED_TILE={0,0};
@ -238,6 +238,7 @@ bool SeasonI::OnUserCreate(){
SetupEncounters(); SetupEncounters();
SetupBattleProperties(); SetupBattleProperties();
SetupCutscenes(); SetupCutscenes();
SetupMapList();
SetGameFlag(Flag::TEST_FLAG1,false); SetGameFlag(Flag::TEST_FLAG1,false);
SetGameFlag(Flag::TEST_FLAG2,false); SetGameFlag(Flag::TEST_FLAG2,false);
SetGameFlag(Flag::TEST_FLAG3,false); SetGameFlag(Flag::TEST_FLAG3,false);
@ -862,27 +863,37 @@ void SeasonI::LoadMap(Map*map) {
lastMarker=marker; lastMarker=marker;
int size_x,size_y; int size_x,size_y;
split4>>size_x; split4>>size_x;
marker=data.find_first_of(';',marker+1);
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*mapTrigger=nullptr; Map*mapTrigger=nullptr;
vd2d triggerCoords; vd2d triggerCoords;
if (data.find_first_of(';',marker+1)!=std::string::npos) { if (marker!=std::string::npos) {
//This means there's extra data we should grab. Should be map, and two positional coordinates. //This means there's extra data we should grab. Should be map, and two positional coordinates.
marker=data.find_first_of(';',marker+1);
std::stringstream split6(data.substr(lastMarker+1,marker-lastMarker-1)); std::stringstream split6(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker; lastMarker=marker;
int mapVal; int mapVal=0;
split6>>mapVal; split6>>mapVal;
mapTrigger=MAPS[(MapName::Map)mapVal]; if (MAPS.count((MapName::Map)mapVal)) {
std::stringstream split7(data.substr(lastMarker+1,marker-lastMarker-1)); mapTrigger=MAPS[(MapName::Map)mapVal];
lastMarker=marker; marker=data.find_first_of(';',marker+1);
split7>>triggerCoords.x; std::stringstream split7(data.substr(lastMarker+1,marker-lastMarker-1));
std::stringstream split8(data.substr(lastMarker+1,marker-lastMarker-1)); lastMarker=marker;
lastMarker=marker; split7>>triggerCoords.x;
split8>>triggerCoords.y; marker=data.find_first_of(';',marker+1);
printf(" Found extra data.\n"); std::stringstream split8(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
split8>>triggerCoords.y;
printf(" Found extra data. Map:%s\n",mapTrigger->mapname.c_str());
map->triggers.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},(TriggerName::Trigger)id,triggerCoords,mapTrigger));
} else {
printf(" Failed to load extra data.\n");
}
} else {
map->triggers.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},(TriggerName::Trigger)id));
} }
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 {
@ -1009,7 +1020,10 @@ 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())+";"+std::to_string(map->triggers[i]->GetMapPtr()->myID)+";"+std::to_string(map->triggers[i]->GetAdditionalCoordData().x)+";"+std::to_string(map->triggers[i]->GetAdditionalCoordData().y); 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());
if (map->triggers[i]->GetMapPtr()!=nullptr) {
trigger+=";"+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]);
} }
@ -1294,6 +1308,13 @@ void SeasonI::updateGame(){
} }
} }
}break; }break;
case GameState::MAP_POSITION_SELECT:{
int selectedTileX=(GetMouseX()+cameraPos.x)/32;
int selectedTileY=(GetMouseY()+cameraPos.y)/32;
if (selectedTileX<MAP_WIDTH&&selectedTileY<MAP_HEIGHT&&selectedTileX>=0&&selectedTileY>=0) {
HIGHLIGHTED_TILE={selectedTileX,selectedTileY};
}
}break;
case GameState::EDITOR:{ case GameState::EDITOR:{
if (IsTextEntryEnabled()) { if (IsTextEntryEnabled()) {
return; return;
@ -1384,8 +1405,17 @@ void SeasonI::updateGame(){
if (GetMouse(1).bHeld) { if (GetMouse(1).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=tile->tileY=15; for (int i=0;i<CURRENT_MAP->triggers.size();i++) {
if (CURRENT_MAP->triggers[i]->GetPos()==HIGHLIGHTED_TILE*32) {
delete CURRENT_MAP->triggers[i];
CURRENT_MAP->triggers.erase(CURRENT_MAP->triggers.begin()+i--);
}
}
} else {
TILE*tile=MAP5[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x];
tile->tileX=tile->tileY=15;
}
}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];
@ -2258,11 +2288,15 @@ void SeasonI::keyUpdates() {
} }
}break; }break;
case GameState::MAP_POSITION_SELECT:{ case GameState::MAP_POSITION_SELECT:{
LAST_PLACED_TRIGGER->SetExtraCoords(HIGHLIGHTED_TILE*32); if (GetMouse(0).bReleased) {
CURRENT_MAP=LAST_PLACED_TRIGGER->GetMapPtr(); LAST_PLACED_TRIGGER->SetExtraCoords(HIGHLIGHTED_TILE*32);
LoadMap(ORIGINATING_MAP); CURRENT_MAP=ORIGINATING_MAP;
CURRENT_MAP->triggers.push_back(LAST_PLACED_TRIGGER); LoadMap(CURRENT_MAP);
LAST_PLACED_TRIGGER=nullptr; CURRENT_MAP->triggers.push_back(LAST_PLACED_TRIGGER);
LAST_PLACED_TRIGGER=nullptr;
GAME_STATE=GameState::EDITOR;
SELECTING_A_MAP_FOR_TRIGGER=false;
}
}break; }break;
case GameState::EDITOR:{ case GameState::EDITOR:{
if (IsTextEntryEnabled()) { if (IsTextEntryEnabled()) {
@ -2352,7 +2386,7 @@ void SeasonI::keyUpdates() {
if (SELECTING_A_MAP_FOR_TRIGGER) { if (SELECTING_A_MAP_FOR_TRIGGER) {
SELECTING_A_MAP_FOR_TRIGGER=false; SELECTING_A_MAP_FOR_TRIGGER=false;
LAST_PLACED_TRIGGER->SetMap(CURRENT_MAP); LAST_PLACED_TRIGGER->SetMap(CURRENT_MAP);
printf("Trigger Map Location set to %s",CURRENT_MAP->mapname.c_str()); printf("Trigger Map Location set to %s\n",CURRENT_MAP->mapname.c_str());
GAME_STATE=GameState::MAP_POSITION_SELECT; GAME_STATE=GameState::MAP_POSITION_SELECT;
} else { } else {
GAME_STATE=GameState::EDITOR; GAME_STATE=GameState::EDITOR;
@ -2830,16 +2864,7 @@ void SeasonI::drawGame(){
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) { if (EDITING_LAYER==layer::COLLISION&&SELECTED_TRIGGER!=TriggerName::NONE) {
DrawStringPropDecal({2,2},Wrap("Editing Triggers - Selected "+TRIGGERS[SELECTED_TRIGGER],WIDTH-4,true,{1,1})); DrawStringPropDecal({2,2},Wrap("Editing Triggers - Selected "+TRIGGERS[SELECTED_TRIGGER],WIDTH-4,true,{1,1}));
for (auto&trigger:CURRENT_MAP->triggers) { DrawTriggers();
FillRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),Pixel(255,0,0,64));
DrawRectDecal(trigger->GetPos()-cameraPos,trigger->GetSize(),YELLOW);
vi2d textOffset={2,2};
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) {
if (IsTextEntryEnabled()) { if (IsTextEntryEnabled()) {
@ -3808,6 +3833,7 @@ void SeasonI::HandleCutscenes() {
case ActionType::LOAD_MAP:{ case ActionType::LOAD_MAP:{
class LoadMap*action=(class LoadMap*)CurrentCutscene->GetAction(); class LoadMap*action=(class LoadMap*)CurrentCutscene->GetAction();
Map*map=action->GetTargetMap(); Map*map=action->GetTargetMap();
CURRENT_MAP=map;
LoadMap(map); LoadMap(map);
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
@ -3817,6 +3843,9 @@ void SeasonI::HandleCutscenes() {
for (int i=0;i<PARTY_MEMBER_COUNT;i++) { for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(pos); PARTY_MEMBER_OBJ[i]->SetPos(pos);
} }
const vi2d cameraOffset={WIDTH/2,HEIGHT/2};
cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()-cameraOffset;
CurrentCutscene->AdvanceAction();
}break; }break;
} }
@ -5127,6 +5156,27 @@ void SeasonI::SetupCutscenes(){
}; };
} }
void SeasonI::DrawTriggers(){
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};
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});
}
}
void SeasonI::SetupMapList(){
int MAP_ENUM_COUNT=0;
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-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-1))},
};
}
#ifndef TEST_SUITE #ifndef TEST_SUITE
int main() int main()
{ {

@ -1,12 +0,0 @@
#include "pixelGameEngine.h"
#include "map.h"
using namespace olc;
extern std::map<std::string,Decal*> SPRITES;
int MAP_ENUM_COUNT=0;
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-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-1))},
};

@ -205,9 +205,6 @@ bool SeasonI::OnUserCreate(){
ITEMLIST[ItemName::FREEZE_PACKET]->description=="Lets out some blistering cold weather."); ITEMLIST[ItemName::FREEZE_PACKET]->description=="Lets out some blistering cold weather.");
Test("Freeze Packet drop chance is set properly", Test("Freeze Packet drop chance is set properly",
ITEMLIST[ItemName::FREEZE_PACKET]->dropChance==256); ITEMLIST[ItemName::FREEZE_PACKET]->dropChance==256);
for (int i=0;i<10000;i++) {
LoadMap(MAPS[MapName::ONETT]);
}
return true; return true;
} }

@ -46,9 +46,10 @@ class Trigger{
MapTransitionCutscene*scene=(MapTransitionCutscene*)CUTSCENES[CutsceneName::TRANSFER_MAP_CUTSCENE]; MapTransitionCutscene*scene=(MapTransitionCutscene*)CUTSCENES[CutsceneName::TRANSFER_MAP_CUTSCENE];
std::vector<CutsceneAction*>actions=scene->GetActions(); std::vector<CutsceneAction*>actions=scene->GetActions();
LoadMap*mapLoadAction=(LoadMap*)actions[1]; LoadMap*mapLoadAction=(LoadMap*)actions[1];
mapLoadAction->SetTargetMap(CURRENT_MAP); mapLoadAction->SetTargetMap(mapChoice);
MovePlayerObjects*playerMoveAction=(MovePlayerObjects*)actions[2]; MovePlayerObjects*playerMoveAction=(MovePlayerObjects*)actions[2];
playerMoveAction->SetTargetPos(HIGHLIGHTED_TILE); playerMoveAction->SetTargetPos(extraCoords);
GAME->StartCutscene(scene);
}break; }break;
} }
} }

Loading…
Cancel
Save