Fix player spawn locations being a whole tile off. Change map background scrolling to not be fixed, but to utilize the entire image across the span of a map. Add a foreground background layer to provide 2 potential parallax backgrounds. Release Build 9091.

This commit is contained in:
sigonasr2 2024-04-25 18:16:38 -05:00
parent 00b18355c1
commit 76c1396fec
11 changed files with 45 additions and 12 deletions

View File

@ -36,7 +36,9 @@
"type": "enum",
"values": [
"None",
"forest"
"forest",
"mountain_day",
"mountain_night"
],
"valuesAsFlags": false
},

View File

@ -85,6 +85,7 @@ All rights reserved.
INCLUDE_EMITTER_LIST
INCLUDE_ITEM_CATEGORIES
INCLUDE_BACKDROP_DATA
INCLUDE_FOREDROP_DATA
INCLUDE_MONSTER_DATA
INCLUDE_PACK_KEY
@ -1037,8 +1038,26 @@ void AiL::RenderWorld(float fElapsedTime){
}
#pragma region Basic Tile Layer Rendering
const MapTag&currentMap=GetCurrentMapData();
vf2d backgroundToMapRatio;
vf2d backgroundExcessAmount;
vf2d backgroundSize;
vf2d foregroundExcessAmount;
vf2d foregroundSize;
vf2d foregroundToMapRatio;
const vf2d mapPixelSize=currentMap.MapSize*currentMap.TileSize;
if(GetCurrentMap().backdrop.length()>0){
DrawPartialDecal({0,0},WINDOW_SIZE,BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),"Backdrop Config.Speed Ratio"_F*-camera.GetPosition()+view.GetWorldOffset(),WINDOW_SIZE);
backgroundSize=BACKDROP_DATA[GetCurrentMap().backdrop].Sprite()->Size();
backgroundExcessAmount=backgroundSize-vf2d(WINDOW_SIZE); //Extends outside the boundaries of the screen. Essentially the background size minus the size of the screen and take half to get the amount that extends in any one direction.
backgroundToMapRatio=1-(backgroundExcessAmount/mapPixelSize); //Expected range is from -half map size to +half map size.
DrawPartialDecal({},BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),backgroundToMapRatio*-camera.GetPosition()+view.GetWorldOffset()+WINDOW_SIZE/2,WINDOW_SIZE);
if(FOREDROP_DATA.count(GetCurrentMap().backdrop)){
foregroundSize=FOREDROP_DATA[GetCurrentMap().backdrop].Sprite()->Size();
foregroundExcessAmount=foregroundSize-vf2d(WINDOW_SIZE); //Extends outside the boundaries of the screen. Essentially the background size minus the size of the screen and take half to get the amount that extends in any one direction.
foregroundToMapRatio=1-(foregroundExcessAmount/mapPixelSize);
DrawPartialDecal({},FOREDROP_DATA[GetCurrentMap().backdrop].Decal(),foregroundToMapRatio*-camera.GetPosition()+view.GetWorldOffset()+WINDOW_SIZE/2,WINDOW_SIZE);
}
}else{
FillRectDecal({0,0},GetScreenSize(),{100,180,100});
}
@ -1144,7 +1163,8 @@ void AiL::RenderWorld(float fElapsedTime){
#pragma region Render Backdrop
if(GetCurrentMap().backdrop.length()>0){
vf2d tileWorldPos=vi2d{x,y}*GetCurrentMapData().tilewidth;
view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),"Backdrop Config.Speed Ratio"_F*-camera.GetPosition()+tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),backgroundToMapRatio*-camera.GetPosition()+tileWorldPos+WINDOW_SIZE/2,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
if(FOREDROP_DATA.count(GetCurrentMap().backdrop))view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},FOREDROP_DATA[GetCurrentMap().backdrop].Decal(),foregroundToMapRatio*-camera.GetPosition()+tileWorldPos+WINDOW_SIZE/2,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
}else{
view.FillRectDecal(vi2d{x,y}*GetCurrentMapData().tilewidth,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},{100,180,100});
}
@ -1174,7 +1194,8 @@ void AiL::RenderWorld(float fElapsedTime){
}else{
if(GetCurrentMap().backdrop.length()>0){
vf2d tileWorldPos=vi2d{x,y}*GetCurrentMapData().tilewidth;
view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),"Backdrop Config.Speed Ratio"_F*-camera.GetPosition()+tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},BACKDROP_DATA[GetCurrentMap().backdrop].Decal(),backgroundToMapRatio*-camera.GetPosition()+tileWorldPos+WINDOW_SIZE/2,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
if(FOREDROP_DATA.count(GetCurrentMap().backdrop))view.DrawPartialDecal(tileWorldPos,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},FOREDROP_DATA[GetCurrentMap().backdrop].Decal(),foregroundToMapRatio*-camera.GetPosition()+tileWorldPos+WINDOW_SIZE/2,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)});
}else{
view.FillRectDecal(vi2d{x,y}*GetCurrentMapData().tilewidth,{float(GetCurrentMapData().tilewidth),float(GetCurrentMapData().tilewidth)},{100,180,100});
}
@ -3008,6 +3029,7 @@ bool AiL::OnUserDestroy(){
delete value;
}
BACKDROP_DATA.clear();
FOREDROP_DATA.clear();
return true;
}else{
return false; //Something is preventing us from quitting. We wait patiently...
@ -3047,6 +3069,10 @@ void AiL::InitializeLevels(){
Renderable&backdrop=BACKDROP_DATA[key];
LoadResource(backdrop,"backdrop_directory"_S+DATA["Backdrops"][key].GetString(),false,false);
}
for(auto&[key,size]:DATA["Foredrops"]){
Renderable&backdrop=FOREDROP_DATA[key];
LoadResource(backdrop,"backdrop_directory"_S+DATA["Foredrops"][key].GetString(),false,false);
}
Test::RunMapTests();
}

View File

@ -62,6 +62,7 @@ using BackdropName=std::string;
#define INCLUDE_PACK_KEY extern std::string PACK_KEY;
#define INCLUDE_BACKDROP_DATA extern std::map<BackdropName,Renderable>BACKDROP_DATA;
#define INCLUDE_FOREDROP_DATA extern std::map<BackdropName,Renderable>FOREDROP_DATA;
#define INCLUDE_CENTERED extern const vf2d Menu::CENTERED;

View File

@ -46,6 +46,7 @@ using BackdropName=std::string;
float TileGroup::FADE_TIME=0.3f;
uint8_t TileGroup::FADE_AMT=160;
std::map<BackdropName,Renderable>BACKDROP_DATA;
std::map<BackdropName,Renderable>FOREDROP_DATA;
Map&MapHelper::MapFromString(std::string mapName){
return game->MAP_DATA.at(mapName);

View File

@ -886,4 +886,5 @@ const Direction Monster::GetFacingDirectionToTarget(vf2d target)const{
else if(targetDirection>=-3*PI/4&&targetDirection<-PI/4)return Direction::NORTH;
ERR(std::format("WARNING! Target direction {} did not result in a proper facing direction!! THIS SHOULD NOT BE HAPPENING!",targetDirection));
return Direction::NORTH;
}

View File

@ -507,7 +507,7 @@ class TMXParser{
float height=1.f;
if(newTag.data.count("width")>0)width=newTag.GetFloat("width");
if(newTag.data.count("height")>0)height=newTag.GetFloat("height");
parsedMapInfo.MapData.playerSpawnLocation={int(newTag.GetFloat("x")-width/2),int(newTag.GetFloat("y")-height/2)};
parsedMapInfo.MapData.playerSpawnLocation={int(newTag.GetFloat("x")+width/2),int(newTag.GetFloat("y")+height/2)};
}else
if (newTag.tag=="object"&&newTag.data["type"]=="NPC") {
if(inNPCTag)parsedMapInfo.npcs.push_back(NPCData{npcTag});

View File

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 9037
#define VERSION_BUILD 9091
#define stringify(a) stringify_(a)
#define stringify_(a) #a

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="238" height="369" tilewidth="24" tileheight="24" infinite="0" nextlayerid="7" nextobjectid="20">
<map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="238" height="369" tilewidth="24" tileheight="24" infinite="0" nextlayerid="7" nextobjectid="27">
<properties>
<property name="Backdrop" propertytype="Backdrop" value="None"/>
<property name="Backdrop" propertytype="Backdrop" value="mountain_day"/>
<property name="Background Music" propertytype="BGM" value="foresty1_1"/>
<property name="Level Type" propertytype="LevelType" value="Dungeon"/>
</properties>
@ -1876,7 +1876,6 @@
</data>
</layer>
<objectgroup id="5" name="Spawn Zones">
<object id="1" name="Player Spawn" type="PlayerSpawnLocation" x="5112" y="8064" width="24" height="24"/>
<object id="2" name="Time Trial Clock" type="TrialClock" x="5112" y="8016" width="24" height="24"/>
<object id="5" name="End Ring" type="EndZone" x="3349" y="165" width="145" height="145"/>
<object id="15" name="Spawn Group 1" type="SpawnGroup" x="4439" y="7869" width="496" height="424">
@ -1897,5 +1896,6 @@
<property name="spawner" type="object" value="15"/>
</properties>
</object>
<object id="26" name="Player Spawn" type="PlayerSpawnLocation" x="265" y="1848" width="24" height="24"/>
</objectgroup>
</map>

View File

@ -1,10 +1,12 @@
Backdrops
{
forest = forest_backdrop.png
mountain_day = commercial_assets/Mountain Range Day.png
mountain_night = commercial_assets/Mountain Range Night.png
}
Backdrop Config
Foredrops
{
# Amount to move per pixel of actual world space.
Speed Ratio = 0.125
mountain_day = commercial_assets/Mountain Range Day Foreground.png
mountain_night = commercial_assets/Mountain Range Night Foreground.png
}