From 22c2c93126b1336e308cbbe2962d1bc6fd2be84f Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 4 Sep 2023 08:44:54 -0500 Subject: [PATCH] Fix Audio issue with nan positions. Enemies can squeeze through their buildings. --- olcCodeJam2023Entry/Unit.cpp | 18 +++++++++++++++--- olcCodeJam2023Entry/Unit.h | 2 ++ olcCodeJam2023Entry/VirusAttack.cpp | 13 +++++++++++-- olcCodeJam2023Entry/olcPGEX_AudioSource.h | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 8700cd6..4aae2c5 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -212,6 +212,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::vector>&otherUnits ,std::vector>&SOUNDS){ @@ -314,6 +315,7 @@ std::vector _Platform::resourceCost={{HEALTH,6}}; _Platform::_Platform(PixelGameEngine*pge,vf2d pos,std::vector>&IMAGES,bool friendly,bool moveable) :Unit(pge,_Platform::resourceCost,pos,24,*IMAGES[PLATFORM],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,false){ isPlatform=true; + platformStructure=true; } void _Platform::Attack(Unit&victim,std::vector>&otherUnits ,std::vector>&SOUNDS){}; @@ -360,7 +362,9 @@ std::string Refresher::unitDescription="Repairs missing bits to surrounding unit std::vector Refresher::resourceCost={{ATKSPD,3},{RANGE,1},{PROCEDURE,8},{HEALTH,4}}; Refresher::Refresher(PixelGameEngine*pge,vf2d pos,std::vector>&IMAGES,bool friendly,bool moveable) :Unit(pge,Refresher::resourceCost,pos,24,*IMAGES[REFRESHER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,false - ,true,false){} + ,true,false){ + platformStructure=true; +} void Refresher::Attack(Unit&victim,std::vector>&otherUnits ,std::vector>&SOUNDS){ target.reset(); //Doesn't acquire a target. @@ -393,7 +397,9 @@ std::string Turret::unitName="Turret"; std::string Turret::unitDescription="Automatically targets attack and movement speed memory ranges before others."; std::vector Turret::resourceCost={{ATKSPD,4},{RANGE,5},{HEALTH,6},{PROCEDURE,16}}; Turret::Turret(PixelGameEngine*pge,vf2d pos,std::vector>&IMAGES,bool friendly,bool moveable) - :Unit(pge,Turret::resourceCost,pos,24,*IMAGES[TURRET],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,false){} + :Unit(pge,Turret::resourceCost,pos,24,*IMAGES[TURRET],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,false){ + platformStructure=true; +} void Turret::Attack(Unit&victim,std::vector>&otherUnits ,std::vector>&SOUNDS){ if(victim.GetMoveSpd()>0){ @@ -438,7 +444,9 @@ std::string MemoryGuard::unitDescription="Reduces the chance of bit modification std::vector MemoryGuard::resourceCost={{HEALTH,10},{ATKSPD,4},{RANGE,4},{PROCEDURE,12}}; MemoryGuard::MemoryGuard(PixelGameEngine*pge,vf2d pos,std::vector>&IMAGES,bool friendly,bool moveable) :Unit(pge,MemoryGuard::resourceCost,pos,24,*IMAGES[MEMORY_GUARD],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,false - ,true,false){} + ,true,false){ + platformStructure=true; +} void MemoryGuard::Attack(Unit&victim,std::vector>&otherUnits ,std::vector>&SOUNDS){ target.reset(); //Doesn't acquire a target. @@ -1125,4 +1133,8 @@ Unit*Unit::GetBuildUnit(){ bool Unit::IsRAMBank(){ return isRAMBank; +} + +bool Unit::IsPlatformStructure(){ + return platformStructure; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 10cd29a..5451911 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -103,6 +103,8 @@ public: Marker atkSpd={}; Marker moveSpd={}; Marker procedure={}; + bool platformStructure=false; + bool IsPlatformStructure(); std::vector& operator <<=(const int n){ for(int i=0;iu,std::shared_ptr if(u->GetPos().y>WORLD_SIZE.y*CONSTANT::TILE_SIZE.y){ u->SetPos({u->GetPos().x,float(WORLD_SIZE.y*CONSTANT::TILE_SIZE.y)}); } - if(u!=u2&&geom2d::overlaps(geom2d::circle(u->GetPos(),u->GetUnitSize().x/2),geom2d::circle(u2->GetPos(),u2->GetUnitSize().x/2))){ + bool bothAreEnemies=!u->IsFriendly()&&!u2->IsFriendly(); + float u1Radius=u->GetUnitSize().x/2; + float u2Radius=u2->GetUnitSize().x/2; + if(bothAreEnemies){ + if(u->IsPlatformStructure()^u2->IsPlatformStructure()){ + u1Radius=u->IsPlatformStructure()?u->GetUnitSize().x/4:u1Radius; + u2Radius=u2->IsPlatformStructure()?u2->GetUnitSize().x/4:u2Radius; + } + } + if(u!=u2&&geom2d::overlaps(geom2d::circle(u->GetPos(),u1Radius),geom2d::circle(u2->GetPos(),u2Radius))){ geom2d::linecollisionLine(u->GetPos(),u2->GetPos()+vf2d{0.001,0.001}); - float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; + float maxDist=u1Radius+u1Radius; float dist=maxDist-collisionLine.length(); vf2d dir=collisionLine.vector().norm(); if(u->IsMoveable()||(!u->IsMoveable()&&!u2->IsMoveable())){ diff --git a/olcCodeJam2023Entry/olcPGEX_AudioSource.h b/olcCodeJam2023Entry/olcPGEX_AudioSource.h index 008cd8e..c53470e 100644 --- a/olcCodeJam2023Entry/olcPGEX_AudioSource.h +++ b/olcCodeJam2023Entry/olcPGEX_AudioSource.h @@ -166,7 +166,7 @@ int olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool int olcPGEX_AudioSource::Play(vf2d pos, float speed, float vol, bool looping, bool paused) { - if(!AL->bSoundOn)return -1; + if(!AL->bSoundOn||isnan(pos.x)||isnan(pos.y))return -1; // Set parameters fPlaySpeed = speed; fVolume = vol*std::max(0.f,abs(1-std::min(1.0f,(AL->GetDistance(pos)/1024.f))));