Navigation between unlocked stages is now possible.
This commit is contained in:
parent
54614d31dc
commit
4f65d2240a
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include "olcUTIL_Geometry2D.h"
|
||||
|
||||
struct ConnectionPoint{
|
||||
@ -5,8 +6,8 @@ struct ConnectionPoint{
|
||||
std::string name;
|
||||
std::string map;
|
||||
std::string unlockCondition;
|
||||
std::array<int,4>neighbors; //Indices into the connectionPoint array.
|
||||
ConnectionPoint(geom2d::rect<float>rect,std::string name,std::string map,std::string unlockCondition)
|
||||
std::array<int,8>neighbors; //Indices into the connectionPoint array.
|
||||
inline ConnectionPoint(geom2d::rect<float>rect,std::string name,std::string map,std::string unlockCondition)
|
||||
:rect(rect),name(name),map(map),unlockCondition(unlockCondition){
|
||||
neighbors.fill(-1);
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "GameState.h"
|
||||
#include "Item.h"
|
||||
#include "Toggleable.h"
|
||||
#include "Unlock.h"
|
||||
#include "State_OverworldMap.h"
|
||||
|
||||
INCLUDE_EMITTER_LIST
|
||||
|
||||
@ -144,6 +146,8 @@ bool Crawler::OnUserCreate(){
|
||||
|
||||
GameState::Initialize();
|
||||
|
||||
Unlock::Initialize();
|
||||
|
||||
ValidateGameStatus(); //Checks to make sure everything has been initialized properly.
|
||||
|
||||
return true;
|
||||
@ -156,6 +160,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
|
||||
RenderWorld(GetElapsedTime());
|
||||
GameState::STATE->Draw(this);
|
||||
RenderMenu();
|
||||
RenderVersionInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1054,8 +1059,6 @@ void Crawler::RenderHud(){
|
||||
DrawShadowStringPropDecal(vf2d{float(ScreenWidth()/2),float(ScreenHeight()/4)-24}-GetTextSizeProp(displayText)/2,displayText,BLUE,VERY_DARK_BLUE);
|
||||
}
|
||||
DisplayBossEncounterInfo();
|
||||
std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD));
|
||||
DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4,versionStr,WHITE,BLACK,{0.4,0.4},0.4);
|
||||
if("debug_player_info"_I){
|
||||
DrawShadowStringDecal({0,128},player->GetPos().str());
|
||||
DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult()));
|
||||
@ -1543,7 +1546,7 @@ datafiledoubledata Crawler::GetDoubleList(std::string key){
|
||||
int main()
|
||||
{
|
||||
Crawler demo;
|
||||
if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4, false))
|
||||
if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4))
|
||||
demo.Start();
|
||||
|
||||
return 0;
|
||||
@ -1828,4 +1831,17 @@ void Crawler::ValidateGameStatus(){
|
||||
std::cout<<"Error TOGGLE!!! Please turn on debug_toggleable_items in configuration.txt and re-run the program to see which toggleable item did not properly get a toggleable group set."<<std::endl;
|
||||
throw;
|
||||
}
|
||||
if(Unlock::unlocks.size()==0){
|
||||
std::cout<<"WARNING! There are no unlocks set! This was probably not intentional! It means no areasa on the overworld are accessible!"<<std::endl;
|
||||
throw;
|
||||
}
|
||||
if(!Unlock::IsUnlocked(State_OverworldMap::GetCurrentConnectionPoint())){
|
||||
std::cout<<"WARNING! The current connection point is not unlocked! This is not supposed to be happening."<<std::endl;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void Crawler::RenderVersionInfo(){
|
||||
std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD));
|
||||
DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4,versionStr,WHITE,BLACK,{0.4,0.4},0.4);
|
||||
}
|
@ -133,6 +133,7 @@ public:
|
||||
void BossDamageDealt(int damage);
|
||||
void ReduceBossEncounterMobCount();
|
||||
void InitializeGraphics();
|
||||
void RenderVersionInfo();
|
||||
MapTag GetCurrentMap();
|
||||
|
||||
struct TileGroupData{
|
||||
|
@ -310,6 +310,7 @@
|
||||
<ClInclude Include="TMXParser.h" />
|
||||
<ClInclude Include="Toggleable.h" />
|
||||
<ClInclude Include="TSXParser.h" />
|
||||
<ClInclude Include="Unlock.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
<ClInclude Include="Version.h" />
|
||||
</ItemGroup>
|
||||
@ -360,6 +361,7 @@
|
||||
<ClCompile Include="Thief.cpp" />
|
||||
<ClCompile Include="Trapper.cpp" />
|
||||
<ClCompile Include="Turret.cpp" />
|
||||
<ClCompile Include="Unlock.cpp" />
|
||||
<ClCompile Include="Warrior.cpp" />
|
||||
<ClCompile Include="utils.cpp" />
|
||||
<ClCompile Include="Witch.cpp" />
|
||||
|
@ -225,6 +225,9 @@
|
||||
<ClInclude Include="State_MainMenu.h">
|
||||
<Filter>Header Files\State</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Unlock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
@ -377,6 +380,9 @@
|
||||
<ClCompile Include="State_OverworldMap.cpp">
|
||||
<Filter>Source Files\Game States</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Unlock.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include "Crawler.h"
|
||||
#include "DEFINES.h"
|
||||
#include "Menu.h"
|
||||
#include "Unlock.h"
|
||||
#include "ConnectionPoint.h"
|
||||
#include "utils.h"
|
||||
|
||||
INCLUDE_MONSTER_LIST
|
||||
INCLUDE_game
|
||||
@ -14,7 +17,8 @@ State_OverworldMap::State_OverworldMap(){
|
||||
}
|
||||
void State_OverworldMap::OnStateChange(GameState*prevState){
|
||||
Menu::CloseAllMenus();
|
||||
game->GetPlayer()->SetPos(currentConnectionPoint->rect.pos);
|
||||
game->GetPlayer()->SetPos(currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16});
|
||||
playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16};
|
||||
game->GetPlayer()->UpdateWalkingAnimation(DOWN);
|
||||
game->GetPlayer()->SetState(State::FORCE_WALK);
|
||||
game->GetPlayer()->SetSizeMult(1);
|
||||
@ -23,6 +27,40 @@ void State_OverworldMap::OnUserUpdate(Crawler*game){
|
||||
game->camera.SetTarget(currentConnectionPoint->rect.middle());
|
||||
game->UpdateCamera(game->GetElapsedTime());
|
||||
game->GetPlayer()->Update(game->GetElapsedTime());
|
||||
|
||||
if(game->GetPlayer()->GetPos()!=playerTargetPos){
|
||||
if(geom2d::line<float>(game->GetPlayer()->GetPos(),playerTargetPos).length()<2){
|
||||
game->GetPlayer()->SetPos(playerTargetPos);
|
||||
}else{
|
||||
game->GetPlayer()->SetPos(game->GetPlayer()->GetPos()+util::pointTo(game->GetPlayer()->GetPos(),playerTargetPos)*playerMoveSpd*game->GetElapsedTime());
|
||||
}
|
||||
}
|
||||
|
||||
for(ConnectionPoint&cp:connections){
|
||||
if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){
|
||||
for(int neighborInd:currentConnectionPoint->neighbors){
|
||||
if(neighborInd==-1)continue;
|
||||
ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd);
|
||||
if(Unlock::IsUnlocked(neighbor.name)&&&cp==&neighbor){
|
||||
currentConnectionPoint=&neighbor;
|
||||
playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16};
|
||||
float angleTo=util::angleTo(game->GetPlayer()->GetPos(),playerTargetPos);
|
||||
if(angleTo>=-3*PI/4&&angleTo<-PI/4){
|
||||
game->GetPlayer()->UpdateWalkingAnimation(UP);
|
||||
}else
|
||||
if(angleTo<PI/4&&angleTo>=-PI/4){
|
||||
game->GetPlayer()->UpdateWalkingAnimation(RIGHT);
|
||||
}else
|
||||
if(angleTo>=PI/4&&angleTo<3*PI/4){
|
||||
game->GetPlayer()->UpdateWalkingAnimation(DOWN);
|
||||
}else{
|
||||
game->GetPlayer()->UpdateWalkingAnimation(LEFT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
void State_OverworldMap::Draw(Crawler*game){
|
||||
currentTime+=game->GetElapsedTime();
|
||||
@ -73,3 +111,11 @@ void State_OverworldMap::SetStageMarker(std::string connectionName){
|
||||
std::cout<<"WARNING! Could not find a connection point with name "<<connectionName<<"!"<<std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
ConnectionPoint&State_OverworldMap::ConnectionPointFromIndex(int ind){
|
||||
return connections.at(ind);
|
||||
}
|
||||
|
||||
ConnectionPoint&State_OverworldMap::GetCurrentConnectionPoint(){
|
||||
return *((State_OverworldMap*)(GameState::states.at(States::OVERWORLD_MAP)))->currentConnectionPoint;
|
||||
}
|
@ -3,12 +3,17 @@
|
||||
#include "ConnectionPoint.h"
|
||||
|
||||
class State_OverworldMap:public GameState{
|
||||
friend class Crawler;
|
||||
ConnectionPoint*currentConnectionPoint;
|
||||
float currentTime;
|
||||
vf2d playerTargetPos;
|
||||
const float playerMoveSpd=48.0;
|
||||
public:
|
||||
State_OverworldMap();
|
||||
static std::vector<ConnectionPoint>connections;
|
||||
static ConnectionPoint&GetCurrentConnectionPoint();
|
||||
void SetStageMarker(std::string connectionName);
|
||||
ConnectionPoint&ConnectionPointFromIndex(int ind);
|
||||
virtual void OnStateChange(GameState*prevState)override;
|
||||
virtual void OnUserUpdate(Crawler*game)override;
|
||||
virtual void Draw(Crawler*game)override;
|
||||
|
@ -416,13 +416,28 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
State_OverworldMap::connections.push_back(newConnection);
|
||||
}
|
||||
for(ConnectionPoint&connection:State_OverworldMap::connections){
|
||||
std::array<int,4>;
|
||||
for(int&val:connection.neighbors){
|
||||
if(idToIndexMap.count(val)){
|
||||
val=idToIndexMap.at(val); //Convert from given Tiled ID to indexed ID in State_OverworldMap::connections
|
||||
}
|
||||
}
|
||||
}
|
||||
int counter=0;
|
||||
for(ConnectionPoint&connection:State_OverworldMap::connections){
|
||||
for(int val:connection.neighbors){
|
||||
if(val!=-1){
|
||||
ConnectionPoint&neighbor=State_OverworldMap::connections.at(val);
|
||||
//Find a blank slot that is available.
|
||||
for(int i=0;i<neighbor.neighbors.size();i++){
|
||||
if(neighbor.neighbors[i]==-1){ //We insert our neighbor pairing here.
|
||||
neighbor.neighbors[i]=counter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
|
||||
}
|
||||
|
21
Crawler/Unlock.cpp
Normal file
21
Crawler/Unlock.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "Unlock.h"
|
||||
|
||||
std::set<std::string>Unlock::unlocks;
|
||||
|
||||
void Unlock::Initialize(){
|
||||
UnlockArea("Stage I-I");
|
||||
UnlockArea("Shop I");
|
||||
UnlockArea("Blacksmith I");
|
||||
UnlockArea("Stage I-II");
|
||||
}
|
||||
|
||||
void Unlock::UnlockArea(std::string unlock){
|
||||
unlocks.insert(unlock);
|
||||
}
|
||||
bool Unlock::IsUnlocked(std::string unlock){
|
||||
return unlocks.count(unlock);
|
||||
}
|
||||
|
||||
bool Unlock::IsUnlocked(ConnectionPoint&cp){
|
||||
return unlocks.count(cp.name);
|
||||
}
|
14
Crawler/Unlock.h
Normal file
14
Crawler/Unlock.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "ConnectionPoint.h"
|
||||
|
||||
class Unlock{
|
||||
friend class Crawler;
|
||||
static std::set<std::string>unlocks;
|
||||
static void Initialize();
|
||||
public:
|
||||
static void UnlockArea(std::string unlock);
|
||||
static bool IsUnlocked(std::string unlock);
|
||||
static bool IsUnlocked(ConnectionPoint&cp);
|
||||
};
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 2485
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 2513
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user