49 lines
1.9 KiB
C++
Raw Normal View History

2023-06-15 00:11:39 -05:00
#include "DEFINES.h"
#include "Effect.h"
#include "Crawler.h"
#include "safemap.h"
2023-06-15 00:11:39 -05:00
INCLUDE_ANIMATION_DATA
INCLUDE_game
Effect::Effect(vf2d pos,float lifetime,std::string animation,bool upperLevel,float size,float fadeout,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending)
:Effect::Effect(pos,lifetime,animation,upperLevel,vf2d{size,size},fadeout,spd,col,rotation,rotationSpd,additiveBlending){
this->animation.AddState(animation,ANIMATION_DATA[animation]);
}
Effect::Effect(vf2d pos,float lifetime,std::string animation,bool upperLevel,vf2d size,float fadeout,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending)
:pos(pos),lifetime(lifetime),upperLevel(upperLevel),size(size),fadeout(fadeout),original_fadeoutTime(fadeout),spd(spd),col(col),rotation(rotation),rotationSpd(rotationSpd),additiveBlending(additiveBlending){
2023-06-15 00:11:39 -05:00
this->animation.AddState(animation,ANIMATION_DATA[animation]);
}
bool Effect::Update(float fElapsedTime){
lifetime-=fElapsedTime;
if(lifetime<=0){
fadeout-=fElapsedTime;
if(fadeout<=0){
return false;
}
}
rotation+=rotationSpd*fElapsedTime;
2023-06-24 02:14:11 -07:00
pos+=spd*fElapsedTime;
2023-06-15 00:11:39 -05:00
animation.UpdateState(internal_animState,fElapsedTime);
return true;
2023-06-15 00:11:39 -05:00
}
void Effect::Draw(){
if(additiveBlending)game->SetDecalMode(DecalMode::ADDITIVE);
2023-06-15 00:11:39 -05:00
if(fadeout==0){
game->view.DrawPartialRotatedDecal(pos,GetFrame().GetSourceImage()->Decal(),rotation,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,size,col);
2023-06-15 00:11:39 -05:00
} else {
game->view.DrawPartialRotatedDecal(pos,GetFrame().GetSourceImage()->Decal(),rotation,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,size,{col.r,col.g,col.b,uint8_t(fadeout/original_fadeoutTime*255)});
2023-06-15 00:11:39 -05:00
}
game->SetDecalMode(DecalMode::NORMAL);
2023-06-15 00:11:39 -05:00
}
Animate2D::Frame Effect::GetFrame(){
return animation.GetFrame(internal_animState);
2023-07-07 06:42:49 -05:00
}
bool Effect::OnUpperLevel(){
return upperLevel;
2023-06-15 00:11:39 -05:00
}