You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
1.8 KiB
94 lines
1.8 KiB
#pragma once
|
|
|
|
#include "olcPixelGameEngine.h"
|
|
#include "Constant.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;
|
|
void Update(float fElapsedTime);
|
|
virtual void Attack(Unit&victim)=0;
|
|
virtual void Draw(PixelGameEngine*pge);
|
|
bool IsFriendly();
|
|
bool IsSelected();
|
|
void Select();
|
|
void Deselect();
|
|
vf2d GetPos();
|
|
bool IsDead();
|
|
vf2d GetUnitSize();
|
|
void SetTargetUnit(std::weak_ptr<Unit>target);
|
|
void SetTargetLocation(vf2d targetLoc);
|
|
void SetPos(vf2d newPos);
|
|
void AttemptAttack(Unit*unit);
|
|
|
|
|
|
std::vector<bool>& operator <<=(const int n){
|
|
for(int i=0;i<GetMemorySize()-1;i++){
|
|
memory[i]=memory[i+1];
|
|
}
|
|
memory[GetMemorySize()-1]=0;
|
|
return memory;
|
|
}
|
|
|
|
std::vector<bool>& operator >>=(const int n){
|
|
for(int i=GetMemorySize()-1;i>0;i--){
|
|
memory[i]=memory[i-1];
|
|
}
|
|
memory[0]=0;
|
|
return memory;
|
|
}
|
|
protected:
|
|
vf2d pos;
|
|
bool friendly;
|
|
Renderable&img;
|
|
Marker health;
|
|
Marker range;
|
|
Marker atkSpd;
|
|
Marker moveSpd;
|
|
Marker procedure;
|
|
std::weak_ptr<Unit>target;
|
|
vf2d targetLoc=CONSTANT::UNSELECTED;
|
|
private:
|
|
int GetBits(Marker&m);
|
|
bool selected=false;
|
|
bool dead=false;
|
|
bool InRange(std::shared_ptr<Unit>target);
|
|
bool InRange(vf2d pos);
|
|
float reloadTimer=0;
|
|
void _Attack(Unit*finalTarget);
|
|
};
|
|
|
|
struct BasicUnit:Unit{
|
|
BasicUnit(vf2d pos,Renderable&img,bool friendly=false);
|
|
void Attack(Unit&victim)override;
|
|
};
|
|
|
|
struct BasicUnit2:Unit{
|
|
BasicUnit2(vf2d pos,Renderable&img,bool friendly=false);
|
|
void Attack(Unit&victim)override;
|
|
}; |