Add in ability for enemies to help other enemies.

master
sigonasr2 1 year ago
parent ca3f00a924
commit 0b2b51c70c
  1. 168
      olcCodeJam2023Entry/Scenario.cpp
  2. 2
      olcCodeJam2023Entry/Scenario.h
  3. 1
      olcCodeJam2023Entry/Sound.h
  4. 110
      olcCodeJam2023Entry/Unit.cpp
  5. 3
      olcCodeJam2023Entry/Unit.h
  6. 196
      olcCodeJam2023Entry/VirusAttack.cpp

@ -1,5 +1,6 @@
#include "Scenario.h"
#include "TileManager.h"
#include "olcUTIL_Geometry2D.h"
Scenario::Scenario(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags)
@ -44,8 +45,29 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
enemy_resources={100,100,100,100,100};
}
unitBuildTimer=std::max(0.f,unitBuildTimer-game.GetPGE()->GetElapsedTime());
std::weak_ptr<Unit>baseOfOperations;
for(auto&u:units){
if(!u->IsFriendly()&&u->IsRAMBank()){
baseOfOperations=u;
break;
}
}
if(baseOfOperations.expired()){
for(auto&u:units){
if(!u->IsFriendly()){
baseOfOperations=u;
break;
}
}
}
//See if there are collectors, if so send memory allocator units towards them.
for(auto cp:collectionPoints){
if(!baseOfOperations.expired()){
std::sort(collectionPoints.begin(),collectionPoints.end(),[&](std::shared_ptr<CollectionPoint>cp1,std::shared_ptr<CollectionPoint>cp2){
geom2d::line<float>toCP1={cp1->pos,baseOfOperations.lock()->GetPos()};
geom2d::line<float>toCP2={cp2->pos,baseOfOperations.lock()->GetPos()};
return toCP1.length()<toCP2.length();});
}
for(auto&cp:collectionPoints){
if(cp->attachedUnit.expired()){
if(cpCheckTimer.count(cp.get())==0||cpCheckTimer[cp.get()]<=0){
for(auto&u:units){
@ -89,7 +111,7 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
UnitType buildUnit=unitChoiceList[randomIndex];
int totalCost=0;
for(int i=0;i<5;i++){
for(int i=0;i<unitResourceCostList[randomIndex].size();i++){
totalCost+=unitResourceCostList[randomIndex][i].size;
}
if(totalCost<=availableMemory){
@ -511,12 +533,108 @@ Stage4::Stage4(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_
:Scenario(units,IMAGES,SOUNDS,objective,game,flags){}
void Stage4::Start(){
nextLevel=LevelName::STAGE5;
flags.playerInControl=false;
flags.guideEnabled=true;
flags.limitedBuildOptions=false;
flags.unitMetersGreyedOut=false;
flags.flashMemoryBar=false;
SetCameraTarget({4*24,4*24},true);
};
void Stage4::Update(){
switch(state){
case 0:{
}break;
case 0:{
DisplayBox("Hacker, I have unfortunate news. I can't supply you with any more bits to construct things with.");
if(box.bPressed){
state=1;
}
}break;
case 1:{
DisplayBox("You've only got 3 health bits to start with this time. To allocate memory you always need at least 5 bits of memory.");
if(box.bPressed){
state=2;
}
}break;
case 2:{
SetCameraTarget({8*24,1*24});
if(camera.ReachedTarget()){
state=3;
}
}break;
case 3:{
DisplayBox("But we can collect bits from the system using these collection points.");
if(box.bPressed){
state=4;
}
}break;
case 4:{
DisplayBox("Simply bring over any unit to these and attach them to it. They will start providing you with system resources to make what you need.");
if(box.bPressed){
state=5;
}
}break;
case 5:{
flags.flashMemoryBar=true;
SetObjective("Setup units at collection points");
DisplayBox("Remember that the system has limited memory available. You'll always be fighting for free space from the system.");
if(box.bPressed){
state=6;
box.SetVisible(false);
flags.playerInControl=true;
}
}break;
case 6:{
collectorsAttached=0;
for(auto&u:units){
if(u->IsAttached()){
collectorsAttached++;
}
}
if(collectorsAttached>=2){
std::shared_ptr<Unit>target;
for(auto&u:units){
if(u->IsRAMBank()){
target=u;
}
}
state=7;
SOUNDS[Sound::ALARM]->PlayCentered();
flags.playerInControl=false;
auto u1=std::make_shared<LeftShifter>(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false);
auto u2=std::make_shared<LeftShifter>(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false);
auto u3=std::make_shared<LeftShifter>(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false);
units.push_back(u1);
units.push_back(u2);
units.push_back(u3);
u1->SetTargetUnit(target);
u2->SetTargetUnit(target);
u3->SetTargetUnit(target);
}
}break;
case 7:{
SetCameraTarget({4*24,4*24});
if(camera.ReachedTarget()){
state=8;
SOUNDS[Sound::WIND]->PlayCentered();
}
}break;
case 8:{
DisplayBox("An ambush...? I, WHAT? -- THIS IS NOT-");
if(box.bPressed){
state=9;
box.SetVisible(false);
nextLevelTimer=5;
}
}break;
case 9:{
nextLevelTimer=std::max(0.f,nextLevelTimer-game.GetPGE()->GetElapsedTime());
if(nextLevelTimer==0){
state=10;
}
}break;
case 10:{
transitionToNextLevel=true;
state=11;
}break;
}
};
bool Stage4::MissionCompleted(){
@ -525,6 +643,9 @@ bool Stage4::MissionCompleted(){
Stage5::Stage5(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags)
:Scenario(units,IMAGES,SOUNDS,objective,game,flags){}
void Stage5::Start(){
SetCameraTarget({4*24,4*24},true);
flags.playerInControl=true;
SetObjective("Defeat all enemy RAM banks.");
nextLevel=LevelName::STAGE6;
};
void Stage5::Update(){
@ -535,11 +656,19 @@ void Stage5::Update(){
}
};
bool Stage5::MissionCompleted(){
return false;
for(auto&u:units){
if(!u->IsFriendly()&&u->IsRAMBank()){
return false;
}
}
return true;
}
Stage6::Stage6(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags)
:Scenario(units,IMAGES,SOUNDS,objective,game,flags){}
void Stage6::Start(){
SetCameraTarget({4*24,4*24},true);
flags.playerInControl=true;
SetObjective("Defeat all enemy RAM banks.");
nextLevel=LevelName::STAGE7;
};
void Stage6::Update(){
@ -550,11 +679,19 @@ void Stage6::Update(){
}
};
bool Stage6::MissionCompleted(){
return false;
for(auto&u:units){
if(!u->IsFriendly()&&u->IsRAMBank()){
return false;
}
}
return true;
}
Stage7::Stage7(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags)
:Scenario(units,IMAGES,SOUNDS,objective,game,flags){}
void Stage7::Start(){
SetCameraTarget({4*24,4*24},true);
flags.playerInControl=true;
SetObjective("Defeat all enemy units.");
nextLevel=LevelName::STAGE8;
};
void Stage7::Update(){
@ -565,11 +702,19 @@ void Stage7::Update(){
}
};
bool Stage7::MissionCompleted(){
return false;
for(auto&u:units){
if(!u->IsFriendly()){
return false;
}
}
return true;
}
Stage8::Stage8(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags)
:Scenario(units,IMAGES,SOUNDS,objective,game,flags){}
void Stage8::Start(){
SetCameraTarget({4*24,4*24},true);
flags.playerInControl=true;
SetObjective("Defeat all enemy units.");
nextLevel=LevelName::FINISH;
};
void Stage8::Update(){
@ -580,5 +725,10 @@ void Stage8::Update(){
}
};
bool Stage8::MissionCompleted(){
return false;
for(auto&u:units){
if(!u->IsFriendly()){
return false;
}
}
return true;
}

@ -74,6 +74,8 @@ protected:
class Stage4:public Scenario{
public:
Stage4(std::vector<std::shared_ptr<Unit>>&units,std::vector<std::unique_ptr<Renderable>>&IMAGES,std::vector<std::unique_ptr<Audio>>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags);
int collectorsAttached=0;
float nextLevelTimer=0;
protected:
void Start();
void Update();

@ -25,5 +25,6 @@ namespace Sound{
DEAD1,
DEAD2,
DEAD3,
WIND,
};
}

@ -588,28 +588,30 @@ void Unit::_DrawHud(TileTransformedView&game,std::vector<std::unique_ptr<Rendera
}
void Unit::DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES){
if(!target.expired()){
geom2d::line<float>lineToTarget(pos,target.lock()->pos);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]);
game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,1},targetLineCol);
} else
if(targetLoc!=CONSTANT::UNSELECTED){
geom2d::line<float>lineToTarget(pos,targetLoc);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]);
game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,0.6},CONSTANT::MOVE_LINE_COL);
}
if(!appliedTarget.expired()){
geom2d::line<float>lineToTarget(pos,appliedTarget.lock()->pos);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
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+(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)});
if(!InFogOfWar()){
if(!target.expired()){
geom2d::line<float>lineToTarget(pos,target.lock()->pos);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]);
game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,1},targetLineCol);
} else
if(targetLoc!=CONSTANT::UNSELECTED){
geom2d::line<float>lineToTarget(pos,targetLoc);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]);
game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,0.6},CONSTANT::MOVE_LINE_COL);
}
if(!appliedTarget.expired()){
geom2d::line<float>lineToTarget(pos,appliedTarget.lock()->pos);
lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2);
lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4);
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+(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<float>(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length();
@ -701,7 +703,7 @@ void Unit::_RunAI(PixelGameEngine*pge){
RunAI(pge);
}
void Unit::_Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector<std::shared_ptr<Unit>>&queuedUnits,std::array<float,5>&resourceGainTimer,std::vector<ResourceGainIcon>&resourceGainIcons,std::vector<std::unique_ptr<Renderable>>&IMAGES){
void Unit::_Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector<std::shared_ptr<Unit>>&queuedUnits,std::array<float,5>&resourceGainTimer,std::vector<ResourceGainIcon>&resourceGainIcons,std::vector<std::unique_ptr<Renderable>>&IMAGES,GameFlags&flags){
if(!target.expired()){
auto ptrTarget=target.lock();
if(!InRange(ptrTarget)&&CanMove()){
@ -731,22 +733,69 @@ void Unit::_Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUND
Resources&targetResource=IsFriendly()?player_resources:enemy_resources;
switch(attachedPoint.lock()->type){
case HEALTH:{
if(!IsFriendly()&&flags.difficulty==2){
targetResource.health+=3;
}
if(!IsFriendly()&&flags.difficulty==1){
targetResource.health++;
}
if(!IsFriendly()&&flags.difficulty==0){
targetResource.health--;
}
targetResource.health++;
}break;
case RANGE:{
if(!IsFriendly()&&flags.difficulty==2){
targetResource.range+=3;
}
if(!IsFriendly()&&flags.difficulty==1){
targetResource.range++;
}
if(!IsFriendly()&&flags.difficulty==0){
targetResource.range--;
}
targetResource.range++;
}break;
case ATKSPD:{
if(!IsFriendly()&&flags.difficulty==2){
targetResource.atkSpd+=3;
}
if(!IsFriendly()&&flags.difficulty==1){
targetResource.atkSpd++;
}
if(!IsFriendly()&&flags.difficulty==0){
targetResource.atkSpd--;
}
targetResource.atkSpd++;
}break;
case MOVESPD:{
if(!IsFriendly()&&flags.difficulty==2){
targetResource.moveSpd+=3;
}
if(!IsFriendly()&&flags.difficulty==1){
targetResource.moveSpd++;
}
if(!IsFriendly()&&flags.difficulty==0){
targetResource.moveSpd--;
}
targetResource.moveSpd++;
}break;
case PROCEDURE:{
if(!IsFriendly()&&flags.difficulty==2){
targetResource.procedure+=3;
}
if(!IsFriendly()&&flags.difficulty==1){
targetResource.procedure++;
}
if(!IsFriendly()&&flags.difficulty==0){
targetResource.procedure--;
}
targetResource.procedure++;
}break;
}
resourceGainIcons.push_back({IMAGES[RESOURCE].get(),attachedPoint.lock()->type,GetPos()});
if(!InFogOfWar()){
resourceGainIcons.push_back({IMAGES[RESOURCE].get(),attachedPoint.lock()->type,GetPos()});
}
}
}
@ -909,6 +958,19 @@ void Unit::_Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,st
if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){
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 {
reloadTimer=1.f/(GetAtkSpd()/2.f);

@ -11,6 +11,7 @@
#include "Resources.h"
#include "Textbox.h"
#include "Memory.h"
#include "GameFlags.h"
#include "olcPGEX_QuickGUI.h"
enum class UnitType{
@ -68,7 +69,7 @@ public:
bool GhostInFogOfWar();
void HideGhost();
vf2d GetGhostPos();
void _Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector<std::shared_ptr<Unit>>&queuedUnits,std::array<float,5>&resourceGainTimer,std::vector<ResourceGainIcon>&resourceGainIcons,std::vector<std::unique_ptr<Renderable>>&IMAGES);
void _Update(PixelGameEngine*pge,std::vector<std::unique_ptr<Audio>>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector<std::shared_ptr<Unit>>&queuedUnits,std::array<float,5>&resourceGainTimer,std::vector<ResourceGainIcon>&resourceGainIcons,std::vector<std::unique_ptr<Renderable>>&IMAGES,GameFlags&flags);
bool IsMoveable();
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES);
bool CanInteractWithEnemies();

@ -189,7 +189,7 @@ void VirusAttack::InitializeLevelData(){
levelData[stage].worldZoom={1,1};
levelData[stage].size={36,36};
levelData[stage].levelColor=DARK_GREEN;
levelData[stage].bgm=Sound::GRAVITY;
levelData[stage].bgm=Sound::COSMOS;
levelData[stage].scenarioIndex=int(stage);
levelData[stage].availableMemory=300;
levelData[stage].player_starting_resources={3,0,0,0,0};
@ -203,14 +203,184 @@ void VirusAttack::InitializeLevelData(){
units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true});
}
collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{12*24,1*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{15*24,1*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{1*24,12*24},-PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{1*24,13*24},-PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{1*24,17*24},-PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{1*24,20*24},-PI/2,MemoryType::RANGE});
}
}
#pragma endregion
#pragma region Stage 5
{
//Stage 5 data.
LevelName stage=STAGE5;
levelData[stage].name=stage;
levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1};
levelData[stage].size={48,48};
levelData[stage].levelColor=DARK_GREY;
levelData[stage].bgm=Sound::BOSS1;
levelData[stage].scenarioIndex=int(stage);
levelData[stage].availableMemory=640;
levelData[stage].player_starting_resources={5,5,5,5,5};
levelData[stage].enemy_starting_resources={5,5,5,5,5};
{
std::vector<UnitData>&units=levelData[stage].unitPlacement;
std::vector<CPData>&collectionPoints=levelData[stage].cpPlacement;
units.push_back({UnitType::RAMBank,vf2d{4*24,4*24},true});
for(int i=0;i<5;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true});
}
collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{10*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{32*24,12*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{20*24,32*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{1*24,7*24},-PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{16*24,16*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{36*24,1*24},-PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{1*24,3*24},-PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{1*24,6*24},-PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{1*24,11*24},-PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{1*24,22*24},-PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{6*24,16*24},-PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{1*24,32*24},-PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-4)*24},PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{(48-1)*24,(48-7)*24},PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-12)*24},PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-23)*24},PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{(48-6)*24,(48-17)*24},PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-33)*24},PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-8)*24,(48-2)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-10)*24,(48-2)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-32)*24,(48-13)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-20)*24,(48-33)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-9)*24,(48-2)*24},PI,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-1)*24,(48-8)*24},PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-16)*24,(48-17)*24},PI,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-36)*24,(48-2)*24},PI/2,MemoryType::PROCEDURE});
for(int i=0;i<5;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{4*24,30*24},false});
units.push_back({UnitType::MemoryAllocator,vf2d{44*24,44*24},false});
}
units.push_back({UnitType::RAMBank,vf2d{4*24,32*24},false});
units.push_back({UnitType::Turret,vf2d{42*24,42*24},false});
units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::Corrupter,vf2d{42*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{45*24,41*24},false});
units.push_back({UnitType::RAMBank,vf2d{44*24,44*24},false});
}
}
#pragma endregion
#pragma endregion
#pragma region Stage 6
{
//Stage 6 data.
LevelName stage=STAGE6;
levelData[stage].name=stage;
levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1};
levelData[stage].size={48,48};
levelData[stage].levelColor=DARK_GREY;
levelData[stage].bgm=Sound::BOSS1;
levelData[stage].scenarioIndex=int(stage);
levelData[stage].availableMemory=640;
levelData[stage].player_starting_resources={5,5,5,5,5};
levelData[stage].enemy_starting_resources={5,5,5,5,5};
{
std::vector<UnitData>&units=levelData[stage].unitPlacement;
std::vector<CPData>&collectionPoints=levelData[stage].cpPlacement;
units.push_back({UnitType::RAMBank,vf2d{4*24,4*24},true});
for(int i=0;i<5;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true});
}
std::vector<vf2d>positions={
{{8,1},{10,1},{32,12},{20,32},{9,1},{1,7},{16,16}
,{36,1},{1,3},{1,6},{1,11},{1,22},{6,16},{1,32}}
};
std::vector<MemoryType>types={
{MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::PROCEDURE,
MemoryType::PROCEDURE,MemoryType::PROCEDURE,MemoryType::PROCEDURE,MemoryType::RANGE,
MemoryType::ATKSPD,MemoryType::MOVESPD,MemoryType::RANGE,MemoryType::ATKSPD,MemoryType::MOVESPD,}
};
if(positions.size()!=types.size()){
throw;
}
while(positions.size()>0){
int randomIndex=rand()%positions.size();
int randomIndex2=rand()%types.size();
float finalDir=0;
if(positions[randomIndex].x<levelData[stage].size.x/2){
if(positions[randomIndex].y<positions[randomIndex].x){
finalDir=0;
}else{
finalDir=-PI/2;
}
} else{
if(positions[randomIndex].y>positions[randomIndex].x){
finalDir=PI;
}else{
finalDir=PI/2;
}
}
collectionPoints.push_back(CPData{positions[randomIndex]*24,finalDir,types[randomIndex2]});
collectionPoints.push_back(CPData{(levelData[stage].size-positions[randomIndex]-vf2d{1,1})*24,float(finalDir+PI),types[randomIndex2]});
positions.erase(positions.begin()+randomIndex);
types.erase(types.begin()+randomIndex2);
}
collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{10*24,1*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{32*24,12*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{20*24,32*24},0,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{1*24,7*24},-PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{16*24,16*24},0,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{36*24,1*24},-PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{1*24,3*24},-PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{1*24,6*24},-PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{1*24,11*24},-PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{1*24,22*24},-PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{6*24,16*24},-PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{1*24,32*24},-PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-4)*24},PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{(48-1)*24,(48-7)*24},PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-12)*24},PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-23)*24},PI/2,MemoryType::RANGE});
collectionPoints.push_back(CPData{{(48-6)*24,(48-17)*24},PI/2,MemoryType::ATKSPD});
collectionPoints.push_back(CPData{{(48-1)*24,(48-33)*24},PI/2,MemoryType::MOVESPD});
collectionPoints.push_back(CPData{{(48-8)*24,(48-2)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-10)*24,(48-2)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-32)*24,(48-13)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-20)*24,(48-33)*24},PI,MemoryType::HEALTH});
collectionPoints.push_back(CPData{{(48-9)*24,(48-2)*24},PI,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-1)*24,(48-8)*24},PI/2,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-16)*24,(48-17)*24},PI,MemoryType::PROCEDURE});
collectionPoints.push_back(CPData{{(48-36)*24,(48-2)*24},PI/2,MemoryType::PROCEDURE});
for(int i=0;i<5;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{44*24,44*24},false});
}
units.push_back({UnitType::Turret,vf2d{42*24,42*24},false});
units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::Corrupter,vf2d{42*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{42*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{45*24,41*24},false});
units.push_back({UnitType::RAMBank,vf2d{44*24,44*24},false});
}
}
#pragma endregion
}
bool VirusAttack::OnUserCreate(){
@ -241,7 +411,8 @@ bool VirusAttack::OnUserCreate(){
InitializeScenarios();
InitializeLevelData();
LoadLevel(STAGE1);
LoadLevel(STAGE5);
levelToLoad=STAGE5;
return true;
}
@ -384,6 +555,7 @@ void VirusAttack::InitializeSounds(){
LoadSound(Sound::DEAD1,"dead1.mp3");
LoadSound(Sound::DEAD2,"dead2.mp3");
LoadSound(Sound::DEAD3,"dead3.mp3");
LoadSound(Sound::WIND,"wind.mp3");
}
bool VirusAttack::UnitCreationClickHandled(){
@ -561,6 +733,18 @@ void VirusAttack::HandleRightClickMove(){
}
void VirusAttack::CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2){
if(u->GetPos().x<0){
u->SetPos({0,u->GetPos().y});
}
if(u->GetPos().x>WORLD_SIZE.x*CONSTANT::TILE_SIZE.x){
u->SetPos({float(WORLD_SIZE.x*CONSTANT::TILE_SIZE.x),u->GetPos().y});
}
if(u->GetPos().y<0){
u->SetPos({u->GetPos().y,0});
}
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))){
geom2d::line<float>collisionLine(u->GetPos(),u2->GetPos()+vf2d{0.001,0.001});
float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2;
@ -928,7 +1112,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
}
}
u->AttemptAttack(u,closestUnit,units,debuffIcons,IMAGES,SOUNDS);
u->_Update(this,SOUNDS,player_resources,enemy_resources,queuedUnits,resourceGainTimer,resourceGainIcons,IMAGES);
u->_Update(this,SOUNDS,player_resources,enemy_resources,queuedUnits,resourceGainTimer,resourceGainIcons,IMAGES,flags);
}
std::erase_if(units,[&](std::shared_ptr<Unit>u){

Loading…
Cancel
Save