Fix Audio issue with nan positions. Enemies can squeeze through their buildings.

master
sigonasr2 1 year ago
parent 25b1e808a1
commit 22c2c93126
  1. 18
      olcCodeJam2023Entry/Unit.cpp
  2. 2
      olcCodeJam2023Entry/Unit.h
  3. 13
      olcCodeJam2023Entry/VirusAttack.cpp
  4. 2
      olcCodeJam2023Entry/olcPGEX_AudioSource.h

@ -212,6 +212,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_ptr<Render
allocatorManager.colText = olc::WHITE;
allocatorButton = new QuickGUI::ImageButton(allocatorManager,*IMAGES[UNIT_ALLOCATOR],{0.5f,0.5f},pos-vf2d{8,48},{20,20});
isRAMBank=true;
platformStructure=true;
}
void RAMBank::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){
@ -314,6 +315,7 @@ std::vector<Memory> _Platform::resourceCost={{HEALTH,6}};
_Platform::_Platform(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_ptr<Renderable>>&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<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){};
@ -360,7 +362,9 @@ std::string Refresher::unitDescription="Repairs missing bits to surrounding unit
std::vector<Memory> Refresher::resourceCost={{ATKSPD,3},{RANGE,1},{PROCEDURE,8},{HEALTH,4}};
Refresher::Refresher(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_ptr<Renderable>>&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<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&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<Memory> Turret::resourceCost={{ATKSPD,4},{RANGE,5},{HEALTH,6},{PROCEDURE,16}};
Turret::Turret(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_ptr<Renderable>>&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<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){
if(victim.GetMoveSpd()>0){
@ -438,7 +444,9 @@ std::string MemoryGuard::unitDescription="Reduces the chance of bit modification
std::vector<Memory> MemoryGuard::resourceCost={{HEALTH,10},{ATKSPD,4},{RANGE,4},{PROCEDURE,12}};
MemoryGuard::MemoryGuard(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_ptr<Renderable>>&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<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){
target.reset(); //Doesn't acquire a target.
@ -1126,3 +1134,7 @@ Unit*Unit::GetBuildUnit(){
bool Unit::IsRAMBank(){
return isRAMBank;
}
bool Unit::IsPlatformStructure(){
return platformStructure;
}

@ -103,6 +103,8 @@ public:
Marker atkSpd={};
Marker moveSpd={};
Marker procedure={};
bool platformStructure=false;
bool IsPlatformStructure();
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){

@ -890,9 +890,18 @@ void VirusAttack::CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>
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<float>(u->GetPos(),u->GetUnitSize().x/2),geom2d::circle<float>(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<float>(u->GetPos(),u1Radius),geom2d::circle<float>(u2->GetPos(),u2Radius))){
geom2d::line<float>collisionLine(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())){

@ -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))));

Loading…
Cancel
Save