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.
179 lines
3.3 KiB
179 lines
3.3 KiB
#include "Unit.h"
|
|
#include "Constant.h"
|
|
|
|
BasicUnit::BasicUnit(vf2d pos,Renderable&img,bool friendly)
|
|
:Unit({
|
|
{HEALTH,4},
|
|
{RANGE,2},
|
|
{ATKSPD,2},
|
|
{MOVESPD,3},
|
|
{PROCEDURE,1},
|
|
},pos,img,friendly){}
|
|
|
|
|
|
void BasicUnit::Attack(Unit&victim){
|
|
|
|
}
|
|
|
|
BasicUnit2::BasicUnit2(vf2d pos,Renderable&img,bool friendly)
|
|
:Unit({
|
|
{RANGE,2},
|
|
{ATKSPD,2},
|
|
{MOVESPD,3},
|
|
{PROCEDURE,1},
|
|
{HEALTH,4},
|
|
},pos,img,friendly){}
|
|
|
|
void BasicUnit2::Attack(Unit&victim){
|
|
|
|
}
|
|
|
|
|
|
|
|
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){
|
|
int initialBarX=pos.x-GetMemorySize()/2*CONSTANT::BAR_SQUARE_SIZE.x;
|
|
int initialBarY=pos.y-CONSTANT::BAR_SQUARE_SIZE.y-img.Sprite()->height/2-2;
|
|
Pixel col=0;
|
|
|
|
|
|
auto CheckColor=[&](int i,Pixel&col){
|
|
if(health.index==i){
|
|
col=CONSTANT::HEALTH_COLOR;
|
|
}
|
|
if(range.index==i){
|
|
col=CONSTANT::RANGE_COLOR;
|
|
}
|
|
if(atkSpd.index==i){
|
|
col=CONSTANT::ATKSPD_COLOR;
|
|
}
|
|
if(moveSpd.index==i){
|
|
col=CONSTANT::MOVESPD_COLOR;
|
|
}
|
|
if(procedure.index==i){
|
|
col=CONSTANT::PROCEDURE_COLOR;
|
|
}
|
|
};
|
|
|
|
for(int i=0;i<GetMemorySize();i++){
|
|
CheckColor(i,col);
|
|
|
|
pge->FillRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
|
float(initialBarY)},CONSTANT::BAR_SQUARE_SIZE,col);
|
|
pge->DrawRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
|
float(initialBarY)},CONSTANT::BAR_SQUARE_SIZE,BLACK);
|
|
}
|
|
pge->DrawRotatedDecal(pos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192});
|
|
if(IsSelected()){
|
|
pge->DrawRotatedDecal(pos,CONSTANT::SELECTION_CIRCLE.Decal(),0,CONSTANT::SELECTION_CIRCLE.Sprite()->Size()/2,vf2d(img.Sprite()->Size())/CONSTANT::SELECTION_CIRCLE.Sprite()->Size(),WHITE);
|
|
}
|
|
}
|
|
|
|
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 Unit::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;
|
|
}
|
|
|
|
bool Unit::IsFriendly(){
|
|
return friendly;
|
|
}
|
|
|
|
|
|
bool Unit::IsSelected(){
|
|
return selected;
|
|
}
|
|
|
|
void Unit::Select(){
|
|
selected=true;
|
|
}
|
|
|
|
void Unit::Deselect(){
|
|
selected=false;
|
|
}
|
|
|
|
vf2d Unit::GetPos(){
|
|
return pos;
|
|
} |