diff --git a/.gitignore b/.gitignore index 3c6714e..386b082 100644 --- a/.gitignore +++ b/.gitignore @@ -361,4 +361,5 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd +*.mp3 diff --git a/olcCodeJam2023Entry/Constant.cpp b/olcCodeJam2023Entry/Constant.cpp index dade43e..795dd24 100644 --- a/olcCodeJam2023Entry/Constant.cpp +++ b/olcCodeJam2023Entry/Constant.cpp @@ -12,7 +12,6 @@ Pixel CONSTANT::MOVE_LINE_COL={147, 252, 66}; vf2d CONSTANT::UNSELECTED={-99,-99}; vi2d CONSTANT::TILE_SIZE={24,24}; -vi2d CONSTANT::WORLD_SIZE={64,64}; float CONSTANT::SCROLL_BOUNDARY=72; diff --git a/olcCodeJam2023Entry/Level.h b/olcCodeJam2023Entry/Level.h new file mode 100644 index 0000000..c6a77d0 --- /dev/null +++ b/olcCodeJam2023Entry/Level.h @@ -0,0 +1,32 @@ +#pragma once +#include "olcPixelGameEngine.h" +#include "Unit.h" +#include "CollectionPoint.h" + +enum LevelName{ + STAGE1, + STAGE2, + STAGE3, + STAGE4, +}; + +struct UnitData{ + UnitType type; + vf2d pos; + bool friendly; +}; + +struct CPData{ + vf2d pos; + float rot; + MemoryType type; +}; + +struct Level{ + vi2d size={1,1}; + Resources player_starting_resources; + Resources enemy_starting_resources; + std::vectorunitPlacement; + std::vectorcpPlacement; + Sound bgm=Sound::COSMOS; +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Sound.h b/olcCodeJam2023Entry/Sound.h index 8f49702..0021085 100644 --- a/olcCodeJam2023Entry/Sound.h +++ b/olcCodeJam2023Entry/Sound.h @@ -2,4 +2,6 @@ enum class Sound{ HUM, + GRAVITY, + COSMOS, }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 2661ea1..7dea115 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -6,32 +6,11 @@ #include "olcPGEX_QuickGUI.h" #include "Textbox.h" -std::string BasicUnit::unitName=""; -std::string BasicUnit::unitDescription=""; -std::vector BasicUnit::resourceCost={{HEALTH,4},{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1}}; -BasicUnit::BasicUnit(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,BasicUnit::resourceCost,pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){} - - -void BasicUnit::Attack(Unit&victim,std::vector>&otherUnits){ - victim<<=1; -} - -std::string BasicUnit2::unitName=""; -std::string BasicUnit2::unitDescription=""; -std::vector BasicUnit2::resourceCost={{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1},{HEALTH,4}}; -BasicUnit2::BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,BasicUnit2::resourceCost,pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){} - -void BasicUnit2::Attack(Unit&victim,std::vector>&otherUnits){ - victim>>=1; -} - std::string LeftShifter::unitName="Left Shifter"; std::string LeftShifter::unitDescription="Memory Shifts target memory 1 bit to the left."; std::vector LeftShifter::resourceCost={{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1},{HEALTH,4}}; LeftShifter::LeftShifter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,LeftShifter::resourceCost,pos,12,*IMAGES[LEFT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} + :Unit(pge,UnitType::LeftShifter,LeftShifter::resourceCost,pos,12,*IMAGES[LEFT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} void LeftShifter::Attack(Unit&victim,std::vector>&otherUnits){ victim<<=1; @@ -41,7 +20,7 @@ std::string RightShifter::unitName="Right Shifter"; std::string RightShifter::unitDescription="Memory Shifts target memory 1 bit to the right."; std::vector RightShifter::resourceCost={{HEALTH,4},{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1}}; RightShifter::RightShifter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,RightShifter::resourceCost,pos,12,*IMAGES[RIGHT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} + :Unit(pge,UnitType::RightShifter,RightShifter::resourceCost,pos,12,*IMAGES[RIGHT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} void RightShifter::Attack(Unit&victim,std::vector>&otherUnits){ victim>>=1; @@ -51,7 +30,7 @@ std::string BitRestorer::unitName="Bit Restorer"; std::string BitRestorer::unitDescription="Randomly restores 1 missing bit to a target."; std::vector BitRestorer::resourceCost={{PROCEDURE,6},{RANGE,1},{ATKSPD,1},{MOVESPD,1},{HEALTH,2}}; BitRestorer::BitRestorer(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,BitRestorer::resourceCost,pos,12,*IMAGES[BIT_RESTORER],CONSTANT::HEALER_TARGET_COL,CONSTANT::HEALER_ATTACK_COL,friendly,moveable,true,false){} + :Unit(pge,UnitType::BitRestorer,BitRestorer::resourceCost,pos,12,*IMAGES[BIT_RESTORER],CONSTANT::HEALER_TARGET_COL,CONSTANT::HEALER_ATTACK_COL,friendly,moveable,true,false){} void BitRestorer::Attack(Unit&victim,std::vector>&otherUnits){ std::vectoremptyMemoryPositions; @@ -93,7 +72,7 @@ std::string MemorySwapper::unitName="Memory Swapper"; std::string MemorySwapper::unitDescription="Flips the orientation of all bits of a target around."; std::vector MemorySwapper::resourceCost={{RANGE,3},{ATKSPD,1},{HEALTH,3},{PROCEDURE,3},{MOVESPD,2}}; MemorySwapper::MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,MemorySwapper::resourceCost,pos,12,*IMAGES[MEMORY_SWAPPER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable,true){ + :Unit(pge,UnitType::MemorySwapper,MemorySwapper::resourceCost,pos,12,*IMAGES[MEMORY_SWAPPER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable,true){ autoAcquireFriendlyTarget=false; } @@ -105,7 +84,7 @@ std::string Corrupter::unitName="Corrupter"; std::string Corrupter::unitDescription="Chooses a random bit and negates it on a target."; std::vector Corrupter::resourceCost={{ATKSPD,3},{RANGE,1},{PROCEDURE,8},{MOVESPD,4},{HEALTH,4}}; Corrupter::Corrupter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,Corrupter::resourceCost,pos,12,*IMAGES[CORRUPTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} + :Unit(pge,UnitType::Corrupter,Corrupter::resourceCost,pos,12,*IMAGES[CORRUPTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){} void Corrupter::Attack(Unit&victim,std::vector>&otherUnits){ //Chooses a bit at random and corrupts it. @@ -117,7 +96,7 @@ std::string MemoryAllocator::unitName="Memory Allocator"; std::string MemoryAllocator::unitDescription="A unit that builds other units."; std::vector MemoryAllocator::resourceCost={{RANGE,1},{ATKSPD,1},{MOVESPD,1},{PROCEDURE,1},{HEALTH,1}}; MemoryAllocator::MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) - :Unit(pge,MemoryAllocator::resourceCost,pos,12,*IMAGES[UNIT_ALLOCATOR],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,true,false){ + :Unit(pge,UnitType::MemoryAllocator,MemoryAllocator::resourceCost,pos,12,*IMAGES[UNIT_ALLOCATOR],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,true,false){ isAllocator=true; } @@ -162,7 +141,7 @@ std::string RAMBank::unitName="RAM Bank"; std::string RAMBank::unitDescription="Allows for the construction of Memory Allocators."; std::vector RAMBank::resourceCost={{RANGE,0},{ATKSPD,0},{MOVESPD,0},{PROCEDURE,25},{HEALTH,16}}; RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly) - :Unit(pge,RAMBank::resourceCost,pos,41,*IMAGES[RAM_BANK],WHITE,WHITE,friendly,false + :Unit(pge,UnitType::RAMBank,RAMBank::resourceCost,pos,41,*IMAGES[RAM_BANK],WHITE,WHITE,friendly,false ,false,false ),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]), originalImg(*IMAGES[RAM_BANK]){ @@ -271,8 +250,8 @@ bool RAMBank::ClickHandled(TileTransformedView&game,Resources&player_resources,s return false; } -Unit::Unit(PixelGameEngine*pge,std::vectormemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,bool friendly,bool moveable,bool friendlyInteractable,bool enemyInteractable) -:pos(pos),radius(radius),ghostPos(pos),img(img),targetLineCol(targetLineColor),attackingLineCol(attackingLineColor),friendly(friendly),moveable(moveable),friendlyInteractable(friendlyInteractable),enemyInteractable(enemyInteractable){ +Unit::Unit(PixelGameEngine*pge,UnitType type,std::vectormemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,bool friendly,bool moveable,bool friendlyInteractable,bool enemyInteractable) +:pos(pos),type(type),radius(radius),ghostPos(pos),img(img),targetLineCol(targetLineColor),attackingLineCol(attackingLineColor),friendly(friendly),moveable(moveable),friendlyInteractable(friendlyInteractable),enemyInteractable(enemyInteractable){ int marker=0; for(Memory&mem:memory){ for(int i=0;imemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,bool friendly=false,bool moveable=true,bool friendlyInteractable=false,bool enemyInteractable=true); + Unit(PixelGameEngine*pge,UnitType type,std::vectormemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,bool friendly=false,bool moveable=true,bool friendlyInteractable=false,bool enemyInteractable=true); int GetHealth(); int GetRange(); int GetAtkSpd(); @@ -140,22 +150,7 @@ private: bool willAttachWhenReachingDestination=false; std::weak_ptrself_ptr; float collectionTime=0; -}; - -struct BasicUnit:Unit{ - BasicUnit(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); - void Attack(Unit&victim,std::vector>&otherUnits)override; - static std::vector resourceCost; - static std::string unitName; - static std::string unitDescription; -}; - -struct BasicUnit2:Unit{ - BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); - void Attack(Unit&victim,std::vector>&otherUnits)override; - static std::vector resourceCost; - static std::string unitName; - static std::string unitDescription; + UnitType type; }; struct LeftShifter:Unit{ diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 618ba6e..bc10581 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -4,6 +4,12 @@ #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" @@ -51,6 +57,56 @@ void VirusAttack::InitializeImages(){ LoadImage(MEMORY_COLLECTION_POINT_HIGHLIGHT,"assets/memory_collection_point_highlight.png"); } +void VirusAttack::InitializeLevelData(){ + #pragma region Stage 1 + //Stage 1 data. + levelData[STAGE1].size={64,64}; + levelData[STAGE1].bgm=Sound::GRAVITY; + levelData[STAGE1].player_starting_resources={5,5,5,5,5}; + levelData[STAGE1].enemy_starting_resources={0,0,0,0,0}; + { + std::vector&units=levelData[STAGE1].unitPlacement; + std::vector&collectionPoints=levelData[STAGE1].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}); + + + 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. + levelData[STAGE2].size={16,16}; + levelData[STAGE2].bgm=Sound::COSMOS; + levelData[STAGE2].player_starting_resources={10,10,10,10,10}; + levelData[STAGE2].enemy_starting_resources={0,0,0,0,0}; + { + std::vector&units=levelData[STAGE2].unitPlacement; + std::vector&collectionPoints=levelData[STAGE2].cpPlacement; + + units.push_back({UnitType::RAMBank,vf2d{134,134},true}); + + units.push_back({UnitType::RAMBank,vf2d{1200,1200},false}); + } + #pragma endregion +} + bool VirusAttack::OnUserCreate(){ SetPixelMode(Pixel::MASK); @@ -77,29 +133,51 @@ bool VirusAttack::OnUserCreate(){ InitializeSounds(); InitializeUnitCreationGUI(); + InitializeLevelData(); - units.push_back(std::make_unique(this,vf2d{128,128},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{129,129},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{130,130},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{130,140},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{131,131},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{132,132},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{133,133},IMAGES,true)); - units.push_back(std::make_unique(this,vf2d{134,134},IMAGES,true)); - + LoadLevel(STAGE1); + + return true; +} - for(int i=0;i<5;i++){ - collectionPoints.push_back(std::make_unique(this,vf2d{32.f+48*i,32.f},0,*IMAGES[MEMORY_COLLECTION_POINT],MemoryType(i))); - collectionPoints.push_back(std::make_unique(this,vf2d{32.f,32.f+48*i},-PI/2,*IMAGES[MEMORY_COLLECTION_POINT],MemoryType(i))); +void VirusAttack::LoadLevel(LevelName level){ + Level&selectedLevel=levelData[level]; + + currentLevel=&selectedLevel; + + WORLD_SIZE=selectedLevel.size; + + if(bgm!=nullptr){ + bgm->Stop(); } + bgm=SOUNDS[selectedLevel.bgm].get(); + bgm->PlayCentered(1,1,true); + player_resources=selectedLevel.player_starting_resources; + enemy_resources=selectedLevel.enemy_starting_resources; - units.push_back(std::make_unique(this,vf2d{1200,1200},IMAGES,false)); + TileManager::visibleTiles.clear(); + units.clear(); + collectionPoints.clear(); - units.push_back(std::make_unique(this,vf2d{1260,1200},IMAGES,false)); - units.push_back(std::make_unique(this,vf2d{360,300},IMAGES,false)); - units.push_back(std::make_unique(this,vf2d{361,300},IMAGES,false)); + for(auto&u:selectedLevel.unitPlacement){ + #define TranslateUnit(type) \ + case UnitType::type:{ \ + units.push_back(std::make_unique(this,u.pos,IMAGES,u.friendly)); \ + }break; - return true; + switch(u.type){ + TranslateUnit(LeftShifter) + TranslateUnit(RightShifter) + TranslateUnit(BitRestorer) + TranslateUnit(MemorySwapper) + TranslateUnit(Corrupter) + TranslateUnit(MemoryAllocator) + TranslateUnit(RAMBank) + } + } + for(auto&cp:selectedLevel.cpPlacement){ + collectionPoints.push_back(std::make_unique(this,cp.pos,cp.rot,*IMAGES[MEMORY_COLLECTION_POINT],cp.type)); + } } void VirusAttack::InitializeUnitCreationGUI(){ @@ -127,6 +205,8 @@ void VirusAttack::InitializeSounds(){ }; LoadSound(Sound::HUM,"machine2.wav"); + LoadSound(Sound::GRAVITY,"gravity.mp3"); + LoadSound(Sound::COSMOS,"cosmos.mp3"); } bool VirusAttack::UnitCreationClickHandled(){ @@ -317,13 +397,13 @@ void VirusAttack::IdentifyClosestTarget(std::weak_ptr&closestUnit,float&cl void VirusAttack::DrawMinimap(){ DrawDecal(GetScreenSize()-IMAGES[MINIMAP_HUD]->Sprite()->Size(),IMAGES[MINIMAP_HUD]->Decal(),{1,1}); vf2d minimapTL=GetScreenSize()-vf2d{64,64}; - vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE; - vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE; + vi2d worldPixelSize=WORLD_SIZE*CONSTANT::TILE_SIZE; + vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/WORLD_SIZE; SetDrawTarget(IMAGES[MINIMAP_OUTLINE]->Sprite()); Clear(BLANK); DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); for(auto&u:units){ - vf2d squareSize=u->GetUnitSize()/vf2d(CONSTANT::WORLD_SIZE); + vf2d squareSize=u->GetUnitSize()/vf2d(WORLD_SIZE); squareSize.x=std::round(std::max(1.f,squareSize.x)); squareSize.y=std::round(std::max(1.f,squareSize.y)); FillRect(u->GetGhostPos()/worldPixelSize*64-squareSize,squareSize*2,u->IsFriendly()?GREEN:RED); @@ -368,7 +448,7 @@ void VirusAttack::HandlePanAndZoom(float fElapsedTime){ void VirusAttack::HandleMinimapClick(){ if(startingDragPos==CONSTANT::UNSELECTED&&GetMouse(0).bHeld&&GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64){ vf2d minimapTL=GetScreenSize()-vf2d{64,64}; - game.SetWorldOffset(vf2d(GetMousePos()-minimapTL)/64*CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE-vf2d(GetScreenSize())/game.GetWorldScale()/2.f); + game.SetWorldOffset(vf2d(GetMousePos()-minimapTL)/64*WORLD_SIZE*CONSTANT::TILE_SIZE-vf2d(GetScreenSize())/game.GetWorldScale()/2.f); } vf2d offset=game.GetWorldOffset(); offset.x=std::clamp(float(offset.x),-ScreenWidth()/2/game.GetWorldScale().x,WORLD_SIZE.x*24-(ScreenWidth()/2/game.GetWorldScale().x)); @@ -467,6 +547,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ AL.fSoundFXVolume=std::min(1.f,game.GetWorldScale().x); AL.OnUserUpdate(fElapsedTime); + if(GetKey(P).bPressed){ + LoadLevel(STAGE1); + } + if(GetKey(O).bPressed){ + LoadLevel(STAGE2); + } + for(auto&tile:TileManager::visibleTiles){ tile.second-=fElapsedTime; } @@ -509,7 +596,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ queuedUnits.clear(); - game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); + game.DrawPartialDecal({0,0},WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); for(auto&u:units){ u->DrawRangeIndicator(this,game,IMAGES); @@ -584,7 +671,7 @@ void VirusAttack::RenderFogOfWar(){ for(int y=game.GetTopLeftTile().y/96-1;y<=game.GetBottomRightTile().y/96+1;y++){ for(int x=game.GetTopLeftTile().x/96-1;x<=game.GetBottomRightTile().x/96+1;x++){ if(TileManager::visibleTiles.count(vi2d{x,y})==0){ - if(x>=0&&y>=0&&x<=CONSTANT::WORLD_SIZE.x*CONSTANT::TILE_SIZE.x&&y<=CONSTANT::WORLD_SIZE.y*CONSTANT::TILE_SIZE.y){ + if(x>=0&&y>=0&&x<=WORLD_SIZE.x*CONSTANT::TILE_SIZE.x&&y<=WORLD_SIZE.y*CONSTANT::TILE_SIZE.y){ game.FillRectDecal(vf2d{float(x),float(y)}*96,{96,96},{0,0,0,128}); } } diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index de3bc79..287fa46 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -12,6 +12,8 @@ #include "CollectionPoint.h" #include "Resources.h" #include "Textbox.h" +#include "olcPGEX_SplashScreen.h" +#include "Level.h" struct Letter{ vf2d pos; @@ -22,7 +24,10 @@ struct Letter{ class VirusAttack : public olc::PixelGameEngine { private: - vi2d WORLD_SIZE=CONSTANT::WORLD_SIZE; + #ifdef SPLASH_ENABLED + SplashScreen splash; + #endif + vi2d WORLD_SIZE={64,64}; std::vector>queuedUnits; std::vector>units; @@ -34,13 +39,16 @@ private: std::map>SOUNDS; olcPGEX_AudioListener AL; - Audio*bgm; + Audio*bgm=nullptr; Resources player_resources,enemy_resources; TileTransformedView game; Textbox unitCreationBox,testBox,memoryAllocatorBox; + Level*currentLevel; + + std::maplevelData; QuickGUI::Manager unitCreationList; QuickGUI::ImageButton*leftShifterButton; @@ -76,6 +84,8 @@ private: bool CanAfford(Resources&resources,std::vector&unitCosts); void ExpendResources(Resources&resources,std::vector&unitCosts); void UpdateUnitCreationListGUI(bool allocatorSelected); + void LoadLevel(LevelName level); + void InitializeLevelData(); public: VirusAttack(); diff --git a/olcCodeJam2023Entry/basic_template.html b/olcCodeJam2023Entry/basic_template.html new file mode 100644 index 0000000..1d7a11d --- /dev/null +++ b/olcCodeJam2023Entry/basic_template.html @@ -0,0 +1,76 @@ + + + + + + + + Virus Attack + + + + + + + + + + + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj index c091ed5..7283692 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj @@ -144,6 +144,7 @@ + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters index 53714b6..cc5fe97 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters @@ -93,6 +93,9 @@ Header Files + + Header Files + diff --git a/olcCodeJam2023Entry/olcPixelGameEngine.h b/olcCodeJam2023Entry/olcPixelGameEngine.h index 63c22af..003cf4c 100644 --- a/olcCodeJam2023Entry/olcPixelGameEngine.h +++ b/olcCodeJam2023Entry/olcPixelGameEngine.h @@ -3973,6 +3973,8 @@ namespace olc struct tagPOINT p{0,0}; GetCursorPos(&p); olc_UpdateScreenMouse(p.x,p.y); + olc_UpdateMouseState(0,GetAsyncKeyState(VK_LBUTTON)>>7); + olc_UpdateMouseState(1,GetAsyncKeyState(VK_RBUTTON)>>7); #endif if (!OnUserUpdate(fElapsedTime)) bAtomActive = false; @@ -6408,7 +6410,11 @@ namespace olc // dimensions of the canvas container's element. Module.olc_AspectRatio = $0 / $1; + Module.olc_MOUSEDOWN=-1; + Module.olc_MOUSEUP=-1; onmousemove = function(e){Module.olc_MOUSEX=e.clientX;Module.olc_MOUSEY=e.clientY;}; + onmousedown = function(e){Module.olc_MOUSEDOWN=e.button;}; + onmouseup = function(e){Module.olc_MOUSEUP=e.button;}; ontouchmove = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; ontouchstart = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; // HACK ALERT! @@ -6639,6 +6645,18 @@ namespace olc ptrPGE->olc_UpdateWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top})); vi2d screenMousePos = {EM_ASM_INT({return Module.olc_MOUSEX;}),EM_ASM_INT({return Module.olc_MOUSEY;})}; ptrPGE->olc_UpdateScreenMouse(screenMousePos.x,screenMousePos.y); + int mouseDown=EM_ASM_INT({return Module.olc_MOUSEDOWN}); + int mouseUp=EM_ASM_INT({return Module.olc_MOUSEUP}); + if(mouseDown!=-1){ + if(mouseDown==2){mouseDown=1;}//Javascript uses button 2 as right click while PGE uses button 1. This translates it back. + ptrPGE->olc_UpdateMouseState(mouseDown,true); + EM_ASM({Module.olc_MOUSEDOWN=-1}); + } + if(mouseUp!=-1){ + if(mouseUp==2){mouseUp=1;}//Javascript uses button 2 as right click while PGE uses button 1. This translates it back. + ptrPGE->olc_UpdateMouseState(mouseUp,false); + EM_ASM({Module.olc_MOUSEUP=-1}); + } olc::Platform::ptrPGE->olc_CoreUpdate(); if (!ptrPGE->olc_IsRunning()) { diff --git a/olcCodeJam2023Entry/pge.data b/olcCodeJam2023Entry/pge.data index 1946f36..c2035b5 100644 Binary files a/olcCodeJam2023Entry/pge.data and b/olcCodeJam2023Entry/pge.data differ diff --git a/olcCodeJam2023Entry/pge.js b/olcCodeJam2023Entry/pge.js index 9845596..075a143 100644 --- a/olcCodeJam2023Entry/pge.js +++ b/olcCodeJam2023Entry/pge.js @@ -190,7 +190,7 @@ Module['FS_createPath']("/", "assets", true, true); } } - loadPackage({"files": [{"filename": "/assets/MAINICON.ico", "start": 0, "end": 766}, {"filename": "/assets/atk.png", "start": 766, "end": 1443}, {"filename": "/assets/attackLine.png", "start": 1443, "end": 2084}, {"filename": "/assets/bit_restorer.png", "start": 2084, "end": 11632}, {"filename": "/assets/corrupter.png", "start": 11632, "end": 22695}, {"filename": "/assets/down_arrow.png", "start": 22695, "end": 23336}, {"filename": "/assets/left_shifter.png", "start": 23336, "end": 32541}, {"filename": "/assets/machine2.wav", "start": 32541, "end": 111149, "audio": 1}, {"filename": "/assets/material.png", "start": 111149, "end": 111844}, {"filename": "/assets/memory_collection_point.png", "start": 111844, "end": 112790}, {"filename": "/assets/memory_collection_point_highlight.png", "start": 112790, "end": 124867}, {"filename": "/assets/memory_swapper.png", "start": 124867, "end": 136317}, {"filename": "/assets/minimap_hud.png", "start": 136317, "end": 139775}, {"filename": "/assets/outline.png", "start": 139775, "end": 140384}, {"filename": "/assets/prc.png", "start": 140384, "end": 149687}, {"filename": "/assets/prc_icon.png", "start": 149687, "end": 150439}, {"filename": "/assets/ram_bank.png", "start": 150439, "end": 152703}, {"filename": "/assets/range_indicator.png", "start": 152703, "end": 161738}, {"filename": "/assets/red_x.png", "start": 161738, "end": 162350}, {"filename": "/assets/right_shifter.png", "start": 162350, "end": 171574}, {"filename": "/assets/rld.png", "start": 171574, "end": 179245}, {"filename": "/assets/rld_icon.png", "start": 179245, "end": 179911}, {"filename": "/assets/rng.png", "start": 179911, "end": 189043}, {"filename": "/assets/rng_icon.png", "start": 189043, "end": 189750}, {"filename": "/assets/selection_circle.png", "start": 189750, "end": 190429}, {"filename": "/assets/shell.png", "start": 190429, "end": 197303}, {"filename": "/assets/sonar.wav", "start": 197303, "end": 453791, "audio": 1}, {"filename": "/assets/spd.png", "start": 453791, "end": 462333}, {"filename": "/assets/spd_icon.png", "start": 462333, "end": 463024}, {"filename": "/assets/targetLine.png", "start": 463024, "end": 463646}, {"filename": "/assets/tile.png", "start": 463646, "end": 464981}, {"filename": "/assets/unit.png", "start": 464981, "end": 465711}], "remote_package_size": 465711}); + loadPackage({"files": [{"filename": "/assets/MAINICON.ico", "start": 0, "end": 766}, {"filename": "/assets/atk.png", "start": 766, "end": 1443}, {"filename": "/assets/attackLine.png", "start": 1443, "end": 2084}, {"filename": "/assets/bit_restorer.png", "start": 2084, "end": 11632}, {"filename": "/assets/corrupter.png", "start": 11632, "end": 22695}, {"filename": "/assets/cosmos.mp3", "start": 22695, "end": 9174299, "audio": 1}, {"filename": "/assets/down_arrow.png", "start": 9174299, "end": 9174940}, {"filename": "/assets/gravity.mp3", "start": 9174940, "end": 16853462, "audio": 1}, {"filename": "/assets/left_shifter.png", "start": 16853462, "end": 16862667}, {"filename": "/assets/machine2.wav", "start": 16862667, "end": 16941275, "audio": 1}, {"filename": "/assets/material.png", "start": 16941275, "end": 16941970}, {"filename": "/assets/memory_collection_point.png", "start": 16941970, "end": 16942916}, {"filename": "/assets/memory_collection_point_highlight.png", "start": 16942916, "end": 16954993}, {"filename": "/assets/memory_swapper.png", "start": 16954993, "end": 16966443}, {"filename": "/assets/minimap_hud.png", "start": 16966443, "end": 16969901}, {"filename": "/assets/outline.png", "start": 16969901, "end": 16970510}, {"filename": "/assets/prc.png", "start": 16970510, "end": 16979813}, {"filename": "/assets/prc_icon.png", "start": 16979813, "end": 16980565}, {"filename": "/assets/ram_bank.png", "start": 16980565, "end": 16982829}, {"filename": "/assets/range_indicator.png", "start": 16982829, "end": 16991864}, {"filename": "/assets/red_x.png", "start": 16991864, "end": 16992476}, {"filename": "/assets/right_shifter.png", "start": 16992476, "end": 17001700}, {"filename": "/assets/rld.png", "start": 17001700, "end": 17009371}, {"filename": "/assets/rld_icon.png", "start": 17009371, "end": 17010037}, {"filename": "/assets/rng.png", "start": 17010037, "end": 17019169}, {"filename": "/assets/rng_icon.png", "start": 17019169, "end": 17019876}, {"filename": "/assets/selection_circle.png", "start": 17019876, "end": 17020555}, {"filename": "/assets/shell.png", "start": 17020555, "end": 17027429}, {"filename": "/assets/sonar.wav", "start": 17027429, "end": 17283917, "audio": 1}, {"filename": "/assets/spd.png", "start": 17283917, "end": 17292459}, {"filename": "/assets/spd_icon.png", "start": 17292459, "end": 17293150}, {"filename": "/assets/targetLine.png", "start": 17293150, "end": 17293772}, {"filename": "/assets/tile.png", "start": 17293772, "end": 17295107}, {"filename": "/assets/unit.png", "start": 17295107, "end": 17295837}], "remote_package_size": 17295837}); })(); @@ -1187,27 +1187,31 @@ function dbg(text) { // === Body === var ASM_CONSTS = { - 5371724: () => { return Module.canvas.getBoundingClientRect().left }, - 5371776: () => { return Module.canvas.getBoundingClientRect().top }, - 5371827: () => { return Module.olc_MOUSEX; }, - 5371855: () => { return Module.olc_MOUSEY; }, - 5371883: () => { window.onunload = Module._olc_OnPageUnload; }, - 5371927: ($0, $1) => { Module.olc_AspectRatio = $0 / $1; onmousemove = function(e){Module.olc_MOUSEX=e.clientX;Module.olc_MOUSEY=e.clientY;}; ontouchmove = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; ontouchstart = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; Module.olc_AssumeDefaultShells = (document.querySelectorAll('.emscripten').length >= 3) ? true : false; var olc_ResizeHandler = function() { let isFullscreen = (document.fullscreenElement != null); let width = (isFullscreen) ? window.innerWidth : Module.canvas.parentNode.clientWidth; let height = (isFullscreen) ? window.innerHeight : Module.canvas.parentNode.clientHeight; let viewWidth = width; let viewHeight = width / Module.olc_AspectRatio; if(viewHeight > height) { viewWidth = height * Module.olc_AspectRatio; viewHeight = height; } viewWidth = parseInt(viewWidth); viewHeight = parseInt(viewHeight); setTimeout(function() { if(Module.olc_AssumeDefaultShells) Module.canvas.parentNode.setAttribute('style', 'width: 100%; height: 70vh; margin-left: auto; margin-right: auto;'); Module.canvas.setAttribute('width', viewWidth); Module.canvas.setAttribute('height', viewHeight); Module.canvas.setAttribute('style', `width: ${viewWidth}px; height: ${viewHeight}px;`); Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight); Module.canvas.focus(); }, 200); }; var olc_Init = function() { if(Module.olc_AspectRatio === undefined) { setTimeout(function() { Module.olc_Init(); }, 50); return; } let resizeObserver = new ResizeObserver(function(entries) { Module.olc_ResizeHandler(); }).observe(Module.canvas.parentNode); let mutationObserver = new MutationObserver(function(mutationsList, observer) { setTimeout(function() { Module.olc_ResizeHandler(); }, 200); }).observe(Module.canvas.parentNode, { attributes: false, childList: true, subtree: false }); window.addEventListener('fullscreenchange', function(e) { setTimeout(function() { Module.olc_ResizeHandler();}, 200); }); }; Module.olc_ResizeHandler = (Module.olc_ResizeHandler != undefined) ? Module.olc_ResizeHandler : olc_ResizeHandler; Module.olc_Init = (Module.olc_Init != undefined) ? Module.olc_Init : olc_Init; Module.olc_Init(); }, - 5374159: () => { if (typeof(AudioContext) !== 'undefined') { return true; } else if (typeof(webkitAudioContext) !== 'undefined') { return true; } return false; }, - 5374306: () => { if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) { return true; } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') { return true; } return false; }, - 5374540: ($0) => { if(typeof(Module['SDL2']) === 'undefined') { Module['SDL2'] = {}; } var SDL2 = Module['SDL2']; if (!$0) { SDL2.audio = {}; } else { SDL2.capture = {}; } if (!SDL2.audioContext) { if (typeof(AudioContext) !== 'undefined') { SDL2.audioContext = new AudioContext(); } else if (typeof(webkitAudioContext) !== 'undefined') { SDL2.audioContext = new webkitAudioContext(); } if (SDL2.audioContext) { autoResumeAudioContext(SDL2.audioContext); } } return SDL2.audioContext === undefined ? -1 : 0; }, - 5375033: () => { var SDL2 = Module['SDL2']; return SDL2.audioContext.sampleRate; }, - 5375101: ($0, $1, $2, $3) => { var SDL2 = Module['SDL2']; var have_microphone = function(stream) { if (SDL2.capture.silenceTimer !== undefined) { clearTimeout(SDL2.capture.silenceTimer); SDL2.capture.silenceTimer = undefined; } SDL2.capture.mediaStreamNode = SDL2.audioContext.createMediaStreamSource(stream); SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1); SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) { if ((SDL2 === undefined) || (SDL2.capture === undefined)) { return; } audioProcessingEvent.outputBuffer.getChannelData(0).fill(0.0); SDL2.capture.currentCaptureBuffer = audioProcessingEvent.inputBuffer; dynCall('vi', $2, [$3]); }; SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode); SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination); SDL2.capture.stream = stream; }; var no_microphone = function(error) { }; SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate); SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0); var silence_callback = function() { SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer; dynCall('vi', $2, [$3]); }; SDL2.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL2.audioContext.sampleRate) * 1000); if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) { navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone); } else if (navigator.webkitGetUserMedia !== undefined) { navigator.webkitGetUserMedia({ audio: true, video: false }, have_microphone, no_microphone); } }, - 5376753: ($0, $1, $2, $3) => { var SDL2 = Module['SDL2']; SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0); SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) { if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; } SDL2.audio.currentOutputBuffer = e['outputBuffer']; dynCall('vi', $2, [$3]); }; SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']); }, - 5377163: ($0, $1) => { var SDL2 = Module['SDL2']; var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels; for (var c = 0; c < numChannels; ++c) { var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c); if (channelData.length != $1) { throw 'Web Audio capture buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!'; } if (numChannels == 1) { for (var j = 0; j < $1; ++j) { setValue($0 + (j * 4), channelData[j], 'float'); } } else { for (var j = 0; j < $1; ++j) { setValue($0 + (((j * numChannels) + c) * 4), channelData[j], 'float'); } } } }, - 5377768: ($0, $1) => { var SDL2 = Module['SDL2']; var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels']; for (var c = 0; c < numChannels; ++c) { var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c); if (channelData.length != $1) { throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!'; } for (var j = 0; j < $1; ++j) { channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; } } }, - 5378248: ($0) => { var SDL2 = Module['SDL2']; if ($0) { if (SDL2.capture.silenceTimer !== undefined) { clearTimeout(SDL2.capture.silenceTimer); } if (SDL2.capture.stream !== undefined) { var tracks = SDL2.capture.stream.getAudioTracks(); for (var i = 0; i < tracks.length; i++) { SDL2.capture.stream.removeTrack(tracks[i]); } SDL2.capture.stream = undefined; } if (SDL2.capture.scriptProcessorNode !== undefined) { SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {}; SDL2.capture.scriptProcessorNode.disconnect(); SDL2.capture.scriptProcessorNode = undefined; } if (SDL2.capture.mediaStreamNode !== undefined) { SDL2.capture.mediaStreamNode.disconnect(); SDL2.capture.mediaStreamNode = undefined; } if (SDL2.capture.silenceBuffer !== undefined) { SDL2.capture.silenceBuffer = undefined } SDL2.capture = undefined; } else { if (SDL2.audio.scriptProcessorNode != undefined) { SDL2.audio.scriptProcessorNode.disconnect(); SDL2.audio.scriptProcessorNode = undefined; } SDL2.audio = undefined; } if ((SDL2.audioContext !== undefined) && (SDL2.audio === undefined) && (SDL2.capture === undefined)) { SDL2.audioContext.close(); SDL2.audioContext = undefined; } }, - 5379420: ($0, $1, $2) => { var w = $0; var h = $1; var pixels = $2; if (!Module['SDL2']) Module['SDL2'] = {}; var SDL2 = Module['SDL2']; if (SDL2.ctxCanvas !== Module['canvas']) { SDL2.ctx = Module['createContext'](Module['canvas'], false, true); SDL2.ctxCanvas = Module['canvas']; } if (SDL2.w !== w || SDL2.h !== h || SDL2.imageCtx !== SDL2.ctx) { SDL2.image = SDL2.ctx.createImageData(w, h); SDL2.w = w; SDL2.h = h; SDL2.imageCtx = SDL2.ctx; } var data = SDL2.image.data; var src = pixels >> 2; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { num = data.length; while (dst < num) { var val = HEAP32[src]; data[dst ] = val & 0xff; data[dst+1] = (val >> 8) & 0xff; data[dst+2] = (val >> 16) & 0xff; data[dst+3] = 0xff; src++; dst += 4; } } else { if (SDL2.data32Data !== data) { SDL2.data32 = new Int32Array(data.buffer); SDL2.data8 = new Uint8Array(data.buffer); SDL2.data32Data = data; } var data32 = SDL2.data32; num = data32.length; data32.set(HEAP32.subarray(src, src + num)); var data8 = SDL2.data8; var i = 3; var j = i + 4*num; if (num % 8 == 0) { while (i < j) { data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; } } else { while (i < j) { data8[i] = 0xff; i = i + 4 | 0; } } } SDL2.ctx.putImageData(SDL2.image, 0, 0); }, - 5380889: ($0, $1, $2, $3, $4) => { var w = $0; var h = $1; var hot_x = $2; var hot_y = $3; var pixels = $4; var canvas = document.createElement("canvas"); canvas.width = w; canvas.height = h; var ctx = canvas.getContext("2d"); var image = ctx.createImageData(w, h); var data = image.data; var src = pixels >> 2; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { num = data.length; while (dst < num) { var val = HEAP32[src]; data[dst ] = val & 0xff; data[dst+1] = (val >> 8) & 0xff; data[dst+2] = (val >> 16) & 0xff; data[dst+3] = (val >> 24) & 0xff; src++; dst += 4; } } else { var data32 = new Int32Array(data.buffer); num = data32.length; data32.set(HEAP32.subarray(src, src + num)); } ctx.putImageData(image, 0, 0); var url = hot_x === 0 && hot_y === 0 ? "url(" + canvas.toDataURL() + "), auto" : "url(" + canvas.toDataURL() + ") " + hot_x + " " + hot_y + ", auto"; var urlBuf = _malloc(url.length + 1); stringToUTF8(url, urlBuf, url.length + 1); return urlBuf; }, - 5381878: ($0) => { if (Module['canvas']) { Module['canvas'].style['cursor'] = UTF8ToString($0); } }, - 5381961: () => { if (Module['canvas']) { Module['canvas'].style['cursor'] = 'none'; } }, - 5382030: () => { return window.innerWidth; }, - 5382060: () => { return window.innerHeight; } + 5371644: () => { return Module.canvas.getBoundingClientRect().left }, + 5371696: () => { return Module.canvas.getBoundingClientRect().top }, + 5371747: () => { return Module.olc_MOUSEX; }, + 5371775: () => { return Module.olc_MOUSEY; }, + 5371803: () => { return Module.olc_MOUSEDOWN }, + 5371833: () => { return Module.olc_MOUSEUP }, + 5371861: () => { Module.olc_MOUSEDOWN=-1 }, + 5371887: () => { Module.olc_MOUSEUP=-1 }, + 5371911: () => { window.onunload = Module._olc_OnPageUnload; }, + 5371955: ($0, $1) => { Module.olc_AspectRatio = $0 / $1; Module.olc_MOUSEDOWN=-1; Module.olc_MOUSEUP=-1; onmousemove = function(e){Module.olc_MOUSEX=e.clientX;Module.olc_MOUSEY=e.clientY;}; onmousedown = function(e){Module.olc_MOUSEDOWN=e.button;}; onmouseup = function(e){Module.olc_MOUSEUP=e.button;}; ontouchmove = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; ontouchstart = function(e){Module.olc_MOUSEX=e.touches[0].clientX;Module.olc_MOUSEY=e.touches[0].clientY;}; Module.olc_AssumeDefaultShells = (document.querySelectorAll('.emscripten').length >= 3) ? true : false; var olc_ResizeHandler = function() { let isFullscreen = (document.fullscreenElement != null); let width = (isFullscreen) ? window.innerWidth : Module.canvas.parentNode.clientWidth; let height = (isFullscreen) ? window.innerHeight : Module.canvas.parentNode.clientHeight; let viewWidth = width; let viewHeight = width / Module.olc_AspectRatio; if(viewHeight > height) { viewWidth = height * Module.olc_AspectRatio; viewHeight = height; } viewWidth = parseInt(viewWidth); viewHeight = parseInt(viewHeight); setTimeout(function() { if(Module.olc_AssumeDefaultShells) Module.canvas.parentNode.setAttribute('style', 'width: 100%; height: 70vh; margin-left: auto; margin-right: auto;'); Module.canvas.setAttribute('width', viewWidth); Module.canvas.setAttribute('height', viewHeight); Module.canvas.setAttribute('style', `width: ${viewWidth}px; height: ${viewHeight}px;`); Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight); Module.canvas.focus(); }, 200); }; var olc_Init = function() { if(Module.olc_AspectRatio === undefined) { setTimeout(function() { Module.olc_Init(); }, 50); return; } let resizeObserver = new ResizeObserver(function(entries) { Module.olc_ResizeHandler(); }).observe(Module.canvas.parentNode); let mutationObserver = new MutationObserver(function(mutationsList, observer) { setTimeout(function() { Module.olc_ResizeHandler(); }, 200); }).observe(Module.canvas.parentNode, { attributes: false, childList: true, subtree: false }); window.addEventListener('fullscreenchange', function(e) { setTimeout(function() { Module.olc_ResizeHandler();}, 200); }); }; Module.olc_ResizeHandler = (Module.olc_ResizeHandler != undefined) ? Module.olc_ResizeHandler : olc_ResizeHandler; Module.olc_Init = (Module.olc_Init != undefined) ? Module.olc_Init : olc_Init; Module.olc_Init(); }, + 5374349: () => { if (typeof(AudioContext) !== 'undefined') { return true; } else if (typeof(webkitAudioContext) !== 'undefined') { return true; } return false; }, + 5374496: () => { if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) { return true; } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') { return true; } return false; }, + 5374730: ($0) => { if(typeof(Module['SDL2']) === 'undefined') { Module['SDL2'] = {}; } var SDL2 = Module['SDL2']; if (!$0) { SDL2.audio = {}; } else { SDL2.capture = {}; } if (!SDL2.audioContext) { if (typeof(AudioContext) !== 'undefined') { SDL2.audioContext = new AudioContext(); } else if (typeof(webkitAudioContext) !== 'undefined') { SDL2.audioContext = new webkitAudioContext(); } if (SDL2.audioContext) { autoResumeAudioContext(SDL2.audioContext); } } return SDL2.audioContext === undefined ? -1 : 0; }, + 5375223: () => { var SDL2 = Module['SDL2']; return SDL2.audioContext.sampleRate; }, + 5375291: ($0, $1, $2, $3) => { var SDL2 = Module['SDL2']; var have_microphone = function(stream) { if (SDL2.capture.silenceTimer !== undefined) { clearTimeout(SDL2.capture.silenceTimer); SDL2.capture.silenceTimer = undefined; } SDL2.capture.mediaStreamNode = SDL2.audioContext.createMediaStreamSource(stream); SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1); SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) { if ((SDL2 === undefined) || (SDL2.capture === undefined)) { return; } audioProcessingEvent.outputBuffer.getChannelData(0).fill(0.0); SDL2.capture.currentCaptureBuffer = audioProcessingEvent.inputBuffer; dynCall('vi', $2, [$3]); }; SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode); SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination); SDL2.capture.stream = stream; }; var no_microphone = function(error) { }; SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate); SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0); var silence_callback = function() { SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer; dynCall('vi', $2, [$3]); }; SDL2.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL2.audioContext.sampleRate) * 1000); if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) { navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone); } else if (navigator.webkitGetUserMedia !== undefined) { navigator.webkitGetUserMedia({ audio: true, video: false }, have_microphone, no_microphone); } }, + 5376943: ($0, $1, $2, $3) => { var SDL2 = Module['SDL2']; SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0); SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) { if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; } SDL2.audio.currentOutputBuffer = e['outputBuffer']; dynCall('vi', $2, [$3]); }; SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']); }, + 5377353: ($0, $1) => { var SDL2 = Module['SDL2']; var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels; for (var c = 0; c < numChannels; ++c) { var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c); if (channelData.length != $1) { throw 'Web Audio capture buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!'; } if (numChannels == 1) { for (var j = 0; j < $1; ++j) { setValue($0 + (j * 4), channelData[j], 'float'); } } else { for (var j = 0; j < $1; ++j) { setValue($0 + (((j * numChannels) + c) * 4), channelData[j], 'float'); } } } }, + 5377958: ($0, $1) => { var SDL2 = Module['SDL2']; var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels']; for (var c = 0; c < numChannels; ++c) { var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c); if (channelData.length != $1) { throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!'; } for (var j = 0; j < $1; ++j) { channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; } } }, + 5378438: ($0) => { var SDL2 = Module['SDL2']; if ($0) { if (SDL2.capture.silenceTimer !== undefined) { clearTimeout(SDL2.capture.silenceTimer); } if (SDL2.capture.stream !== undefined) { var tracks = SDL2.capture.stream.getAudioTracks(); for (var i = 0; i < tracks.length; i++) { SDL2.capture.stream.removeTrack(tracks[i]); } SDL2.capture.stream = undefined; } if (SDL2.capture.scriptProcessorNode !== undefined) { SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {}; SDL2.capture.scriptProcessorNode.disconnect(); SDL2.capture.scriptProcessorNode = undefined; } if (SDL2.capture.mediaStreamNode !== undefined) { SDL2.capture.mediaStreamNode.disconnect(); SDL2.capture.mediaStreamNode = undefined; } if (SDL2.capture.silenceBuffer !== undefined) { SDL2.capture.silenceBuffer = undefined } SDL2.capture = undefined; } else { if (SDL2.audio.scriptProcessorNode != undefined) { SDL2.audio.scriptProcessorNode.disconnect(); SDL2.audio.scriptProcessorNode = undefined; } SDL2.audio = undefined; } if ((SDL2.audioContext !== undefined) && (SDL2.audio === undefined) && (SDL2.capture === undefined)) { SDL2.audioContext.close(); SDL2.audioContext = undefined; } }, + 5379610: ($0, $1, $2) => { var w = $0; var h = $1; var pixels = $2; if (!Module['SDL2']) Module['SDL2'] = {}; var SDL2 = Module['SDL2']; if (SDL2.ctxCanvas !== Module['canvas']) { SDL2.ctx = Module['createContext'](Module['canvas'], false, true); SDL2.ctxCanvas = Module['canvas']; } if (SDL2.w !== w || SDL2.h !== h || SDL2.imageCtx !== SDL2.ctx) { SDL2.image = SDL2.ctx.createImageData(w, h); SDL2.w = w; SDL2.h = h; SDL2.imageCtx = SDL2.ctx; } var data = SDL2.image.data; var src = pixels >> 2; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { num = data.length; while (dst < num) { var val = HEAP32[src]; data[dst ] = val & 0xff; data[dst+1] = (val >> 8) & 0xff; data[dst+2] = (val >> 16) & 0xff; data[dst+3] = 0xff; src++; dst += 4; } } else { if (SDL2.data32Data !== data) { SDL2.data32 = new Int32Array(data.buffer); SDL2.data8 = new Uint8Array(data.buffer); SDL2.data32Data = data; } var data32 = SDL2.data32; num = data32.length; data32.set(HEAP32.subarray(src, src + num)); var data8 = SDL2.data8; var i = 3; var j = i + 4*num; if (num % 8 == 0) { while (i < j) { data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; data8[i] = 0xff; i = i + 4 | 0; } } else { while (i < j) { data8[i] = 0xff; i = i + 4 | 0; } } } SDL2.ctx.putImageData(SDL2.image, 0, 0); }, + 5381079: ($0, $1, $2, $3, $4) => { var w = $0; var h = $1; var hot_x = $2; var hot_y = $3; var pixels = $4; var canvas = document.createElement("canvas"); canvas.width = w; canvas.height = h; var ctx = canvas.getContext("2d"); var image = ctx.createImageData(w, h); var data = image.data; var src = pixels >> 2; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { num = data.length; while (dst < num) { var val = HEAP32[src]; data[dst ] = val & 0xff; data[dst+1] = (val >> 8) & 0xff; data[dst+2] = (val >> 16) & 0xff; data[dst+3] = (val >> 24) & 0xff; src++; dst += 4; } } else { var data32 = new Int32Array(data.buffer); num = data32.length; data32.set(HEAP32.subarray(src, src + num)); } ctx.putImageData(image, 0, 0); var url = hot_x === 0 && hot_y === 0 ? "url(" + canvas.toDataURL() + "), auto" : "url(" + canvas.toDataURL() + ") " + hot_x + " " + hot_y + ", auto"; var urlBuf = _malloc(url.length + 1); stringToUTF8(url, urlBuf, url.length + 1); return urlBuf; }, + 5382068: ($0) => { if (Module['canvas']) { Module['canvas'].style['cursor'] = UTF8ToString($0); } }, + 5382151: () => { if (Module['canvas']) { Module['canvas'].style['cursor'] = 'none'; } }, + 5382220: () => { return window.innerWidth; }, + 5382250: () => { return window.innerHeight; } }; diff --git a/olcCodeJam2023Entry/pge.wasm b/olcCodeJam2023Entry/pge.wasm index 8581683..94f1255 100644 Binary files a/olcCodeJam2023Entry/pge.wasm and b/olcCodeJam2023Entry/pge.wasm differ