|
|
|
|
#pragma region License
|
|
|
|
|
/*
|
|
|
|
|
License (OLC-3)
|
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
|
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
|
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
|
|
|
be used to endorse or promote products derived from this software without specific
|
|
|
|
|
prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
|
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
Portions of this software are copyright <EFBFBD> 2024 The FreeType
|
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
|
All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
#pragma endregion
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "AdventuresInLestoria.h"
|
|
|
|
|
#include "SoundEffect.h"
|
|
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
|
INCLUDE_GFX
|
|
|
|
|
INCLUDE_MONSTER_LIST
|
|
|
|
|
|
|
|
|
|
struct TrailEffect:Effect{
|
|
|
|
|
inline TrailEffect(vf2d startPos,float lifetime,const std::string&imgFile,int damage,float damageTickFrequency,bool upperLevel,float fadeout,vf2d scale,float imgXOffsetSpd,Oscillator<Pixel>col,EffectType type=EffectType::NONE,bool additiveBlending=false)
|
|
|
|
|
:endPos(startPos),imageXSpd(imgXOffsetSpd),damage(damage),col(col),damageTickFrequency(damageTickFrequency),Effect(startPos,lifetime,imgFile,upperLevel,0.f,fadeout,scale,{},type,WHITE,0.f,0.f,additiveBlending){}
|
|
|
|
|
inline void SetEndPos(const vf2d pos){
|
|
|
|
|
this->endPos=pos;
|
|
|
|
|
}
|
|
|
|
|
inline bool Update(float fElapsedTime){
|
|
|
|
|
col.Update(fElapsedTime);
|
|
|
|
|
imageXOffset+=imageXSpd*fElapsedTime;
|
|
|
|
|
rotation=util::angleTo(pos,endPos);
|
|
|
|
|
hitTimer-=fElapsedTime;
|
|
|
|
|
|
|
|
|
|
if(hitTimer<=0.f){
|
|
|
|
|
for(std::shared_ptr<Monster>&monster:MONSTER_LIST){
|
|
|
|
|
vf2d closestPointToFlameTrail{geom2d::closest(geom2d::line<float>{pos,endPos},monster->GetPos())};
|
|
|
|
|
float distToTrail{util::distance(monster->GetPos(),closestPointToFlameTrail)};
|
|
|
|
|
if(!monster->InUndamageableState(OnUpperLevel(),GetZ())&&distToTrail<=24*size.y){
|
|
|
|
|
monster->Hurt(damage,OnUpperLevel(),GetZ(),HurtFlag::DOT);
|
|
|
|
|
SoundEffect::PlaySFX("Burn",monster->GetPos());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hitTimer+=damageTickFrequency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Effect::Update(fElapsedTime);
|
|
|
|
|
}
|
|
|
|
|
inline void Draw(const Pixel blendCol)const{
|
|
|
|
|
geom2d::line<float>flameTrailLine{pos,endPos};
|
|
|
|
|
geom2d::line<float>flameTrailLineRectLine1{pos+vf2d{GetFrame().GetSourceImage()->Sprite()->height/2.f*size.y,rotation-PI/2}.cart(),endPos+vf2d{GetFrame().GetSourceImage()->Sprite()->height/2.f*size.y,rotation-PI/2}.cart()};
|
|
|
|
|
geom2d::line<float>flameTrailLineRectLine2{pos+vf2d{GetFrame().GetSourceImage()->Sprite()->height/2.f*size.y,rotation+PI/2}.cart(),endPos+vf2d{GetFrame().GetSourceImage()->Sprite()->height/2.f*size.y,rotation+PI/2}.cart()};
|
|
|
|
|
vf2d flameTrailSize{flameTrailLine.length(),float(GetFrame().GetSourceImage()->Sprite()->height)};
|
|
|
|
|
flameTrailSize*=size;
|
|
|
|
|
|
|
|
|
|
const auto PixelToUVSpace=[this](vf2d pixelPos){
|
|
|
|
|
pixelPos.x+=imageXOffset;
|
|
|
|
|
return pixelPos/GetFrame().GetSourceImage()->Sprite()->Size()/size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
game->view.DrawPolygonDecal(GetFrame().GetSourceImage()->Decal(),std::vector<vf2d>{
|
|
|
|
|
flameTrailLine.upoint(0.5f),flameTrailLineRectLine1.start,flameTrailLineRectLine1.upoint(0.5f),flameTrailLineRectLine1.end,
|
|
|
|
|
flameTrailLineRectLine2.end,flameTrailLineRectLine2.upoint(0.5f),flameTrailLineRectLine2.start,flameTrailLineRectLine1.start,
|
|
|
|
|
},std::vector<vf2d>{
|
|
|
|
|
PixelToUVSpace(flameTrailSize/2),PixelToUVSpace({}),PixelToUVSpace({flameTrailSize.x/2.f,0}),PixelToUVSpace({flameTrailSize.x,0.f}),
|
|
|
|
|
PixelToUVSpace(flameTrailSize),PixelToUVSpace({flameTrailSize.x/2.f,flameTrailSize.y}),PixelToUVSpace({0.f,flameTrailSize.y}),PixelToUVSpace({}),
|
|
|
|
|
},std::vector<Pixel>{
|
|
|
|
|
col.get(),{0,0,0,0},col.get(),{0,0,0,0},
|
|
|
|
|
{0,0,0,0},col.get(),{0,0,0,0},{0,0,0,0},
|
|
|
|
|
},blendCol);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
Oscillator<Pixel>col;
|
|
|
|
|
vf2d endPos{};
|
|
|
|
|
float imageXSpd;
|
|
|
|
|
float imageXOffset{};
|
|
|
|
|
int damage;
|
|
|
|
|
float damageTickFrequency;
|
|
|
|
|
float hitTimer{};
|
|
|
|
|
};
|