Initial setup for Units
This commit is contained in:
parent
84881f1706
commit
a413e45842
108
olcCodeJam2023Entry/Unit.cpp
Normal file
108
olcCodeJam2023Entry/Unit.cpp
Normal file
@ -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::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly)
|
||||||
|
:pos(pos),img(img),friendly(friendly){
|
||||||
|
int marker=0;
|
||||||
|
for(Memory&mem:memory){
|
||||||
|
for(int i=0;i<mem.size;i++){
|
||||||
|
this->memory.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<m.size;i++){
|
||||||
|
if(memory[i+m.index]){
|
||||||
|
activeBits++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activeBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetHealth(){
|
||||||
|
return GetBits(health);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetRange(){
|
||||||
|
return GetBits(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetAtkSpd(){
|
||||||
|
return GetBits(atkSpd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetMoveSpd(){
|
||||||
|
return GetBits(moveSpd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetProcedure(){
|
||||||
|
return GetBits(procedure);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Unit::GetMemorySize(){
|
||||||
|
return memory.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasicUnit::Update(float fElapsedTime){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit& operator <<(Unit&u,const int n){
|
||||||
|
for(int i=0;i<u.GetMemorySize()-1;i++){
|
||||||
|
u.memory[i]=u.memory[i+1];
|
||||||
|
}
|
||||||
|
u.memory[u.GetMemorySize()-1]=0;
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit& operator >>(Unit&u,const int n){
|
||||||
|
for(int i=1;i<u.GetMemorySize();i++){
|
||||||
|
u.memory[i]=u.memory[i-1];
|
||||||
|
}
|
||||||
|
u.memory[0]=0;
|
||||||
|
return u;
|
||||||
|
}
|
51
olcCodeJam2023Entry/Unit.h
Normal file
51
olcCodeJam2023Entry/Unit.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "olcPixelGameEngine.h"
|
||||||
|
|
||||||
|
struct Marker{
|
||||||
|
size_t index;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MemoryType{
|
||||||
|
HEALTH,
|
||||||
|
RANGE,
|
||||||
|
ATKSPD,
|
||||||
|
MOVESPD,
|
||||||
|
PROCEDURE
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Memory{
|
||||||
|
MemoryType type;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Unit{
|
||||||
|
public:
|
||||||
|
Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly=false);
|
||||||
|
int GetHealth();
|
||||||
|
int GetRange();
|
||||||
|
int GetAtkSpd();
|
||||||
|
int GetMoveSpd();
|
||||||
|
int GetProcedure();
|
||||||
|
int GetMemorySize();
|
||||||
|
std::vector<bool>memory;
|
||||||
|
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;
|
||||||
|
};
|
@ -12,21 +12,29 @@ VirusAttack::VirusAttack()
|
|||||||
|
|
||||||
bool VirusAttack::OnUserCreate(){
|
bool VirusAttack::OnUserCreate(){
|
||||||
// Called once at the start, so create things here
|
// Called once at the start, so create things here
|
||||||
|
|
||||||
|
VIRUS_IMG1.Load("assets/unit.png");
|
||||||
|
|
||||||
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},VIRUS_IMG1,true));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||||
// Called once per frame, draws random coloured pixels
|
// Called once per frame, draws random coloured pixels
|
||||||
for (int x = 0; x < ScreenWidth(); x++)
|
for(std::unique_ptr<Unit>&u:units){
|
||||||
for (int y = 0; y < ScreenHeight(); y++)
|
u->Update(fElapsedTime);
|
||||||
Draw(x, y, olc::Pixel(rand() % 256, rand() % 256, rand() % 256));
|
}
|
||||||
|
|
||||||
|
for(std::unique_ptr<Unit>&u:units){
|
||||||
|
u->Draw(this);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
VirusAttack app;
|
VirusAttack app;
|
||||||
if (app.Construct(256, 240, 4, 4))
|
if (app.Construct(240, 160, 4, 4))
|
||||||
app.Start();
|
app.Start();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,8 +1,11 @@
|
|||||||
#include "olcPixelGameEngine.h"
|
#include "olcPixelGameEngine.h"
|
||||||
#include "olcSoundWaveEngine.h"
|
#include "olcSoundWaveEngine.h"
|
||||||
|
#include "Unit.h"
|
||||||
class VirusAttack : public olc::PixelGameEngine
|
class VirusAttack : public olc::PixelGameEngine
|
||||||
{
|
{
|
||||||
|
Renderable VIRUS_IMG1;
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<Unit>>units;
|
||||||
public:
|
public:
|
||||||
VirusAttack();
|
VirusAttack();
|
||||||
|
|
||||||
|
@ -141,9 +141,11 @@
|
|||||||
<ClInclude Include="olcUTIL_Geometry2D.h" />
|
<ClInclude Include="olcUTIL_Geometry2D.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="resource1.h" />
|
<ClInclude Include="resource1.h" />
|
||||||
|
<ClInclude Include="Unit.h" />
|
||||||
<ClInclude Include="VirusAttack.h" />
|
<ClInclude Include="VirusAttack.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Unit.cpp" />
|
||||||
<ClCompile Include="VirusAttack.cpp" />
|
<ClCompile Include="VirusAttack.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -48,11 +48,17 @@
|
|||||||
<ClInclude Include="VirusAttack.h">
|
<ClInclude Include="VirusAttack.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Unit.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="VirusAttack.cpp">
|
<ClCompile Include="VirusAttack.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Unit.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="olcCodeJam2023Entry.rc">
|
<ResourceCompile Include="olcCodeJam2023Entry.rc">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user