diff --git a/olcCodeJam2023Entry/Constant.h b/olcCodeJam2023Entry/Constant.h index 50a5dd3..70a14db 100644 --- a/olcCodeJam2023Entry/Constant.h +++ b/olcCodeJam2023Entry/Constant.h @@ -1,6 +1,8 @@ #pragma once #include "olcPixelGameEngine.h" +#define PI 3.14159 + class CONSTANT{ public: static vf2d BAR_SQUARE_SIZE; diff --git a/olcCodeJam2023Entry/Image.h b/olcCodeJam2023Entry/Image.h index dda8e4d..44fceae 100644 --- a/olcCodeJam2023Entry/Image.h +++ b/olcCodeJam2023Entry/Image.h @@ -7,6 +7,8 @@ enum Image{ OUTLINE, MINIMAP_OUTLINE, VIRUS_IMG1, - SELECTION_CIRCLE + SELECTION_CIRCLE, + MATRIX, + MEMORY_COLLECTION_POINT, }; diff --git a/olcCodeJam2023Entry/Info.txt b/olcCodeJam2023Entry/Info.txt index 38676ee..d2d99e9 100644 --- a/olcCodeJam2023Entry/Info.txt +++ b/olcCodeJam2023Entry/Info.txt @@ -4,8 +4,7 @@ Bit Repair Memory Swapper Corrupter (Randomly destroys bits) -Pipes -Attach collectors to them +"Memory Collection Point" Attach collectors to them (Unit attaches to pipe) Memory Structure (Allocators) RAM Bank (Creates new Memory Structures) has its own rate of creation based on Procedure amount. diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 5ef6d31..774c9ae 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -3,6 +3,7 @@ #define OLC_PGEX_TRANSFORMEDVIEW #include "olcUTIL_Geometry2D.h" #include "TileManager.h" +#include "util.h" #include "VirusAttack.h" @@ -22,10 +23,12 @@ void VirusAttack::InitializeImages(){ 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"); } bool VirusAttack::OnUserCreate(){ + SetPixelMode(Pixel::MASK); + game.Initialise(GetScreenSize()); InitializeImages(); @@ -33,6 +36,10 @@ bool VirusAttack::OnUserCreate(){ 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); + units.push_back(std::make_unique(vf2d{32,32},*IMAGES[VIRUS_IMG1],true)); for(int i=0;i<10;i++){ if(rand()%2==0){ @@ -41,6 +48,12 @@ bool VirusAttack::OnUserCreate(){ units.push_back(std::make_unique(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false)); } } + + 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))); + } + return true; } @@ -136,11 +149,7 @@ void VirusAttack::DrawMinimap(){ vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE; vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE; SetDrawTarget(IMAGES[MINIMAP_OUTLINE]->Sprite()); - for(int y=0;y<64;y++){ - for(int x=0;x<64;x++){ - Draw(x,y,BLANK); - } - } + Clear(BLANK); DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); for(auto&u:units){ FillRect(u->GetGhostPos()/worldPixelSize*64,vf2d{2,2}*u->GetUnitSize()/24,u->IsFriendly()?GREEN:RED); @@ -184,7 +193,59 @@ void VirusAttack::HandleMinimapClick(){ } } +void VirusAttack::UpdateMatrixTexture(float fElapsedTime){ + if(matrixTimer==0){ + activeLetters.emplace_back(vf2d{float(rand()%64),float(64)},util::random(-40)-20,matrixLetters[rand()%matrixLetters.size()]); + matrixTimer=util::random(0.125); + } + if(updatePixelsTimer==0){ + SetDrawTarget(IMAGES[MATRIX]->Sprite()); + Sprite*img=IMAGES[MATRIX]->Sprite(); + for(int y=63;y>=0;y--){ + for(int x=63;x>=0;x--){ + Pixel col=img->GetPixel(x,y); + if(col.r>0){ + if(x>0){ + Pixel leftCol=img->GetPixel(x-1,y); + if(leftCol.rwidth-1){ + Pixel rightCol=img->GetPixel(x+1,y); + if(rightCol.rGetPixel(1,y)); + } + SetDrawTarget(nullptr); + updatePixelsTimer=0.1; + } + if(activeLetters.size()>0){ + SetDrawTarget(IMAGES[MATRIX]->Sprite()); + for(Letter&letter:activeLetters){ + letter.pos.y+=letter.spd*fElapsedTime; + DrawString(letter.pos,std::string(1,letter.c)); + } + SetDrawTarget(nullptr); + IMAGES[MATRIX]->Decal()->Update(); + } + matrixTimer=std::max(0.f,matrixTimer-fElapsedTime); + updatePixelsTimer=std::max(0.f,updatePixelsTimer-fElapsedTime); + std::erase_if(activeLetters,[](Letter&letter){return letter.pos.y<-32;}); +} + bool VirusAttack::OnUserUpdate(float fElapsedTime){ + UpdateMatrixTexture(fElapsedTime); HandleDraggingSelection(); HandleRightClickMove(); HandlePanAndZoom(fElapsedTime); @@ -223,6 +284,34 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ for(auto&u:units){ u->Draw(game,IMAGES); } + + for(auto&collectionPoint:collectionPoints){ + collectionPoint->Update(this,*IMAGES[MATRIX]); + geom2d::rectcpRect=geom2d::rect({collectionPoint->pos-collectionPoint->img.Sprite()->Size()/2,collectionPoint->img.Sprite()->Size()}); + geom2d::rectviewRegion=geom2d::rect({game.GetWorldTL(),game.GetWorldVisibleArea()}); + if(geom2d::overlaps(cpRect,viewRegion)){ + Pixel col; + switch(collectionPoint->type){ + case HEALTH:{ + col=CONSTANT::HEALTH_COLOR; + }break; + case RANGE:{ + col=CONSTANT::RANGE_COLOR; + }break; + case ATKSPD:{ + col=CONSTANT::ATKSPD_COLOR; + }break; + case MOVESPD:{ + col=CONSTANT::MOVESPD_COLOR; + }break; + case PROCEDURE:{ + col=CONSTANT::PROCEDURE_COLOR; + }break; + } + game.DrawRotatedDecal(collectionPoint->pos,collectionPoint->img.Decal(),collectionPoint->rot,collectionPoint->img.Sprite()->Size()/2,{1,1},col); + } + } + for(auto&u:units){ u->DrawHud(game,IMAGES); } @@ -240,9 +329,35 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawMinimap(); + DrawDecal({0,0},IMAGES[MATRIX]->Decal(),{1,1},{128,0,128}); + return true; } +VirusAttack::CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type) + :pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){ + img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height); + pge->SetDrawTarget(img.Sprite()); + pge->Clear(BLANK); + pge->DrawSprite({0,0},collectionPointImg.Sprite()); + pge->SetDrawTarget(nullptr); + img.Decal()->Update(); +} + +void VirusAttack::CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){ + pge->SetDrawTarget(img.Sprite()); + for(int y=0;yheight;y++){ + for(int x=0;xwidth;x++){ + Pixel col=originalCollectionPointImg->GetPixel(x,y); + if(col==WHITE){ + pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y))); + } + } + } + img.Decal()->Update(); + pge->SetDrawTarget(nullptr); +} + int main() { VirusAttack app; diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index eaba096..22fe37f 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -5,15 +5,38 @@ #include "Constant.h" #include "Image.h" +struct Letter{ + vf2d pos; + float spd; + char c; +}; + class VirusAttack : public olc::PixelGameEngine { + class CollectionPoint{ + public: + vf2d pos; + Renderable img; + Sprite*originalCollectionPointImg; + MemoryType type; + vf2d randomOffset; + float rot; + CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type); + void Update(PixelGameEngine*pge,Renderable&matrixImg); + }; private: std::vector>units; + std::vector>collectionPoints; std::map>IMAGES; TileTransformedView game; + float matrixTimer=0; + float updatePixelsTimer=0; + const std::arraymatrixLetters={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',}; + std::vectoractiveLetters; + vf2d startingDragPos=CONSTANT::UNSELECTED; void HandleDraggingSelection(); void DrawSelectionRectangle(); @@ -25,6 +48,7 @@ private: void DrawMinimap(); void HandleMinimapClick(); void InitializeImages(); + void UpdateMatrixTexture(float fElapsedTime); public: VirusAttack(); diff --git a/olcCodeJam2023Entry/assets/bit_restorer.png b/olcCodeJam2023Entry/assets/bit_restorer.png new file mode 100644 index 0000000..13bc0b0 Binary files /dev/null and b/olcCodeJam2023Entry/assets/bit_restorer.png differ diff --git a/olcCodeJam2023Entry/assets/corrupter.png b/olcCodeJam2023Entry/assets/corrupter.png new file mode 100644 index 0000000..0b0a658 Binary files /dev/null and b/olcCodeJam2023Entry/assets/corrupter.png differ diff --git a/olcCodeJam2023Entry/assets/left_shifter.png b/olcCodeJam2023Entry/assets/left_shifter.png new file mode 100644 index 0000000..5388670 Binary files /dev/null and b/olcCodeJam2023Entry/assets/left_shifter.png differ diff --git a/olcCodeJam2023Entry/assets/memory_collection_point.png b/olcCodeJam2023Entry/assets/memory_collection_point.png new file mode 100644 index 0000000..18ac209 Binary files /dev/null and b/olcCodeJam2023Entry/assets/memory_collection_point.png differ diff --git a/olcCodeJam2023Entry/assets/memory_swapper.png b/olcCodeJam2023Entry/assets/memory_swapper.png new file mode 100644 index 0000000..e37d3d6 Binary files /dev/null and b/olcCodeJam2023Entry/assets/memory_swapper.png differ diff --git a/olcCodeJam2023Entry/assets/right_shifter.png b/olcCodeJam2023Entry/assets/right_shifter.png new file mode 100644 index 0000000..b3bd542 Binary files /dev/null and b/olcCodeJam2023Entry/assets/right_shifter.png differ diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj index 76f7398..6fa7f16 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj @@ -145,12 +145,14 @@ + + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters index 261b99a..d1f74a4 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters @@ -63,6 +63,9 @@ Header Files + + Header Files + @@ -77,6 +80,9 @@ Source Files + + Source Files + diff --git a/olcCodeJam2023Entry/util.cpp b/olcCodeJam2023Entry/util.cpp new file mode 100644 index 0000000..f4f2b89 --- /dev/null +++ b/olcCodeJam2023Entry/util.cpp @@ -0,0 +1,8 @@ +#include "util.h" +#include "olcPixelGameEngine.h" + +namespace util{ + float random(float range){ + return float(rand())/RAND_MAX*range; + } +} \ No newline at end of file diff --git a/olcCodeJam2023Entry/util.h b/olcCodeJam2023Entry/util.h new file mode 100644 index 0000000..f5ae447 --- /dev/null +++ b/olcCodeJam2023Entry/util.h @@ -0,0 +1,5 @@ +#pragma once + +namespace util{ + float random(float range); +} \ No newline at end of file