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.
104 lines
4.5 KiB
104 lines
4.5 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 "util.h"
|
|
#include "AdventuresInLestoria.h"
|
|
#include "BombBoom.h"
|
|
|
|
INCLUDE_DATA
|
|
INCLUDE_ANIMATION_DATA
|
|
INCLUDE_MONSTER_LIST
|
|
INCLUDE_game
|
|
|
|
Bomb::Bomb(const vf2d pos,const float z,const float gravity,const float detonationTime,const float bombFadeoutTime,const float bombKnockbackFactor,const vf2d targetPos,const float radius,const int damage,const bool upperLevel,const bool friendly,const Pixel col,const vf2d scale)
|
|
:Bullet(pos,{},radius,damage,"goblin_bomb.png",upperLevel,true,INFINITY,false,friendly,col,scale)
|
|
,gravity(gravity),detonationTime(detonationTime),bombFadeoutTime(bombFadeoutTime),bombKnockbackFactor(bombKnockbackFactor),targetPos(targetPos){
|
|
this->z=z;
|
|
deactivated=true;
|
|
bomb_animation.AddState("Fuse",ANIMATION_DATA.at("goblin_bomb_fuse.png"));
|
|
bomb_animation.ChangeState(animation,"Fuse");
|
|
}
|
|
void Bomb::Update(float fElapsedTime){
|
|
vel=geom2d::line<float>(pos,targetPos).vector();
|
|
detonationTime-=fElapsedTime;
|
|
bomb_animation.UpdateState(animation,fElapsedTime);
|
|
if(detonationTime>0.f){
|
|
zVel+=gravity*fElapsedTime;
|
|
z=std::max(0.f,z+zVel*fElapsedTime);
|
|
if(z==0.f)zVel*=-1.f;
|
|
}else
|
|
if(fadeOutTime==0.f){
|
|
z=0; //Force the bomb to be grounded.
|
|
fadeOutTime=bombFadeoutTime;
|
|
game->AddEffect(std::make_unique<BombBoom>(pos,0.f,OnUpperLevel(),vf2d{radius,radius}/12.f/1.5f/*Upscale 24x24 to 36x36*/,1.f,vf2d{},WHITE,0.f,0.f,true));
|
|
float distToPlayer=geom2d::line<float>(pos,game->GetPlayer()->GetPos()).length();
|
|
if(friendly){
|
|
const MonsterHurtList hurtEnemies=game->HurtEnemies(pos,radius,damage,OnUpperLevel(),z);
|
|
for(auto&[monsterPtr,wasHit]:hurtEnemies){
|
|
if(wasHit)monsterPtr->ProximityKnockback(pos,bombKnockbackFactor);
|
|
}
|
|
if(distToPlayer<=radius){
|
|
game->GetPlayer()->ProximityKnockback(pos,bombKnockbackFactor);
|
|
}
|
|
}else{
|
|
if(distToPlayer<=radius){
|
|
if(game->GetPlayer()->Hurt(damage,OnUpperLevel(),z)){
|
|
game->GetPlayer()->ProximityKnockback(pos,bombKnockbackFactor);
|
|
}
|
|
}
|
|
for(auto&monsterPtr:MONSTER_LIST){
|
|
float distToMonster=geom2d::line<float>(pos,monsterPtr->GetPos()).length();
|
|
if(distToMonster<=radius){
|
|
monsterPtr->ProximityKnockback(pos,bombKnockbackFactor);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
bool Bomb::PlayerHit(Player*player){
|
|
return false;
|
|
}
|
|
bool Bomb::MonsterHit(Monster&monster){
|
|
return false;
|
|
}
|
|
|
|
void Bomb::Draw()const{
|
|
Bullet::Draw();
|
|
game->view.DrawPartialRotatedDecal(pos-vf2d{0,GetZ()},bomb_animation.GetFrame(animation).GetSourceImage()->Decal(),rotates?atan2(vel.y,vel.x)-PI/2:0,bomb_animation.GetFrame(animation).GetSourceRect().size/2,bomb_animation.GetFrame(animation).GetSourceRect().pos,bomb_animation.GetFrame(animation).GetSourceRect().size,scale,fadeOutTime==0?col:Pixel{col.r,col.g,col.b,uint8_t(util::lerp(col.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime)))});
|
|
} |