The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
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.
95 lines
4.2 KiB
95 lines
4.2 KiB
#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
|
|
|
|
#include "BulletTypes.h"
|
|
#include "AdventuresInLestoria.h"
|
|
#include <ranges>
|
|
#include "util.h"
|
|
#include "SoundEffect.h"
|
|
|
|
INCLUDE_game
|
|
|
|
ThrownProjectile::ThrownProjectile(vf2d pos,vf2d targetPos,const std::string&img,float explodeRadius,float z,float totalFallTime,float totalRiseZAmt,int damage,bool upperLevel,bool hitsMultiple,float lifetime,bool friendly,Pixel col,vf2d scale,float image_angle,const std::optional<Effect>explodeEffect,const std::optional<std::string>explodeSoundEffect,const std::optional<LingeringEffect>lingeringEffect)
|
|
:Bullet(pos,util::pointTo(pos,targetPos)*util::distance(pos,targetPos)/totalFallTime,0.f,damage,img,upperLevel,hitsMultiple,lifetime,false,friendly,col,scale,image_angle),initialZ(z),explodeRadius(explodeRadius),totalRiseZAmt(totalRiseZAmt),totalFallTime(totalFallTime),startingPos(pos),targetPos(targetPos),originalRisingTime(totalFallTime*0.25f),risingTime(originalRisingTime),originalFallingTime(totalFallTime*0.75f),fallingTime(originalFallingTime),explodeEffect(explodeEffect),img(img),explodeSoundEffect(explodeSoundEffect),lingeringEffect(lingeringEffect){
|
|
this->z=z;
|
|
}
|
|
|
|
void ThrownProjectile::OnGroundLand(){
|
|
const HurtList hurtList{game->Hurt(pos,explodeRadius,damage,OnUpperLevel(),z,HurtType::MONSTER,HurtFlag::PLAYER_ABILITY)};
|
|
if(explodeEffect){
|
|
Effect&explosionEffect{game->AddEffect(std::make_unique<Effect>(explodeEffect.value()))};
|
|
explosionEffect.pos+=pos;
|
|
}
|
|
if(explodeSoundEffect)SoundEffect::PlaySFX(explodeSoundEffect.value(),pos);
|
|
if(lingeringEffect){
|
|
LingeringEffect&lingerEffect{dynamic_cast<LingeringEffect&>(game->AddEffect(std::make_unique<LingeringEffect>(lingeringEffect.value())))};
|
|
lingerEffect.posOscillator.val1+=pos;
|
|
lingerEffect.posOscillator.val2+=pos;
|
|
lingerEffect.pos+=pos;
|
|
}
|
|
|
|
vel={};
|
|
fadeOutTime=0.25f;
|
|
Deactivate();
|
|
}
|
|
void ThrownProjectile::_OnGroundLand(){
|
|
z=0.f;
|
|
OnGroundLand();
|
|
}
|
|
|
|
void ThrownProjectile::Update(float fElapsedTime){
|
|
if(IsDeactivated())return;
|
|
image_angle+=0.5*PI*fElapsedTime;
|
|
|
|
const bool Landed{fallingTime<=0.f};
|
|
if(Landed){
|
|
_OnGroundLand();
|
|
}else{
|
|
if(risingTime>0.f){
|
|
risingTime-=fElapsedTime;
|
|
z=util::lerp(initialZ,initialZ+totalRiseZAmt,1-(risingTime/originalRisingTime));
|
|
}else{
|
|
fallingTime-=fElapsedTime;
|
|
z=util::lerp(initialZ+totalRiseZAmt,0.f,1-(fallingTime/originalFallingTime));
|
|
}
|
|
}
|
|
}
|
|
|
|
void ThrownProjectile::ModifyOutgoingDamageData(HurtDamageInfo&data){
|
|
if(friendly)data.hurtFlags|=HurtFlag::PLAYER_ABILITY;
|
|
} |