Scale correction on right edge of camera.

main
sigonasr2 3 months ago
parent f47d49417b
commit 66622c84f7
  1. 2
      .gitignore
  2. 1010
      assets/TestLevel.tmx
  3. 4
      hamster.vcxproj.user
  4. 10
      src/Hamster.cpp
  5. 2
      src/Hamster.h
  6. 15
      src/HamsterGame.cpp
  7. 4
      src/olcUTIL_Camera2D.h

2
.gitignore vendored

@ -16,3 +16,5 @@ vs-build
/bin/hamster.pdb
/hamster.exe
/.vs/cmake.db
/hamster.dir/Release
/x64/Release

File diff suppressed because it is too large Load Diff

@ -4,4 +4,8 @@
<LocalDebuggerWorkingDirectory>C:/Users/sigon/source/repos/hamster</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>C:/Users/sigon/source/repos/hamster</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

@ -176,6 +176,12 @@ void Hamster::HandlePlayerControls(){
if(HamsterGame::Game().GetKey(A).bHeld){
aimingDir+=vf2d{-1,0};
}
if(HamsterGame::Game().GetKey(PGUP).bHeld){
z+=HamsterGame::Game().GetElapsedTime();
}
if(HamsterGame::Game().GetKey(PGDN).bHeld){
z=std::max(0.f,z-HamsterGame::Game().GetElapsedTime());
}
if(aimingDir!=vf2d{}){
targetRot=aimingDir.norm().polar().y;
const vf2d currentVel{vel};
@ -321,4 +327,8 @@ const float Hamster::GetDrownRatio()const{
}
const float Hamster::GetBurnRatio()const{
return burnTimer/DEFAULT_BURN_TIME;
}
const float&Hamster::GetZ()const{
return z;
}

@ -77,6 +77,7 @@ class Hamster{
vf2d pos;
vf2d vel;
vf2d lastSafeLocation{};
float z;
float lastSafeLocationTimer{};
float rot{};
float targetRot{};
@ -104,6 +105,7 @@ public:
static void DrawHamsters(TransformedView&tv);
const Animate2D::Frame&GetCurrentAnimation()const;
const vf2d&GetPos()const;
const float&GetZ()const;
void HandlePlayerControls();
void TurnTowardsTargetDirection();
void MoveHamster();

@ -19,7 +19,6 @@ bool HamsterGame::OnUserCreate(){
camera=Camera2D{SCREEN_FRAME.size};
camera.SetMode(Camera2D::Mode::LazyFollow);
tv.Initialise(SCREEN_FRAME.size,{1,1});
tv.SetWorldOffset(-SCREEN_FRAME.pos);
LoadGraphics();
LoadAnimations();
currentTileset=TSXParser{ASSETS_DIR+std::string("Terrain.tsx")};
@ -96,8 +95,14 @@ void HamsterGame::LoadLevel(const std::string_view mapName){
}
void HamsterGame::UpdateGame(const float fElapsedTime){
/*if(Hamster::GetPlayer().GetZ()>1.f){
tv.SetZoom(1.f/sqrt(Hamster::GetPlayer().GetZ()),tv.WorldToScreen(Hamster::GetPlayer().GetPos())-SCREEN_FRAME.pos);
}else{
tv.SetZoom(1.f,tv.WorldToScreen(Hamster::GetPlayer().GetPos())-SCREEN_FRAME.pos);
}*/
camera.Update(fElapsedTime);
tv.SetWorldOffset(-SCREEN_FRAME.pos+camera.GetViewPosition());
tv.HandlePanAndZoom();
//std::cout<<tv.GetWorldScale().str()<<std::endl;
Hamster::UpdateHamsters(fElapsedTime);
Powerup::UpdatePowerups(fElapsedTime);
border.Update(fElapsedTime);
@ -156,9 +161,13 @@ const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const
}
void HamsterGame::DrawLevelTiles(){
float extendedBounds{SCREEN_FRAME.pos.x};
extendedBounds*=1/tv.GetWorldScale().x;
std::cout<<tv.GetWorldTL().str()<<std::endl;
std::cout<<tv.GetWorldBR().str()<<std::endl;
for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){
for(float y=tv.GetWorldTL().y-16;y<=tv.GetWorldBR().y+16;y+=16){
for(float x=tv.GetWorldTL().x-1+SCREEN_FRAME.pos.x;x<=tv.GetWorldBR().x+16+SCREEN_FRAME.pos.x;x+=16){
for(float x=tv.GetWorldTL().x-1+extendedBounds;x<=tv.GetWorldBR().x+16+extendedBounds;x+=16){
if(x<=0.f||y<=0.f||x>=currentMap.value().GetData().GetMapData().width*16||y>=currentMap.value().GetData().GetMapData().height*16)continue;
const int numTilesWide{GetGFX("gametiles.png").Sprite()->width/16};
const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16};

@ -135,6 +135,10 @@ namespace olc::utils
m_vWorldBoundarySize = vSize;
}
inline void SetViewSize(const olc::vf2d&vSize){
m_vViewSize = vSize;
}
// Instruct camera to respect world boundaries
inline void EnableWorldBoundary(const bool bEnable)
{

Loading…
Cancel
Save