diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp new file mode 100644 index 0000000..8ebbfaf --- /dev/null +++ b/olcCodeJam2023Entry/Unit.cpp @@ -0,0 +1,108 @@ +#include "Unit.h" + + + +BasicUnit::BasicUnit(vf2d pos,Renderable&img,bool friendly) + :Unit({ + {HEALTH,4}, + {RANGE,2}, + {ATKSPD,2}, + {MOVESPD,3}, + {PROCEDURE,1}, + },pos,img,friendly){} + + + + +Unit::Unit(std::vectormemory,vf2d pos,Renderable&img,bool friendly) +:pos(pos),img(img),friendly(friendly){ + int marker=0; + for(Memory&mem:memory){ + for(int i=0;imemory.push_back(true); + } + switch(mem.type){ + case HEALTH:{ + health.index=marker; + health.size=mem.size; + }break; + case RANGE:{ + range.index=marker; + range.size=mem.size; + }break; + case ATKSPD:{ + atkSpd.index=marker; + atkSpd.size=mem.size; + }break; + case MOVESPD:{ + moveSpd.index=marker; + moveSpd.size=mem.size; + }break; + case PROCEDURE:{ + procedure.index=marker; + procedure.size=mem.size; + }break; + } + marker+=mem.size; + } +} + + + +void Unit::Draw(PixelGameEngine*pge){ + pge->DrawRotatedDecal(pos,img.Decal(),0,img.Sprite()->Size()/2); +} + +int Unit::GetBits(Marker&m){ + int activeBits=0; + for(int i=0;i>(Unit&u,const int n){ + for(int i=1;imemory,vf2d pos,Renderable&img,bool friendly=false); + int GetHealth(); + int GetRange(); + int GetAtkSpd(); + int GetMoveSpd(); + int GetProcedure(); + int GetMemorySize(); + std::vectormemory; + virtual void Update(float fElapsedTime)=0; + virtual void Draw(PixelGameEngine*pge); +protected: + vf2d pos; + bool friendly; + Renderable&img; + Marker health; + Marker range; + Marker atkSpd; + Marker moveSpd; + Marker procedure; +private: + int GetBits(Marker&m); +}; + +struct BasicUnit:Unit{ + BasicUnit(vf2d pos,Renderable&img,bool friendly=false); + void Update(float fElapsedTime)override; +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 4edb02b..0536164 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -12,21 +12,29 @@ VirusAttack::VirusAttack() bool VirusAttack::OnUserCreate(){ // Called once at the start, so create things here + + VIRUS_IMG1.Load("assets/unit.png"); + + units.push_back(std::make_unique(vf2d{32,32},VIRUS_IMG1,true)); return true; } bool VirusAttack::OnUserUpdate(float fElapsedTime){ // Called once per frame, draws random coloured pixels - for (int x = 0; x < ScreenWidth(); x++) - for (int y = 0; y < ScreenHeight(); y++) - Draw(x, y, olc::Pixel(rand() % 256, rand() % 256, rand() % 256)); + for(std::unique_ptr&u:units){ + u->Update(fElapsedTime); + } + + for(std::unique_ptr&u:units){ + u->Draw(this); + } return true; } int main() { VirusAttack app; - if (app.Construct(256, 240, 4, 4)) + if (app.Construct(240, 160, 4, 4)) app.Start(); return 0; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 1aca66e..e327271 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -1,8 +1,11 @@ #include "olcPixelGameEngine.h" #include "olcSoundWaveEngine.h" - +#include "Unit.h" class VirusAttack : public olc::PixelGameEngine { + Renderable VIRUS_IMG1; + + std::vector>units; public: VirusAttack(); diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj index a4e3b34..76d384c 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj @@ -141,9 +141,11 @@ + + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters index 05d87c1..9b45082 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters @@ -48,11 +48,17 @@ Header Files + + Header Files + Source Files + + Source Files +