#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 "olcUTIL_Geometry2D.h" #include "TileManager.h" #include "util.h" #include "Scenario.h" VirusAttack::VirusAttack() { // Name your application sAppName = "Virus Attack"; } void VirusAttack::InitializeImages(){ auto LoadImage=[&](Image img,std::string filepath,bool filter=false,bool clamp=true){ IMAGES[img]=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"); LoadImage(VIRUS_IMG1,"assets/unit.png"); LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); 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"); 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); } void VirusAttack::InitializeLevelData(){ #pragma region Stage 1 { //Stage 1 data. LevelName stage=STAGE1; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].scenario=scenarios[0]; levelData[stage].levelColor=DARK_RED; levelData[stage].size={64,64}; levelData[stage].bgm=Sound::BOSS2; levelData[stage].player_starting_resources={500,500,500,500,500}; 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::RightShifter,vf2d{129,129},true}); units.push_back({UnitType::BitRestorer,vf2d{130,130},true}); units.push_back({UnitType::BitRestorer,vf2d{130,140},true}); units.push_back({UnitType::MemorySwapper,vf2d{131,131},true}); units.push_back({UnitType::Corrupter,vf2d{132,132},true}); units.push_back({UnitType::MemoryAllocator,vf2d{133,133},true}); units.push_back({UnitType::RAMBank,vf2d{134,134},true}); units.push_back({UnitType::MemoryGuard,vf2d{200,134},true}); for(int i=0;i<5;i++){ collectionPoints.push_back({vf2d{32.f+48*i,32.f},0,MemoryType(i)}); collectionPoints.push_back({vf2d{32.f,32.f+48*i},-PI/2,MemoryType(i)}); } units.push_back({UnitType::RAMBank,vf2d{1200,1200},false}); units.push_back({UnitType::RightShifter,vf2d{1260,1200},false}); units.push_back({UnitType::RightShifter,vf2d{360,300},false}); units.push_back({UnitType::RightShifter,vf2d{361,300},false}); } } #pragma endregion #pragma region Stage 2 { //Stage 2 data. LevelName stage=STAGE2; levelData[stage].cameraStart={96,96}; levelData[stage].worldZoom={1,1}; levelData[stage].size={16,16}; levelData[stage].scenario=scenarios[1]; levelData[stage].levelColor=DARK_GREEN; levelData[stage].bgm=Sound::COSMOS; levelData[stage].player_starting_resources={10,10,10,10,10}; 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{134,134},true}); units.push_back({UnitType::RAMBank,vf2d{1200,1200},false}); } } #pragma endregion } bool VirusAttack::OnUserCreate(){ srand(time(NULL)); SetPixelMode(Pixel::MASK); game.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); IMAGES[MINIMAP_OUTLINE]=std::make_unique(); IMAGES[MINIMAP_OUTLINE]->Create(64,64); IMAGES[MATRIX]=std::make_unique(); IMAGES[MATRIX]->Create(64,64,false,false); IMAGES[MATRIX]->Sprite()->SetSampleMode(Sprite::PERIODIC); AL.AudioSystemInit(); InitializeSounds(); InitializeGUIs(); InitializeScenarios(); InitializeLevelData(); LoadLevel(STAGE1); return true; } void VirusAttack::LoadLevel(LevelName level){ Level&selectedLevel=levelData[level]; currentLevel=&selectedLevel; WORLD_SIZE=selectedLevel.size; game.SetWorldScale(selectedLevel.worldZoom); game.SetWorldOffset(selectedLevel.cameraStart-vf2d(GetScreenSize())/2.f/game.GetWorldScale()); if(bgm==nullptr){ bgm=SOUNDS[selectedLevel.bgm].get(); bgm->PlayCentered(1,1,true); } else if(bgm!=SOUNDS[selectedLevel.bgm].get()){ bgm->Stop(); bgm=SOUNDS[selectedLevel.bgm].get(); 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)}; } void VirusAttack::InitializeGUIs(){ 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}); } void VirusAttack::InitializeScenarios(){ scenarios.emplace_back(new Stage1(this)); scenarios.emplace_back(new Stage1(this)); } void VirusAttack::InitializeSounds(){ int soundIndex=0; auto LoadSound=[&](Sound sound,std::string soundFilename){ SOUNDS[sound]=std::make_unique