#define OLC_PGE_APPLICATION #define OLC_SOUNDWAVE #define OLC_PGEX_TRANSFORMEDVIEW #define AUDIO_LISTENER_IMPLEMENTATION #define AUDIO_SOURCE_IMPLEMENTATION #define OLC_PGEX_QUICKGUI #define SPLASH_ENABLED #ifdef SPLASH_ENABLED #define OLC_PGEX_SPLASHSCREEN #endif #include "Scenario.h" #include "TileManager.h" #include "olcUTIL_Geometry2D.h" #include "util.h" #include "Level.h" #include "Scenario.h" #include "VirusAttack.h" VirusAttack*game; std::vector>IMAGES; std::vector>SOUNDS; std::vector>SCENARIOS; VirusAttack::VirusAttack() { // Name your application sAppName = "Virus Attack"; game=this; } void VirusAttack::InitializeImages(){ auto LoadImage=[&](Image img,std::string filepath,bool filter=false,bool clamp=true){ IMAGES.emplace_back(std::make_unique()); IMAGES[img]->Load(filepath,nullptr,filter,clamp); }; LoadImage(TILE,"assets/tile.png",false,false); LoadImage(MINIMAP_HUD,"assets/minimap_hud.png"); LoadImage(OUTLINE,"assets/outline.png"); IMAGES.emplace_back(std::make_unique()); IMAGES[MINIMAP_OUTLINE]->Create(64,64); LoadImage(VIRUS_IMG1,"assets/unit.png"); LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); IMAGES.emplace_back(std::make_unique()); IMAGES[MATRIX]->Create(64,64,false,false); IMAGES[MATRIX]->Sprite()->SetSampleMode(Sprite::PERIODIC); LoadImage(MEMORY_COLLECTION_POINT,"assets/memory_collection_point.png"); LoadImage(LEFT_SHIFTER,"assets/left_shifter.png"); LoadImage(RIGHT_SHIFTER,"assets/right_shifter.png"); LoadImage(BIT_RESTORER,"assets/bit_restorer.png"); LoadImage(MEMORY_SWAPPER,"assets/memory_swapper.png"); LoadImage(CORRUPTER,"assets/corrupter.png"); LoadImage(UNIT_ALLOCATOR,"assets/shell.png"); LoadImage(RAM_BANK,"assets/ram_bank.png"); LoadImage(RANGE_INDICATOR,"assets/range_indicator.png"); LoadImage(DOWN_ARROW,"assets/down_arrow.png"); LoadImage(RED_X,"assets/red_x.png"); LoadImage(RLD,"assets/rld.png"); LoadImage(PRC,"assets/prc.png"); LoadImage(RNG,"assets/rng.png"); LoadImage(SPD,"assets/spd.png"); LoadImage(TARGETING_LINE,"assets/targetLine.png"); LoadImage(ATTACKING_LINE,"assets/attackLine.png",false,false); LoadImage(RLD_ICON,"assets/rld_icon.png"); LoadImage(PRC_ICON,"assets/prc_icon.png"); LoadImage(RNG_ICON,"assets/rng_icon.png"); LoadImage(SPD_ICON,"assets/spd_icon.png"); LoadImage(RESOURCE,"assets/material.png"); LoadImage(MEMORY_COLLECTION_POINT_HIGHLIGHT,"assets/memory_collection_point_highlight.png"); LoadImage(MEMORY_GUARD,"assets/memoryguard.png"); LoadImage(REFRESHER,"assets/refresher.png"); LoadImage(TURRET,"assets/turret.png"); LoadImage(PLATFORM,"assets/platform.png"); LoadImage(GUARD_ICON,"assets/shieldIcon.png"); LoadImage(GUIDE,"assets/guide.png"); LoadImage(ROUND_BAR,"assets/round_bar.png"); LoadImage(SEGMENT_BAR,"assets/segmentBar.png",false,false); LoadImage(HOODED_FIGURE,"assets/hooded_figure.png"); LoadImage(SPOOK_HOODED_FIGURE,"assets/spook_hooded_figure.png"); LoadImage(RESTART,"assets/restart.png"); LoadImage(RESTART_HOVER,"assets/restartHover.png"); LoadImage(SHIELD_BUBBLE,"assets/shieldbubble.png"); titleScreenText.Create(426,100,false,true); SetDrawTarget(titleScreenText.Sprite()); Clear(BLANK); float textScale=3; vf2d textSize=GetTextSizeProp("Virus Attack")*textScale; DrawShadowStringProp(titleScreenText.Sprite()->Size()/2-textSize/2,"Virus Attack",WHITE,BLACK,{textScale,textScale},textScale); SetDrawTarget(nullptr); titleScreenText.Decal()->Update(); textOrientationX=titleScreenText.Sprite()->width/2; textOrientationY=titleScreenText.Sprite()->height-12; } void VirusAttack::InitializeLevelData(){ #pragma region Stage 1 { //Stage 1 data. LevelName stage=STAGE1; levelData[stage].name=stage; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].levelColor=DARK_GREEN; levelData[stage].size={24,24}; levelData[stage].bgm=Sound::GRAVITY; levelData[stage].scenarioIndex=int(stage); levelData[stage].availableMemory=240; levelData[stage].player_starting_resources={5,5,5,5,5}; levelData[stage].enemy_starting_resources={0,0,0,0,0}; { std::vector&units=levelData[stage].unitPlacement; std::vector&collectionPoints=levelData[stage].cpPlacement; units.push_back({UnitType::LeftShifter,vf2d{128,128},true}); units.push_back({UnitType::LeftShifter,vf2d{128,128},true}); units.push_back({UnitType::RAMBank,vf2d{320,320},false}); } } #pragma endregion #pragma region Stage 2 { //Stage 2 data. LevelName stage=STAGE2; levelData[stage].name=stage; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].size={30,30}; levelData[stage].levelColor=DARK_GREEN; levelData[stage].bgm=Sound::GRAVITY; levelData[stage].scenarioIndex=int(stage); levelData[stage].availableMemory=240; levelData[stage].player_starting_resources={50,30,40,30,55}; levelData[stage].enemy_starting_resources={0,0,0,0,0}; { std::vector&units=levelData[stage].unitPlacement; std::vector&collectionPoints=levelData[stage].cpPlacement; units.push_back({UnitType::_Platform,vf2d{7*24,10*24},true}); units.push_back({UnitType::RightShifter,vf2d{20*24,21*24},false}); units.push_back({UnitType::LeftShifter,vf2d{20*24,22*24},false}); units.push_back({UnitType::MemoryAllocator,vf2d{22*24,24*24},false}); units.push_back({UnitType::RAMBank,vf2d{22*24,23*24},false}); } } #pragma endregion #pragma region Stage 3 { //Stage 3 data. LevelName stage=STAGE3; levelData[stage].name=stage; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].size={30,30}; levelData[stage].levelColor=DARK_GREEN; levelData[stage].bgm=Sound::GRAVITY; levelData[stage].scenarioIndex=int(stage); levelData[stage].availableMemory=240; levelData[stage].player_starting_resources={100,40,60,40,100}; levelData[stage].enemy_starting_resources={0,0,0,0,0}; { std::vector&units=levelData[stage].unitPlacement; std::vector&collectionPoints=levelData[stage].cpPlacement; units.push_back({UnitType::RAMBank,vf2d{3*24,6*24},true}); for(int i=0;i<4;i++){ units.push_back({UnitType::RightShifter,vf2d{3*24,8*24},true}); } units.push_back({UnitType::LeftShifter,vf2d{3*24,7*24},true}); units.push_back({UnitType::RightShifter,vf2d{18*24,19*24},false}); units.push_back({UnitType::LeftShifter,vf2d{20*24,22*24},false}); units.push_back({UnitType::LeftShifter,vf2d{21*24,22*24},false}); for(int i=0;i<8;i++){ units.push_back({UnitType::MemoryAllocator,vf2d{20*24,17*24},false}); } units.push_back({UnitType::_Platform,vf2d{22*24,23*24},false}); } } #pragma endregion #pragma region Stage 4 { //Stage 4 data. LevelName stage=STAGE4; levelData[stage].name=stage; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].size={36,36}; levelData[stage].levelColor=DARK_GREEN; levelData[stage].bgm=Sound::COSMOS; levelData[stage].scenarioIndex=int(stage); levelData[stage].availableMemory=300; levelData[stage].player_starting_resources={3,0,0,0,0}; levelData[stage].enemy_starting_resources={3,0,0,0,0}; { std::vector&units=levelData[stage].unitPlacement; std::vector&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{{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&units=levelData[stage].unitPlacement; std::vector&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{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 #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&units=levelData[stage].unitPlacement; std::vector&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::vectorpositions={ {{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::vectortypes={ {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].xpositions[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); } for(int i=0;i<5;i++){ units.push_back({UnitType::MemoryAllocator,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&units=levelData[stage].unitPlacement; std::vector&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::vectorpositions={ {{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::vectortypes={ {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].xpositions[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&units=levelData[stage].unitPlacement; std::vector&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::vectorpositions={ {{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::vectortypes={ {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].xpositions[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); } 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}); for(int i=0;i<5;i++){ 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::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::Turret,vf2d{11*24,52*24},false}); } } #pragma endregion } bool VirusAttack::OnUserCreate(){ srand(time(NULL)); currentBackCol=newCol=colorChangeOptions[rand()%colorChangeOptions.size()]; SetPixelMode(Pixel::MASK); gametv.Initialise(GetScreenSize()); InitializeImages(); unitCreationBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.", {}); unitCreationBox.SetVisible(false); testBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{}); testBox.SetVisible(false); memoryAllocatorBox.Initialize(CONSTANT::MEMORY_ALLOCATOR_BOX_DISPLAY_STRING,{},CONSTANT::MEMORY_ALLOCATOR_BOX_HEADER_STRING); 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); AL.AudioSystemInit(); InitializeSounds(); InitializeGUIs(); InitializeScenarios(); InitializeLevelData(); LoadLevel(STAGE1); levelToLoad=STAGE1; return true; } void VirusAttack::LoadLevel(LevelName level){ Level&selectedLevel=levelData[level]; currentLevel=&selectedLevel; currentScenario=currentLevel->scenarioIndex; WORLD_SIZE=selectedLevel.size; gametv.SetWorldScale(selectedLevel.worldZoom); gametv.SetWorldOffset(selectedLevel.cameraStart-vf2d(GetScreenSize())/2.f/gametv.GetWorldScale()); if(bgm==nullptr){ bgm=SOUNDS[int(selectedLevel.bgm)].get(); bgm_handle=bgm->PlayCentered(1,1,true); } else if(bgm!=SOUNDS[int(selectedLevel.bgm)].get()){ bgm->Stop(); bgm=SOUNDS[int(selectedLevel.bgm)].get(); bgm_handle=bgm->PlayCentered(1,1,true); } player_resources=selectedLevel.player_starting_resources; enemy_resources=selectedLevel.enemy_starting_resources; TileManager::visibleTiles.clear(); std::for_each(units.begin(),units.end(),[&](auto&u){ u->OnDeath(SOUNDS); }); units.clear(); collectionPoints.clear(); for(auto&u:selectedLevel.unitPlacement){ #define TranslateUnit(type) \ case UnitType::type:{ \ units.push_back(std::make_shared(this,u.pos,IMAGES,u.friendly)); \ }break; switch(u.type){ TranslateUnit(LeftShifter) TranslateUnit(RightShifter) TranslateUnit(BitRestorer) TranslateUnit(MemorySwapper) TranslateUnit(Corrupter) TranslateUnit(MemoryAllocator) TranslateUnit(RAMBank) TranslateUnit(_Platform) TranslateUnit(MemoryGuard) TranslateUnit(Refresher) TranslateUnit(Turret) default:{ std::cout<<"Could not load unit type "<(this,cp.pos,cp.rot,*IMAGES[MEMORY_COLLECTION_POINT],cp.type)); } randomBackgroundOffset={util::random(128),util::random(128)}; objective=""; SCENARIOS[currentScenario]->_Start(); } void VirusAttack::InitializeGUIs(){ restartButton=new QuickGUI::TransparentImageButton(restartManager,*IMAGES[RESTART],*IMAGES[RESTART_HOVER],{1,1},{float(ScreenWidth()-32),12.f},{28,28}); unitCreationList.colNormal = olc::DARK_GREEN; unitCreationList.colHover = olc::GREEN; unitCreationList.colClick = olc::YELLOW; unitCreationList.colDisable = olc::DARK_GREY; unitCreationList.colBorder = olc::YELLOW; unitCreationList.colText = olc::WHITE; platformCreationList.CopyThemeFrom(unitCreationList); leftShifterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[LEFT_SHIFTER],{0.5,0.5},{16.f+32*0,float(ScreenHeight()-48)},{20,20}); rightShifterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[RIGHT_SHIFTER],{0.5,0.5},{16.f+32*1,float(ScreenHeight()-48)},{20,20}); bitRestorerButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[BIT_RESTORER],{0.5,0.5},{16.f+32*2,float(ScreenHeight()-48)},{20,20}); memorySwapperButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[MEMORY_SWAPPER],{0.5,0.5},{16.f+32*3,float(ScreenHeight()-48)},{20,20}); corrupterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[CORRUPTER],{0.5,0.5},{16.f+32*4,float(ScreenHeight()-48)},{20,20}); platformButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[PLATFORM],{0.25,0.25},{16.f+32*5,float(ScreenHeight()-48)},{20,20}); ramBankButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[RAM_BANK],{0.125,0.125},{float(ScreenWidth()-48),48.f+32*0},{20,20}); refresherButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[REFRESHER],{0.25,0.25},{float(ScreenWidth()-48),48.f+32*1},{20,20}); turretButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[TURRET],{0.25,0.25},{float(ScreenWidth()-48),48.f+32*2},{20,20}); memoryGuardButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[MEMORY_GUARD],{0.25,0.25},{float(ScreenWidth()-48),48.f+32*3},{20,20}); unitCreationList.DisplayAllControls(false); platformCreationList.DisplayAllControls(false); 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); } void VirusAttack::InitializeScenarios(){ SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); SCENARIOS.emplace_back(std::make_unique(units,IMAGES,SOUNDS,objective,gametv,flags)); } void VirusAttack::InitializeSounds(){ int soundIndex=0; auto LoadSound=[&](Sound::Sound sound,std::string soundFilename){ SOUNDS.emplace_back(std::make_unique