diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 23c2ea0..7ee4257 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -345,7 +345,7 @@ void Unit::DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std: if(reloadTimer>0){ util::ApplyMatrixEffect(game.GetPGE(),attackingLine,*IMAGES[ATTACKING_LINE],IMAGES[MATRIX]); float reloadSpd=1.f/(GetAtkSpd()/2.f); - game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),attackingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*30,0},{lineToTarget.length(),24},{1,1+(reloadTimer/reloadSpd)*0.25f},{attackingLineCol.r,attackingLineCol.g,attackingLineCol.b,uint8_t(IsFriendly()?200:160)}); + game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),attackingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*30,0},{lineToTarget.length(),24},{1,1+(attackFailed?-0.3f:(reloadTimer/reloadSpd)*0.25f)},attackFailed?Pixel{192,192,192,130}:Pixel{attackingLineCol.r,attackingLineCol.g,attackingLineCol.b,uint8_t(IsFriendly()?200:160)}); } } float dist=geom2d::line(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length(); @@ -564,14 +564,21 @@ void Unit::_Attacked(std::weak_ptrattacker){ } void Unit::_Attack(std::weak_ptrattacker,std::weak_ptrfinalTarget,std::vector>&otherUnits){ - if(GetAtkSpd()>0){ - Attack(*finalTarget.lock(),otherUnits); - finalTarget.lock()->_Attacked(attacker); - reloadTimer=1.f/(GetAtkSpd()/2.f); - if(GetCurrentTarget().expired()&&!IsFriendly()){ - if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ - SetTargetUnit(finalTarget); + if(GetProcedure()>0&&GetAtkSpd()>0){ + attackFailed=false; + float procChance=float(GetProcedure())/procedure.size; + if(util::random(1)>=1-procChance){ + Attack(*finalTarget.lock(),otherUnits); + finalTarget.lock()->_Attacked(attacker); + reloadTimer=1.f/(GetAtkSpd()/2.f); + if(GetCurrentTarget().expired()&&!IsFriendly()){ + if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ + SetTargetUnit(finalTarget); + } } + } else { + reloadTimer=1.f/(GetAtkSpd()/2.f); + attackFailed=true; } } } diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 1151c49..69d26c7 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -107,6 +107,7 @@ protected: bool InRange(Unit*target); bool InRange(vf2d pos); float reloadTimer=0; + bool attackFailed=false; bool autoAcquireFriendlyTarget=true; private: Renderable targetingLine; diff --git a/olcCodeJam2023Entry/assets/prc_icon.png b/olcCodeJam2023Entry/assets/prc_icon.png new file mode 100644 index 0000000..bc44396 Binary files /dev/null and b/olcCodeJam2023Entry/assets/prc_icon.png differ diff --git a/olcCodeJam2023Entry/assets/rld_icon.png b/olcCodeJam2023Entry/assets/rld_icon.png new file mode 100644 index 0000000..5e677ed Binary files /dev/null and b/olcCodeJam2023Entry/assets/rld_icon.png differ diff --git a/olcCodeJam2023Entry/assets/rng_icon.png b/olcCodeJam2023Entry/assets/rng_icon.png new file mode 100644 index 0000000..f2278e8 Binary files /dev/null and b/olcCodeJam2023Entry/assets/rng_icon.png differ diff --git a/olcCodeJam2023Entry/assets/spd_icon.png b/olcCodeJam2023Entry/assets/spd_icon.png new file mode 100644 index 0000000..8aa40c3 Binary files /dev/null and b/olcCodeJam2023Entry/assets/spd_icon.png differ