Prepare Trail of Fire graphics and structures. Update lerp util to be generalized and introduce generalized Oscillator class. Release Build 11271.

pull/65/head
sigonasr2 3 months ago
parent 5b7c25df46
commit 901f2e38bc
  1. 8
      Adventures in Lestoria/Adventures in Lestoria.vcxproj
  2. 6
      Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters
  3. 9
      Adventures in Lestoria/BlackHole.h
  4. 3
      Adventures in Lestoria/BulletTypes.h
  5. 2
      Adventures in Lestoria/DeadlyDash.cpp
  6. 13
      Adventures in Lestoria/Effect.h
  7. 2
      Adventures in Lestoria/EnergyBolt.cpp
  8. 14
      Adventures in Lestoria/FadeInOutEffect.cpp
  9. 2
      Adventures in Lestoria/Minimap.cpp
  10. 64
      Adventures in Lestoria/Oscillator.h
  11. 57
      Adventures in Lestoria/TrailEffect.h
  12. 2
      Adventures in Lestoria/Version.h
  13. 4
      Adventures in Lestoria/Wizard.cpp
  14. BIN
      Adventures in Lestoria/assets/FlamesTexture.png
  15. 1
      Adventures in Lestoria/assets/config/gfx/gfx.txt
  16. 4
      Adventures in Lestoria/util.cpp
  17. 24
      Adventures in Lestoria/util.h
  18. BIN
      x64/Release/Adventures in Lestoria.exe

@ -537,6 +537,10 @@
</ClInclude>
<ClInclude Include="MonsterData.h" />
<ClInclude Include="olcPGEX_SplashScreen.h" />
<ClInclude Include="Oscillator.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="Overlay.h">
<SubType>
</SubType>
@ -726,6 +730,10 @@
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="TrailEffect.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="Tutorial.h" />
<ClInclude Include="VisualNovel.h" />
<ClInclude Include="Test.h" />

@ -687,6 +687,12 @@
<ClInclude Include="BlackHole.h">
<Filter>Source Files\Effects</Filter>
</ClInclude>
<ClInclude Include="TrailEffect.h">
<Filter>Source Files\Effects</Filter>
</ClInclude>
<ClInclude Include="Oscillator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -38,17 +38,18 @@ All rights reserved.
#pragma once
#include "AdventuresInLestoria.h"
#include "util.h"
#include "Effect.h"
INCLUDE_MONSTER_LIST
struct BlackHole:FadeInOutEffect{
inline BlackHole(OscillatorVf2d pos,const std::string&img,float lifetime,float cycleSpd,bool onUpperLevel,OscillatorFloat size,vf2d spd,OscillatorPixel col,float rotation,float rotationSpd,bool additiveBlending=false,float particleSpawnFreq=0.f,const std::function<Effect(const Effect&self)>&particleGenerator={})
:FadeInOutEffect(pos,img,lifetime,cycleSpd,onUpperLevel,size,spd,col,rotation,rotationSpd,additiveBlending,particleSpawnFreq,particleGenerator){}
inline BlackHole(Oscillator<vf2d>pos,const std::string&img,float lifetime,bool onUpperLevel,Oscillator<vf2d>size,vf2d spd,Oscillator<Pixel>col,float rotation,float rotationSpd,bool additiveBlending=false,float particleSpawnFreq=0.f,const std::function<Effect(const Effect&self)>&particleGenerator={})
:FadeInOutEffect(pos,img,lifetime,onUpperLevel,size,spd,col,rotation,rotationSpd,additiveBlending,particleSpawnFreq,particleGenerator){}
inline bool Update(float fElapsedTime){
for(std::shared_ptr<Monster>&m:MONSTER_LIST){
float distToMonster{util::distance(pos,m->GetPos())};
if(distToMonster<="Black Hole"_ENC["PULL IN RADIUS"]/100.f*24){
if(!m->IsSolid()&&m->OnUpperLevel()==OnUpperLevel()&&m->GetZ()<1.f&&distToMonster<="Black Hole"_ENC["PULL IN RADIUS"]/100.f*24){
float pullInForce{util::map_range<float>(distToMonster,0,"Black Hole"_ENC["PULL IN RADIUS"]/100.f*24,"Black Hole"_ENC["PULL IN FORCE MAX"],"Black Hole"_ENC["PULL IN FORCE MIN"])};
m->AddAddedVelocity(util::pointTo(m->GetPos(),pos)*pullInForce);
}

@ -39,6 +39,7 @@ All rights reserved.
#include "Bullet.h"
#include "Direction.h"
#include "Effect.h"
#include "TrailEffect.h"
struct EnergyBolt:public Bullet{
float lastParticleSpawn=0;
@ -56,6 +57,8 @@ struct FireBolt:public Bullet{
BulletDestroyState PlayerHit(Player*player)override;//DO NOT CALL THIS DIRECTLY! INSTEAD USE _PlayerHit()!!
BulletDestroyState MonsterHit(Monster&monster,const uint8_t markStacksBeforeHit)override;//DO NOT CALL THIS DIRECTLY! INSTEAD USE _MonsterHit()!!
void ModifyOutgoingDamageData(HurtDamageInfo&data);
private:
std::optional<std::reference_wrapper<TrailEffect>>flameTrail;
};
struct LightningBolt:public Bullet{

@ -79,7 +79,7 @@ void DeadlyDash::Draw(const Pixel blendCol)const{
for(int i:std::ranges::iota_view(0,afterImageCount)){
const float fadeTimeBegins{(i+1)*afterImagesLingeringTime};
uint8_t alpha{255U};
if(GetAliveTime()>fadeTimeBegins)alpha=std::max(0.f,util::lerp(255,0,(GetAliveTime()-fadeTimeBegins)/afterImagesLingeringTime));
if(GetAliveTime()>fadeTimeBegins)alpha=std::max(0.f,float(util::lerp(255,0,(GetAliveTime()-fadeTimeBegins)/afterImagesLingeringTime)));
const Animate2D::FrameSequence&animation{ANIMATION_DATA[this->animation]};
const float animationFrameTimer{i*animation.m_fFrameDuration};

@ -40,12 +40,10 @@ All rights reserved.
#include "IBullet.h"
#include <unordered_set>
#include <variant>
#include "Oscillator.h"
class Monster;
class Player;
using HitList=std::unordered_set<std::variant<Monster*,Player*>>;
using OscillatorVf2d=std::pair<vf2d,vf2d>;
using OscillatorPixel=std::pair<Pixel,Pixel>;
using OscillatorFloat=std::pair<float,float>;
enum class EffectType{
NONE,
@ -175,15 +173,14 @@ struct FadeInOutEffect:Effect{
//cycleSpd is how long it takes to get from fully opaque to fully transparent, and back to fully opaque
FadeInOutEffect(vf2d pos,const std::string&img,float lifetime,float cycleSpd,bool onUpperLevel,float size,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending=false,float particleSpawnFreq=0.f,const std::function<Effect(const Effect&self)>&particleGenerator={});
//A version with oscillators for position and colors, for extra animation effects!
FadeInOutEffect(OscillatorVf2d pos,const std::string&img,float lifetime,float cycleSpd,bool onUpperLevel,OscillatorFloat size,vf2d spd,OscillatorPixel col,float rotation,float rotationSpd,bool additiveBlending=false,float particleSpawnFreq=0.f,const std::function<Effect(const Effect&self)>&particleGenerator={});
FadeInOutEffect(Oscillator<vf2d>pos,const std::string&img,float lifetime,bool onUpperLevel,Oscillator<vf2d>size,vf2d spd,Oscillator<Pixel>col,float rotation,float rotationSpd,bool additiveBlending=false,float particleSpawnFreq=0.f,const std::function<Effect(const Effect&self)>&particleGenerator={});
virtual bool Update(float fElapsedTime)override;
virtual void Draw()const override;
std::function<Effect(const Effect&self)>particleGenerator;
const float particleSpawnFreq;
const float cycleSpd;
const OscillatorVf2d posOscillator;
const OscillatorFloat sizeOscillator;
const OscillatorPixel colOscillator;
Oscillator<vf2d>posOscillator;
Oscillator<vf2d>sizeOscillator;
Oscillator<Pixel>colOscillator;
float particleSpawnTimer{};
const float originalParticleSpawnTimer{};
};

@ -69,7 +69,7 @@ BulletDestroyState EnergyBolt::MonsterHit(Monster&monster,const uint8_t markStac
{
if(!game->GetPlayer()->HasEnchant("Piercing Bolt"))fadeOutTime="Wizard.Auto Attack.BulletHitFadeoutTime"_F;
game->AddEffect(std::make_unique<Effect>(monster.GetPos(),0,"splash_effect.png",upperLevel,monster.GetSizeMult(),"Wizard.Auto Attack.SplashEffectFadeoutTime"_F));
if(hitList.size()==1)damage=ceil(float(damage)/2);
if(hitList.size()==1)damage=ceil(damage*"Piercing Bolt"_ENC["MULTI TARGET DAMAGE"]/100.f);
return BulletDestroyState::KEEP_ALIVE;
}

@ -44,9 +44,9 @@ All rights reserved.
INCLUDE_game
FadeInOutEffect::FadeInOutEffect(vf2d pos,const std::string&img,float lifetime,float cycleSpd,bool onUpperLevel,float size,vf2d spd,Pixel col,float rotation,float rotationSpd,bool additiveBlending,float particleSpawnFreq,const std::function<Effect(const Effect&self)>&particleGenerator)
:FadeInOutEffect({pos,pos},img,lifetime,cycleSpd,onUpperLevel,{size,size},spd,{col,{col.r,col.g,col.b,0}},rotation,rotationSpd,additiveBlending,particleSpawnFreq,particleGenerator){}
FadeInOutEffect::FadeInOutEffect(OscillatorVf2d pos,const std::string&img,float lifetime,float cycleSpd,bool onUpperLevel,OscillatorFloat size,vf2d spd,OscillatorPixel col,float rotation,float rotationSpd,bool additiveBlending,float particleSpawnFreq,const std::function<Effect(const Effect&self)>&particleGenerator)
:particleSpawnFreq(particleSpawnFreq),particleGenerator(particleGenerator),cycleSpd(cycleSpd),particleSpawnTimer(particleSpawnFreq),originalParticleSpawnTimer(particleSpawnTimer),posOscillator(pos),colOscillator(col),sizeOscillator(size),Effect(pos.first,lifetime,img,onUpperLevel,size.first,0.25f,spd,col.first,rotation,rotationSpd,additiveBlending){}
:FadeInOutEffect({pos,pos,cycleSpd},img,lifetime,onUpperLevel,{{size,size},{size,size},cycleSpd},spd,{col,{col.r,col.g,col.b,0},cycleSpd},rotation,rotationSpd,additiveBlending,particleSpawnFreq,particleGenerator){}
FadeInOutEffect::FadeInOutEffect(Oscillator<vf2d>pos,const std::string&img,float lifetime,bool onUpperLevel,Oscillator<vf2d>size,vf2d spd,Oscillator<Pixel>col,float rotation,float rotationSpd,bool additiveBlending,float particleSpawnFreq,const std::function<Effect(const Effect&self)>&particleGenerator)
:particleSpawnFreq(particleSpawnFreq),particleGenerator(particleGenerator),particleSpawnTimer(particleSpawnFreq),originalParticleSpawnTimer(particleSpawnTimer),posOscillator(pos),colOscillator(col),sizeOscillator(size),Effect(pos.first,lifetime,img,onUpperLevel,size.first,0.25f,spd,col.first,rotation,rotationSpd,additiveBlending){}
bool FadeInOutEffect::Update(float fElapsedTime){
if(particleGenerator){
particleSpawnTimer-=fElapsedTime;
@ -55,11 +55,9 @@ bool FadeInOutEffect::Update(float fElapsedTime){
game->AddEffect(std::make_unique<Effect>(particleGenerator(*this)));
}
}
float t{float(abs(sin(PI*game->GetRunTime()*cycleSpd)))};
pos=posOscillator.first.lerp(posOscillator.second,t);
size={util::lerp(sizeOscillator.first,sizeOscillator.second,t),util::lerp(sizeOscillator.first,sizeOscillator.second,t)};
col=PixelLerp(colOscillator.first,colOscillator.second,t);
col.a=util::lerp(colOscillator.first.a,colOscillator.second.a,t);
pos=posOscillator.Update(fElapsedTime);
size=sizeOscillator.Update(fElapsedTime);
col=colOscillator.Update(fElapsedTime);
return Effect::Update(fElapsedTime);
}
void FadeInOutEffect::Draw()const{

@ -218,7 +218,7 @@ void Minimap::UpdateChunk(const MapName map,const vi2d chunkPos,const InitialLoa
const vi2d chunkOffset={"Minimap.Chunk Size"_I/2,"Minimap.Chunk Size"_I/2};
const float distance=geom2d::line<float>(centerChunkPos+chunkOffset,vf2d{float(x),float(y)}).length();
const int alpha=std::clamp(util::lerp(255,0,(distance-"Minimap.Chunk Size"_I)/"Minimap.Chunk Size"_I),0.f,255.f);
const int alpha=std::clamp(float(util::lerp(255,0,(distance-"Minimap.Chunk Size"_I)/"Minimap.Chunk Size"_I)),0.f,255.f);
if(cover.Sprite()->GetPixel(x,y).a>alpha)continue; //The distance was uncovered by another closer chunk, don't need to reveal it here.

@ -0,0 +1,64 @@
#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 © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "util.h"
template<class T>
class Oscillator{
public:
Oscillator()
:Oscillator({},{},0.f){}
Oscillator(T val1,T val2,float cycleSpd)
:val1(val1),val2(val2),first(this->val1),second(this->val2),cycleSpd(cycleSpd),currentVal(val1){}
const T&Update(const float fElapsedTime){
currentVal=util::lerp(val1,val2,sin(PI*timer*cycleSpd)/2+0.5f);
timer+=fElapsedTime;
return get();
}
const T&get(){
return currentVal;
};
const T&first;
const T&second;
private:
T val1,val2;
T currentVal;
float cycleSpd;
double timer{};
};

@ -0,0 +1,57 @@
#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 © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "Effect.h"
class TrailEffect:Effect{
inline TrailEffect(vf2d startPos,float lifetime,const std::string&imgFile,bool upperLevel,float fadeout,vf2d scale,float imgXOffsetSpd,Oscillator<Pixel>col,EffectType type=EffectType::NONE,bool additiveBlending=false)
:Effect(pos,lifetime,imgFile,upperLevel,scale,fadeout,{},col.first,0.f,0.f,additiveBlending){}
inline void SetEndPos(const vf2d pos){
this->endPos=pos;
}
inline bool Update(float fElapsedTime){
col.Update(fElapsedTime);
}
inline void Draw()const{
}
private:
Oscillator<Pixel>col;
vf2d endPos{};
};

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 5
#define VERSION_BUILD 11250
#define VERSION_BUILD 11271
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -156,14 +156,14 @@ void Wizard::InitializeClassAbilities(){
if(game->TestingModeEnabled()||dist>0&&p->CanPathfindTo(p->GetPos(),teleportPoint,float("Wizard.Right Click Ability.TilesMax"_I))
&&(NoTileCollisionExistsHere()||NoPlayerCollisionWithTile())){
if(p->HasEnchant("Blink Portal")){
Effect&eff{game->AddEffect(std::make_unique<FadeInOutEffect>(OscillatorVf2d{p->GetPos(),p->GetPos()+vf2d{0,-6.f}},"portal.png","Blink Portal"_ENC["REACTIVATION TIME"],0.5f,p->OnUpperLevel(),OscillatorFloat{0.9f,1.1f},vf2d{},OscillatorPixel{WHITE,0x50196f},0.f,0.f),true)};
Effect&eff{game->AddEffect(std::make_unique<FadeInOutEffect>(Oscillator<vf2d>{p->GetPos(),p->GetPos()+vf2d{0,-6.f},0.5f},"portal.png","Blink Portal"_ENC["REACTIVATION TIME"],p->OnUpperLevel(),Oscillator<vf2d>{{0.9f,0.9f},{1.1f,1.1f},0.5f},vf2d{},Oscillator<Pixel>{WHITE,Pixel(0x50196f),0.5f},0.f,0.f),true)};
eff.SetType(EffectType::BLINK_PORTAL);
}
TeleportTo(teleportPoint);
p->lastPathfindingCooldown=0.1f;
if(p->HasEnchant("Black Hole")){
Effect&blackHoleEff{game->AddEffect(std::make_unique<BlackHole>(OscillatorVf2d{p->GetPos(),p->GetPos()+vf2d{0,-6.f}},"blackhole.png","Black Hole"_ENC["BLACK HOLE DURATION"],0.75f,p->OnUpperLevel(),OscillatorFloat{3.4f,3.7f},vf2d{},OscillatorPixel{WHITE,WHITE},util::random(2*PI),PI/3,false,0.03f,[](const Effect&self){
Effect&blackHoleEff{game->AddEffect(std::make_unique<BlackHole>(Oscillator<vf2d>{p->GetPos(),p->GetPos()+vf2d{0,-6.f},0.75f},"blackhole.png","Black Hole"_ENC["BLACK HOLE DURATION"],p->OnUpperLevel(),Oscillator<vf2d>{{3.4f,3.4f},{3.7f,3.7f},0.75f},vf2d{},Oscillator<Pixel>{WHITE,WHITE,0.75f},util::random(2*PI),PI/3,false,0.03f,[](const Effect&self){
vf2d particlePos{self.pos+vf2d{"Black Hole"_ENC["PULL IN RADIUS"]/100.f*24,util::random(2*PI)}.cart()};
return Effect{particlePos,util::random_range(0.3f,0.5f),"pixel.png",self.OnUpperLevel(),util::random(2.f),0.1f,util::pointTo(particlePos,self.pos)*util::random_range(700,1000),PixelLerp(BLACK,Pixel(0x9859de),util::random(1.f)),0.f,0.f,false};
}),true)};

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

@ -127,6 +127,7 @@ Images
GFX_SpecialTargetMark = special_target.png
GFX_BlackHole = blackhole.png
GFX_Portal = portal.png
GFX_Flames = FlamesTexture.png
GFX_Thief_Sheet = nico-thief.png
GFX_Trapper_Sheet = nico-trapper.png

@ -72,10 +72,6 @@ float util::radToDeg(float rad){
return rad*57.2957795130823208767f;
}
float util::lerp(float n1,float n2,double t){
return float(n1*(1-t)+n2*t);
}
std::string util::timerStr(float time){
int seconds=int(time);
int hours=seconds/3600;

@ -54,7 +54,27 @@ namespace olc::util{
float angleTo(vf2d posFrom,vf2d posTo);
float degToRad(float deg);
float radToDeg(float rad);
float lerp(float n1,float n2,double t);
#pragma region Lerp templates + specializations
template<class T,class U>
inline auto lerp(const T val1,const U val2,const float t){
return decltype(val1+val2)(val1*(1-t)+val2*t);
}
template<>
inline auto lerp<vf2d,vf2d>(const vf2d val1,const vf2d val2,const float t){
return val1.lerp(val2,t);
}
template<>
//NOTE: Also interpolates the alpha!!!
inline auto lerp<Pixel,Pixel>(const Pixel val1,const Pixel val2,const float t){
Pixel col{PixelLerp(val1,val2,t)};
col.a=lerp(val1.a,val2.a,t);
return col;
}
#pragma endregion
std::string timerStr(float time);
std::string WrapText(PixelGameEngine*pge,std::string str,int width,bool proportional,vd2d scale);
std::u32string WrapText(PixelGameEngine*pge,std::u32string str,int width,Font&font,vd2d scale);
@ -95,4 +115,4 @@ constexpr auto circ_add(
}
//Converts unit distances to pixels. (Every 100 units = 24 pixels)
long double operator""_Pixels(long double unitDist);
long double operator""_Pixels(long double unitDist);
Loading…
Cancel
Save