Virus Attack finalizing

master
sigonasr2 1 year ago
parent 0b2b51c70c
commit a4439afc3f
  1. 5
      .gitignore
  2. 60
      olcCodeJam2023Entry/Scenario.cpp
  3. 1
      olcCodeJam2023Entry/Scenario.h
  4. 245
      olcCodeJam2023Entry/VirusAttack.cpp
  5. 4
      olcCodeJam2023Entry/VirusAttack.h
  6. BIN
      olcCodeJam2023Entry/pge.data
  7. 2
      olcCodeJam2023Entry/pge.js
  8. BIN
      olcCodeJam2023Entry/pge.wasm

5
.gitignore vendored

@ -11,6 +11,9 @@
*.sln.docstates
*.wav
Windows
Emscripten
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
@ -363,3 +366,5 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
*.mp3
*.zip
/olcCodeJam2023Entry/VirusAttack.exe

@ -44,14 +44,22 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
if(!setupEasyMode&&flags.difficulty==0){
enemy_resources={100,100,100,100,100};
}
attackTimer=std::max(0.f,attackTimer-game.GetPGE()->GetElapsedTime());
unitBuildTimer=std::max(0.f,unitBuildTimer-game.GetPGE()->GetElapsedTime());
std::weak_ptr<Unit>baseOfOperations;
std::weak_ptr<Unit>enemyBaseOfOperations;
for(auto&u:units){
if(!u->IsFriendly()&&u->IsRAMBank()){
baseOfOperations=u;
break;
}
}
for(auto&u:units){
if(u->IsFriendly()&&u->IsRAMBank()){
enemyBaseOfOperations=u;
break;
}
}
if(baseOfOperations.expired()){
for(auto&u:units){
if(!u->IsFriendly()){
@ -93,7 +101,7 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
}
if(memoryAllocatorCount<3){
for(auto&u:units){
if(u->IsRAMBank()){
if(!u->IsFriendly()&&u->IsRAMBank()){
AttemptBuild(UnitType::MemoryAllocator,u->GetPos(),MemoryAllocator::resourceCost,enemy_resources,availableMemory,queuedUnits);
}
}
@ -148,6 +156,35 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<Colle
}
}
}
if(attackTimer==0){
if(!enemyBaseOfOperations.expired()){
for(auto&u:units){
if(!u->IsFriendly()&&rand()%3==0){
if(u->CanInteractWithEnemies()&&!u->IsAllocator()&&u->CanMove()){
u->SetTargetUnit(enemyBaseOfOperations);
}
}
}
for(auto&u:units){
if(!u->IsFriendly()&&u->GetCurrentTarget().expired()&&u->CanInteractWithAllies()){
if(rand()%5==0){
u->SetTargetLocation(enemyBaseOfOperations.lock()->GetPos());
}
}
}
}
switch(flags.difficulty){
case 0:{
attackTimer=999;
}break;
case 1:{
attackTimer=300;
}break;
case 2:{
attackTimer=120;
}break;
}
}
}
/*
std::shared_ptr<UnitClass>buildUnit=std::make_shared<UnitClass>(this,u->GetPos(),IMAGES,u->IsFriendly()); \
@ -674,7 +711,12 @@ void Stage6::Start(){
void Stage6::Update(){
switch(state){
case 0:{
flags.playerInControl=false;
DisplayBox("...");
if(box.bPressed){
flags.playerInControl=true;
box.SetVisible(false);
}
}break;
}
};
@ -697,7 +739,19 @@ void Stage7::Start(){
void Stage7::Update(){
switch(state){
case 0:{
flags.playerInControl=false;
DisplayBox("I see you have a few new tricks up your sleeve, Hacker.");
if(box.bPressed){
state=1;
}
}break;
case 1:{
DisplayBox("Don't think it'll be that easy to get through this one...");
if(box.bPressed){
state=2;
flags.playerInControl=true;
box.SetVisible(false);
}
}break;
}
};

@ -19,6 +19,7 @@ public:
LevelName nextLevel=LevelName::STAGE1;
void RunAI(Resources&enemy_resources,std::vector<std::shared_ptr<CollectionPoint>>&collectionPoints,int availableMemory,std::vector<std::shared_ptr<Unit>>&queuedUnits,std::vector<std::unique_ptr<Audio>>&SOUNDS);
bool setupEasyMode=false;
float attackTimer=120;
std::map<CollectionPoint*,float>cpCheckTimer;
bool AttemptBuild(UnitType unit,vf2d pos,std::vector<Memory>&resourceCost,Resources&enemy_resources,int availableMemory,std::vector<std::shared_ptr<Unit>>&queuedUnits);
protected:

@ -338,46 +338,181 @@ void VirusAttack::InitializeLevelData(){
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});
units.push_back({UnitType::Refresher,vf2d{2*24,42*24},false});
units.push_back({UnitType::MemoryGuard,vf2d{7*24,44*24},false});
units.push_back({UnitType::LeftShifter,vf2d{2*24,44*24},false});
units.push_back({UnitType::LeftShifter,vf2d{2*24,44*24},false});
units.push_back({UnitType::Corrupter,vf2d{2*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{2*24,44*24},false});
units.push_back({UnitType::RightShifter,vf2d{5*24,41*24},false});
units.push_back({UnitType::RAMBank,vf2d{4*24,44*24},false});
}
}
#pragma endregion
#pragma region Stage 7
{
//Stage 7 data.
LevelName stage=STAGE7;
levelData[stage].name=stage;
levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1};
levelData[stage].size={64,64};
levelData[stage].levelColor=DARK_RED;
levelData[stage].bgm=Sound::BOSS2;
levelData[stage].scenarioIndex=int(stage);
levelData[stage].availableMemory=960;
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}
,{14,16},{27,29},{14,12},{7,36},{16,30},{22,19},{39,40}}
};
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,
MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::PROCEDURE,
MemoryType::PROCEDURE,MemoryType::ATKSPD,MemoryType::MOVESPD,MemoryType::RANGE,}
};
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);
}
units.push_back({UnitType::Turret,vf2d{52*24,52*24},false});
units.push_back({UnitType::LeftShifter,vf2d{52*24,54*24},false});
units.push_back({UnitType::LeftShifter,vf2d{52*24,54*24},false});
units.push_back({UnitType::Corrupter,vf2d{52*24,54*24},false});
units.push_back({UnitType::RightShifter,vf2d{52*24,54*24},false});
units.push_back({UnitType::RightShifter,vf2d{55*24,51*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++){
units.push_back({UnitType::MemoryAllocator,vf2d{54*24,54*24},false});
}
units.push_back({UnitType::Turret,vf2d{53*24,22*24},false});
units.push_back({UnitType::RAMBank,vf2d{54*24,24*24},false});
for(int i=0;i<2;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{54*24,25*24},false});
}
units.push_back({UnitType::RightShifter,vf2d{53*24,24*24},false});
units.push_back({UnitType::BitRestorer,vf2d{54*24,25*24},false});
units.push_back({UnitType::RightShifter,vf2d{54*24,26*24},false});
}
}
#pragma endregion
#pragma region Stage 8
{
//Stage 8 data.
LevelName stage=STAGE8;
levelData[stage].name=stage;
levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1};
levelData[stage].size={64,64};
levelData[stage].levelColor=DARK_RED;
levelData[stage].bgm=Sound::BOSS2;
levelData[stage].scenarioIndex=int(stage);
levelData[stage].availableMemory=1280;
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}
,{14,16},{27,29},{14,12},{7,36},{16,30},{22,19},{39,40}}
};
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,
MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::PROCEDURE,
MemoryType::PROCEDURE,MemoryType::ATKSPD,MemoryType::MOVESPD,MemoryType::RANGE,}
};
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);
}
units.push_back({UnitType::Refresher,vf2d{52*24,52*24},false});
units.push_back({UnitType::RAMBank,vf2d{54*24,54*24},false});
for(int i=0;i<5;i++){
units.push_back({UnitType::MemoryAllocator,vf2d{54*24,54*24},false});
}
units.push_back({UnitType::RAMBank,vf2d{40*24,36*24},false});
units.push_back({UnitType::RAMBank,vf2d{10*24,54*24},false});
}
}
#pragma endregion
@ -401,6 +536,8 @@ bool VirusAttack::OnUserCreate(){
memoryAllocatorBox.SetVisible(false);
platformCreationBox.SetVisible(false);
restartBox.SetVisible(false);
completedBox.SetVisible(false);
creditsBox.SetVisible(false);
attackingLineModified.Create(IMAGES[ATTACKING_LINE]->Sprite()->width,IMAGES[ATTACKING_LINE]->Sprite()->height,false,false);
@ -411,8 +548,8 @@ bool VirusAttack::OnUserCreate(){
InitializeScenarios();
InitializeLevelData();
LoadLevel(STAGE5);
levelToLoad=STAGE5;
LoadLevel(STAGE1);
levelToLoad=STAGE1;
return true;
}
@ -505,10 +642,10 @@ void VirusAttack::InitializeGUIs(){
unitCreationList.DisplayAllControls(false);
platformCreationList.DisplayAllControls(false);
campaignStartButton=new QuickGUI::TransparentButton(mainMenu,"Start Campaign",{float(ScreenWidth()/2)-120.f,80+47.5f*0+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
audioToggleButton=new QuickGUI::TransparentButton(mainMenu,"Audio: On",{float(ScreenWidth()/2)-120.f,80+47.5f*1+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
difficultyToggleButton=new QuickGUI::TransparentButton(mainMenu,"Difficulty: Normal",{float(ScreenWidth()/2)-120.f,80+47.5f*2+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
creditsButton=new QuickGUI::TransparentButton(mainMenu,"Credits",{float(ScreenWidth()/2)-120.f,80+47.5f*3+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
campaignStartButton=new QuickGUI::TransparentButton(mainMenu,"Start Campaign",{float(ScreenWidth()/2)-120.f,80+47.5f*1+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
audioToggleButton=new QuickGUI::TransparentButton(mainMenu,"Audio: On",{float(ScreenWidth()/2)-120.f,80+47.5f*2+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
difficultyToggleButton=new QuickGUI::TransparentButton(mainMenu,"Difficulty: Normal",{float(ScreenWidth()/2)-120.f,80+47.5f*3+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
//creditsButton=new QuickGUI::TransparentButton(mainMenu,"Credits",{float(ScreenWidth()/2)-120.f,80+47.5f*3+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
exitGameButton=new QuickGUI::TransparentButton(mainMenu,"Exit Game",{float(ScreenWidth()/2)-120.f,80+47.5f*4+10},{240,24},CONSTANT::INCREASE_VALUE_COLOR);
}
@ -946,10 +1083,12 @@ void VirusAttack::RenderCollectionPoints(CollectionPoint*cp){
bool VirusAttack::OnUserUpdate(float fElapsedTime){
UpdateMatrixTexture(fElapsedTime);
gameplayTime+=fElapsedTime;
if(state!=GameState::COMPLETED){
if(gameplayTime>=1){
gameplayTime--;
gameSeconds++;
}
}
switch(state){
#pragma region MAIN_MENU
case GameState::MAIN_MENU:{
@ -960,6 +1099,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
state=GameState::GAMEPLAY;
RestartLevel();
gameplayTime=0;
gameSeconds=0;
}
if(audioToggleButton->bPressed){
audioMode=(audioMode+1)%3;
@ -981,6 +1121,20 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
}break;
}
}
if(difficultyToggleButton->bPressed){
flags.difficulty=(flags.difficulty+1)%3;
switch(flags.difficulty){
case 0:{
difficultyToggleButton->sText="Difficulty: Easy";
}break;
case 1:{
difficultyToggleButton->sText="Difficulty: Normal";
}break;
case 2:{
difficultyToggleButton->sText="Difficulty: Hard";
}break;
}
}
if(exitGameButton->bPressed){
SOUNDS[Sound::BUTTONSELECT]->PlayCentered();
}
@ -1229,12 +1383,9 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
#pragma endregion
#pragma region 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);
}break;
#pragma endregion
#pragma region CREDITS
case GameState::CREDITS:{
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!");
}break;
#pragma endregion
}

@ -60,7 +60,6 @@ public:
QuickGUI::TransparentButton*campaignStartButton;
QuickGUI::TransparentButton*audioToggleButton;
QuickGUI::TransparentButton*difficultyToggleButton;
QuickGUI::TransparentButton*creditsButton;
QuickGUI::TransparentButton*exitGameButton;
QuickGUI::Manager restartManager;
QuickGUI::TransparentImageButton*restartButton;
@ -114,6 +113,9 @@ public:
GameFlags flags;
float flashTimer=0;
Textbox completedBox;
Textbox creditsBox;
std::string objective="";
vf2d randomBackgroundOffset;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 MiB

After

Width:  |  Height:  |  Size: 24 MiB

File diff suppressed because one or more lines are too long

Binary file not shown.
Loading…
Cancel
Save