Fix minor bugs and levels. Ready to go. Final post-fix feature build.
This commit is contained in:
parent
a4439afc3f
commit
1a07786e7a
@ -143,6 +143,37 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!u->IsFriendly()&&u->IsPlatform()){
|
||||||
|
std::array<UnitType,7>unitChoiceList={UnitType::RAMBank,UnitType::Refresher,UnitType::Refresher,UnitType::Turret,
|
||||||
|
UnitType::Turret,UnitType::Turret,UnitType::MemoryGuard};
|
||||||
|
std::array<std::vector<Memory>,7>unitResourceCostList={RAMBank::resourceCost,Refresher::resourceCost,Refresher::resourceCost,Turret::resourceCost,
|
||||||
|
Turret::resourceCost,Turret::resourceCost,MemoryGuard::resourceCost};
|
||||||
|
int randomIndex=rand()%unitChoiceList.size();
|
||||||
|
UnitType buildUnit=unitChoiceList[randomIndex];
|
||||||
|
|
||||||
|
int totalCost=0;
|
||||||
|
for(int i=0;i<unitResourceCostList[randomIndex].size();i++){
|
||||||
|
totalCost+=unitResourceCostList[randomIndex][i].size;
|
||||||
|
}
|
||||||
|
if(totalCost<=availableMemory){
|
||||||
|
#define Build(type) \
|
||||||
|
case UnitType::type:{ \
|
||||||
|
u->SetBuildUnit(8,std::make_shared<type>(game.GetPGE(),u->GetPos(),IMAGES,false),SOUNDS); \
|
||||||
|
}break;
|
||||||
|
switch(buildUnit){
|
||||||
|
Build(RAMBank)
|
||||||
|
Build(Refresher)
|
||||||
|
Build(Turret)
|
||||||
|
Build(MemoryGuard)
|
||||||
|
}
|
||||||
|
if(enemy_resources.health>0){enemy_resources.health=std::max(0,enemy_resources.health-totalCost);}else
|
||||||
|
if(enemy_resources.atkSpd>0){enemy_resources.atkSpd=std::max(0,enemy_resources.atkSpd-totalCost);}else
|
||||||
|
if(enemy_resources.moveSpd>0){enemy_resources.moveSpd=std::max(0,enemy_resources.moveSpd-totalCost);}else
|
||||||
|
if(enemy_resources.range>0){enemy_resources.range=std::max(0,enemy_resources.range-totalCost);}else
|
||||||
|
{enemy_resources.procedure=std::max(0,enemy_resources.procedure-totalCost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
switch(flags.difficulty){
|
switch(flags.difficulty){
|
||||||
case 0:{
|
case 0:{
|
||||||
unitBuildTimer=120;
|
unitBuildTimer=120;
|
||||||
|
@ -727,6 +727,7 @@ void Unit::_Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUND
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!attachedPoint.expired()){
|
if(!attachedPoint.expired()){
|
||||||
|
SetPos(attachedPoint.lock()->pos+vf2d{cos(float(attachedPoint.lock()->rot+PI/2))*16,sin(float(attachedPoint.lock()->rot+PI/2))*16});
|
||||||
collectionTime-=pge->GetElapsedTime();
|
collectionTime-=pge->GetElapsedTime();
|
||||||
if(collectionTime<=0){
|
if(collectionTime<=0){
|
||||||
collectionTime=CONSTANT::COLLECTION_WAIT_TIME;
|
collectionTime=CONSTANT::COLLECTION_WAIT_TIME;
|
||||||
@ -939,11 +940,26 @@ void Unit::Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUNDS
|
|||||||
|
|
||||||
void Unit::Attacked(std::weak_ptr<Unit>attacker){}
|
void Unit::Attacked(std::weak_ptr<Unit>attacker){}
|
||||||
|
|
||||||
void Unit::_Attacked(std::weak_ptr<Unit>attacker){
|
void Unit::_Attacked(std::weak_ptr<Unit>attacker,std::vector<std::shared_ptr<Unit>>&otherUnits){
|
||||||
Attacked(attacker);
|
Attacked(attacker);
|
||||||
if(attacker.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){
|
if(attacker.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){
|
||||||
SetTargetUnit(attacker);
|
SetTargetUnit(attacker);
|
||||||
}
|
}
|
||||||
|
if(attacker.lock()->IsFriendly()!=IsFriendly()){
|
||||||
|
for(auto&u:otherUnits){
|
||||||
|
if(this!=u.get()&&!u->IsFriendly()&&u->GetCurrentTarget().expired()&&u->CanMove()&&!u->IsAllocator()){
|
||||||
|
geom2d::line<float>distLine={GetPos(),u->GetPos()};
|
||||||
|
if(distLine.length()<320){
|
||||||
|
if(u->CanInteractWithEnemies()){
|
||||||
|
u->SetTargetUnit(attacker);
|
||||||
|
}else
|
||||||
|
if(u->CanInteractWithAllies()){
|
||||||
|
u->SetTargetLocation(GetPos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::_Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits,std::vector<std::unique_ptr<Audio>>&SOUNDS){
|
void Unit::_Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits,std::vector<std::unique_ptr<Audio>>&SOUNDS){
|
||||||
@ -952,25 +968,12 @@ void Unit::_Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,st
|
|||||||
float procChance=float(GetProcedure())/procedure.size;
|
float procChance=float(GetProcedure())/procedure.size;
|
||||||
if(util::random(1)>=1-procChance){
|
if(util::random(1)>=1-procChance){
|
||||||
Attack(*finalTarget.lock(),otherUnits,SOUNDS);
|
Attack(*finalTarget.lock(),otherUnits,SOUNDS);
|
||||||
finalTarget.lock()->_Attacked(attacker);
|
finalTarget.lock()->_Attacked(attacker,otherUnits);
|
||||||
reloadTimer=1.f/(GetAtkSpd()/2.f);
|
reloadTimer=1.f/(GetAtkSpd()/2.f);
|
||||||
if(GetCurrentTarget().expired()&&!IsFriendly()){
|
if(GetCurrentTarget().expired()&&!IsFriendly()){
|
||||||
if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){
|
if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){
|
||||||
SetTargetUnit(finalTarget);
|
SetTargetUnit(finalTarget);
|
||||||
}
|
}
|
||||||
for(auto&u:otherUnits){
|
|
||||||
if(this!=u.get()&&!u->IsFriendly()&&u->GetCurrentTarget().expired()){
|
|
||||||
geom2d::line<float>distLine={GetPos(),u->GetPos()};
|
|
||||||
if(distLine.length()<200){
|
|
||||||
if(u->CanInteractWithEnemies()){
|
|
||||||
u->SetTargetUnit(finalTarget);
|
|
||||||
}else
|
|
||||||
if(u->CanInteractWithAllies()){
|
|
||||||
u->SetTargetLocation(GetPos());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reloadTimer=1.f/(GetAtkSpd()/2.f);
|
reloadTimer=1.f/(GetAtkSpd()/2.f);
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
virtual void RunAI(PixelGameEngine*pge);
|
virtual void RunAI(PixelGameEngine*pge);
|
||||||
void _RunAI(PixelGameEngine*pge);
|
void _RunAI(PixelGameEngine*pge);
|
||||||
virtual void Attacked(std::weak_ptr<Unit>attacker);
|
virtual void Attacked(std::weak_ptr<Unit>attacker);
|
||||||
void _Attacked(std::weak_ptr<Unit>attacker);
|
void _Attacked(std::weak_ptr<Unit>attacker,std::vector<std::shared_ptr<Unit>>&otherUnits);
|
||||||
std::weak_ptr<Unit>GetCurrentTarget();
|
std::weak_ptr<Unit>GetCurrentTarget();
|
||||||
void DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES);
|
void DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES);
|
||||||
bool AutoAcquiresFriendlyTargets();
|
bool AutoAcquiresFriendlyTargets();
|
||||||
|
@ -353,7 +353,6 @@ void VirusAttack::InitializeLevelData(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Stage 7
|
#pragma region Stage 7
|
||||||
{
|
{
|
||||||
//Stage 7 data.
|
//Stage 7 data.
|
||||||
@ -439,8 +438,6 @@ void VirusAttack::InitializeLevelData(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma region Stage 8
|
#pragma region Stage 8
|
||||||
{
|
{
|
||||||
//Stage 8 data.
|
//Stage 8 data.
|
||||||
@ -502,17 +499,28 @@ void VirusAttack::InitializeLevelData(){
|
|||||||
types.erase(types.begin()+randomIndex2);
|
types.erase(types.begin()+randomIndex2);
|
||||||
}
|
}
|
||||||
|
|
||||||
units.push_back({UnitType::Refresher,vf2d{52*24,52*24},false});
|
|
||||||
|
for(int i=0;i<2;i++){
|
||||||
|
units.push_back({UnitType::MemoryAllocator,vf2d{53*24,53*24},false});
|
||||||
|
}
|
||||||
|
units.push_back({UnitType::Refresher,vf2d{56*24,56*24},false});
|
||||||
units.push_back({UnitType::RAMBank,vf2d{54*24,54*24},false});
|
units.push_back({UnitType::RAMBank,vf2d{54*24,54*24},false});
|
||||||
|
|
||||||
|
|
||||||
for(int i=0;i<5;i++){
|
for(int i=0;i<5;i++){
|
||||||
units.push_back({UnitType::MemoryAllocator,vf2d{54*24,54*24},false});
|
units.push_back({UnitType::MemoryAllocator,vf2d{39*24,35*24},false});
|
||||||
}
|
}
|
||||||
|
units.push_back({UnitType::Refresher,vf2d{43*24,52*24},false});
|
||||||
|
units.push_back({UnitType::Turret,vf2d{44*24,52*24},false});
|
||||||
|
units.push_back({UnitType::MemoryGuard,vf2d{40*24,35*24},false});
|
||||||
units.push_back({UnitType::RAMBank,vf2d{40*24,36*24},false});
|
units.push_back({UnitType::RAMBank,vf2d{40*24,36*24},false});
|
||||||
|
units.push_back({UnitType::Turret,vf2d{37*24,57*24},false});
|
||||||
|
units.push_back({UnitType::Turret,vf2d{42*24,57*24},false});
|
||||||
|
|
||||||
|
for(int i=0;i<2;i++){
|
||||||
|
units.push_back({UnitType::MemoryAllocator,vf2d{10*24,53*24},false});
|
||||||
|
}
|
||||||
units.push_back({UnitType::RAMBank,vf2d{10*24,54*24},false});
|
units.push_back({UnitType::RAMBank,vf2d{10*24,54*24},false});
|
||||||
|
units.push_back({UnitType::Turret,vf2d{11*24,52*24},false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
@ -1294,7 +1302,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
|||||||
|
|
||||||
for(auto&u:units){
|
for(auto&u:units){
|
||||||
u->Draw(gametv,IMAGES);
|
u->Draw(gametv,IMAGES);
|
||||||
if(u->IsGuarded()){
|
if(u->IsGuarded()&&!u->InFogOfWar()){
|
||||||
gametv.DrawDecal(u->GetPos()+vf2d{float(u->GetUnitSize().x/2),-float(u->GetUnitSize().y/2)}-vf2d{float(IMAGES[GUARD_ICON]->Sprite()->width),0.f}*0.375,IMAGES[GUARD_ICON]->Decal(),{0.375,0.375});
|
gametv.DrawDecal(u->GetPos()+vf2d{float(u->GetUnitSize().x/2),-float(u->GetUnitSize().y/2)}-vf2d{float(IMAGES[GUARD_ICON]->Sprite()->width),0.f}*0.375,IMAGES[GUARD_ICON]->Decal(),{0.375,0.375});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1383,9 +1391,16 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
|||||||
#pragma endregion
|
#pragma endregion
|
||||||
#pragma region COMPLETED
|
#pragma region COMPLETED
|
||||||
case GameState::COMPLETED:{
|
case GameState::COMPLETED:{
|
||||||
|
|
||||||
DrawPartialDecal({0,0},GetScreenSize(),IMAGES[MATRIX]->Decal(),randomBackgroundOffset+gametv.GetWorldOffset()*(vf2d{32,32}/vf2d(GetScreenSize()))*gametv.GetWorldScale(),{32,32},Pixel{currentLevel->levelColor.r,currentLevel->levelColor.g,currentLevel->levelColor.b,164}/2);
|
DrawPartialDecal({0,0},GetScreenSize(),IMAGES[MATRIX]->Decal(),randomBackgroundOffset+gametv.GetWorldOffset()*(vf2d{32,32}/vf2d(GetScreenSize()))*gametv.GetWorldScale(),{32,32},Pixel{currentLevel->levelColor.r,currentLevel->levelColor.g,currentLevel->levelColor.b,164}/2);
|
||||||
completedBox.Initialize("Thank you for playing Virus Attack!\n\nCompletion Time:"+std::to_string(gameSeconds)+" seconds\n\nHuge shoutout to the OLC community, javidx9 for the PGE, and all supporters!");
|
completedBox.Initialize("Thank you for playing Virus Attack!\n\nCompletion Time:"+std::to_string(gameSeconds)+" seconds\n\nHuge shoutout to the OLC community, javidx9 for the PGE, and all supporters!\n\n\nPress [Escape] to return to the main menu.",{0,0},"Congratulations!",nullptr,{float(ScreenWidth()-2),1.f});
|
||||||
|
completedBox.UpdateAndDraw({0,0},this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory);
|
||||||
|
if(GetKey(ESCAPE).bPressed){
|
||||||
|
state=GameState::MAIN_MENU;
|
||||||
|
float titleScreenY=-200;
|
||||||
|
float textOrientationY=0;
|
||||||
|
float textOrientationX=0;
|
||||||
|
levelToLoad=LevelName::STAGE1;
|
||||||
|
}
|
||||||
}break;
|
}break;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user