Fix up warnings (mostly loss of data cast warnings). When an ability gets interrupted, the key is required to be depressed before another cast attempt can be made. Added collision layer tiles to a few tiles in 1-1 due to ability to walk out-of-bounds.

This commit is contained in:
2023-11-27 02:38:12 -06:00
parent cfd5586d63
commit e4fae723c9
51 changed files with 229 additions and 220 deletions
+25 -23
View File
@@ -81,13 +81,13 @@ void Player::Initialize(){
bool Player::SetX(float x){
vf2d newPos={x,pos.y};
vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth;
vi2d tilePos=vi2d(newPos/float(game->GetCurrentMap().tilewidth))*game->GetCurrentMap().tilewidth;
geom2d::rect<int>collisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel);
#pragma region lambdas
auto NoTileCollisionExistsHere=[&](){return collisionRect.pos==game->NO_COLLISION.pos&&collisionRect.size==game->NO_COLLISION.size;};
#pragma endregion
if(NoTileCollisionExistsHere()){
pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult()));
pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2.f*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2.f*GetSizeMult()));
Moved();
return true;
} else {
@@ -97,7 +97,7 @@ bool Player::SetX(float x){
#pragma endregion
collision.pos+=tilePos;
if(NoPlayerCollisionWithTile()){
pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult()));
pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2.f*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2.f*GetSizeMult()));
Moved();
return true;
}
@@ -107,13 +107,13 @@ bool Player::SetX(float x){
bool Player::SetY(float y){
vf2d newPos={pos.x,y};
vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth;
vi2d tilePos=vi2d(newPos/float(game->GetCurrentMap().tilewidth))*game->GetCurrentMap().tilewidth;
geom2d::rect<int>collisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel);
#pragma region lambdas
auto NoTileCollisionExistsHere=[&](){return collisionRect.pos==game->NO_COLLISION.pos&&collisionRect.size==game->NO_COLLISION.size;};
#pragma endregion
if(NoTileCollisionExistsHere()){
pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult()));
pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2.f*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2.f*GetSizeMult()));
Moved();
return true;
} else {
@@ -123,7 +123,7 @@ bool Player::SetY(float y){
#pragma endregion
collision.pos+=tilePos;
if(NoPlayerCollisionWithTile()){
pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult()));
pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2.f*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2.f*GetSizeMult()));
Moved();
return true;
}
@@ -141,7 +141,7 @@ bool Player::SetPos(vf2d pos){
if(resultY&&!resultX){
resultX=SetX(pos.x);
}
return resultX|resultY;
return resultX||resultY;
}
vf2d&Player::GetPos(){
@@ -177,7 +177,7 @@ int Player::GetMaxMana() {
}
int Player::GetAttack(){
float mod_atk=atk;
float mod_atk=float(atk);
for(Buff&b:GetBuffs(BuffType::ATTACK_UP)){
mod_atk+=atk*b.intensity;
}
@@ -247,7 +247,7 @@ void Player::Update(float fElapsedTime){
}
}
while(manaTickTimer<=0){
manaTickTimer+=0.2;
manaTickTimer+=0.2f;
RestoreMana(1,true);
}
for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){
@@ -265,14 +265,14 @@ void Player::Update(float fElapsedTime){
switch(facingDirection){
case UP:{
if(lastAnimationFlip==0){
lastAnimationFlip=0.03;
lastAnimationFlip=0.03f;
facingDirection=DOWN;
animation.ChangeState(internal_animState,"WARRIOR_WALK_S");
}
}break;
case DOWN:{
if(lastAnimationFlip==0){
lastAnimationFlip=0.03;
lastAnimationFlip=0.03f;
facingDirection=UP;
animation.ChangeState(internal_animState,"WARRIOR_WALK_N");
}
@@ -291,7 +291,7 @@ void Player::Update(float fElapsedTime){
spin_angle=0;
z=0;
float numb=4;
game->HurtEnemies(pos,"Warrior.Ability 2.Range"_F/100*12,GetAttack()*"Warrior.Ability 2.DamageMult"_F,OnUpperLevel(),0);
game->HurtEnemies(pos,"Warrior.Ability 2.Range"_F/100*12,int(GetAttack()*"Warrior.Ability 2.DamageMult"_F),OnUpperLevel(),0);
game->AddEffect(std::make_unique<Effect>(GetPos(),"Warrior.Ability 2.EffectLifetime"_F,"ground-slam-attack-front.png",upperLevel,"Warrior.Ability 2.Range"_F/300*1.33f,"Warrior.Ability 2.EffectFadetime"_F),std::make_unique<Effect>(GetPos(),"Warrior.Ability 2.EffectLifetime"_F,"ground-slam-attack-back.png",upperLevel,"Warrior.Ability 2.Range"_F/300*1.33f,"Warrior.Ability 2.EffectFadetime"_F));
}
if(lastAnimationFlip>0){
@@ -379,7 +379,7 @@ void Player::Update(float fElapsedTime){
if(dist<=0.001){
m.SetPos(m.GetPos()+vf2d{util::random(2)-1,util::random(2)-1});
}else{
m.SetPos(line.rpoint(dist*1.1));
m.SetPos(line.rpoint(dist*1.1f));
}
if(m.IsAlive()){
vel=line.vector().norm()*-128;
@@ -430,9 +430,10 @@ void Player::Update(float fElapsedTime){
}
} else
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.Pressed()){
notEnoughManaDisplay={ability.name,1};
notEnoughManaDisplay={ability.name,1.f};
}
}
}else
if(key.Released()||!key.Held())ability.waitForRelease=false;
}
};
CheckAndPerformAbility(rightClickAbility,Player::KEY_DEFENSIVE);
@@ -531,10 +532,10 @@ void Player::Update(float fElapsedTime){
if(remainingRapidFireShots>0){
remainingRapidFireShots--;
geom2d::line pointTowardsCursor(GetPos(),game->GetWorldMousePos());
vf2d extendedLine=pointTowardsCursor.upoint(1.1);
vf2d extendedLine=pointTowardsCursor.upoint(1.1f);
float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x);
attack_cooldown_timer=ARROW_ATTACK_COOLDOWN;
BULLET_LIST.push_back(std::make_unique<Arrow>(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F-PI/8*"Ranger.Ability 1.ArrowSpd"_F)}+movementVelocity,12*"Ranger.Ability 1.ArrowRadius"_F/100,GetAttack()*"Ranger.Ability 1.DamageMult"_F,OnUpperLevel(),true)));
BULLET_LIST.push_back(std::make_unique<Arrow>(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F-PI/8*"Ranger.Ability 1.ArrowSpd"_F)}+movementVelocity,12*"Ranger.Ability 1.ArrowRadius"_F/100,int(GetAttack()*"Ranger.Ability 1.DamageMult"_F),OnUpperLevel(),true)));
SetAnimationBasedOnTargetingDirection(angleToCursor);
rapidFireTimer=RAPID_FIRE_SHOOT_DELAY;
}else{
@@ -574,7 +575,7 @@ bool Player::CanAct(){
}
bool Player::CanAct(Ability&ability){
return (ability.canCancelCast||state!=State::CASTING)&&state!=State::ANIMATION_LOCK&&GameState::STATE==GameState::states[States::GAME_RUN];
return !ability.waitForRelease&&(ability.canCancelCast||state!=State::CASTING)&&state!=State::ANIMATION_LOCK&&GameState::STATE==GameState::states[States::GAME_RUN];
}
bool Player::HasIframes(){
@@ -583,8 +584,8 @@ bool Player::HasIframes(){
bool Player::Hurt(int damage,bool onUpperLevel,float z){
if(hp<=0||HasIframes()||OnUpperLevel()!=onUpperLevel||abs(GetZ()-z)>1) return false;
if(GetState()==State::BLOCK)damage*=1-"Warrior.Right Click Ability.DamageReduction"_F;
float mod_dmg=damage;
if(GetState()==State::BLOCK)damage*=int(1-"Warrior.Right Click Ability.DamageReduction"_F);
float mod_dmg=float(damage);
lastCombatTime=0;
for(Buff&b:GetBuffs(BuffType::DAMAGE_REDUCTION)){
mod_dmg-=damage*b.intensity;
@@ -592,12 +593,12 @@ bool Player::Hurt(int damage,bool onUpperLevel,float z){
hp=std::max(0,hp-int(mod_dmg));
if(lastHitTimer>0){
damageNumberPtr.get()->damage+=int(mod_dmg);
damageNumberPtr.get()->pauseTime=0.4;
damageNumberPtr.get()->pauseTime=0.4f;
} else {
damageNumberPtr=std::make_shared<DamageNumber>(pos,int(mod_dmg),true);
DAMAGENUMBER_LIST.push_back(damageNumberPtr);
}
lastHitTimer=0.05;
lastHitTimer=0.05f;
return true;
}
@@ -634,6 +635,7 @@ Key Player::GetFacingDirection(){
void Player::Moved(){
if(state==State::CASTING){
state=State::NORMAL;
castPrepAbility->waitForRelease=true;
castInfo={"",0};
DAMAGENUMBER_LIST.push_back(std::make_shared<DamageNumber>(GetPos(),0,true,INTERRUPT));
}
@@ -718,7 +720,7 @@ void Player::RemoveAllBuffs(){
void Player::CastSpell(Ability&ability){
vf2d castPosition=game->GetWorldMousePos();
float distance=sqrt(pow(GetX()-game->GetWorldMousePos().x,2)+pow(GetY()-game->GetWorldMousePos().y,2));
float distance=float(sqrt(pow(GetX()-game->GetWorldMousePos().x,2)+pow(GetY()-game->GetWorldMousePos().y,2)));
if(distance>ability.precastInfo.range){//Clamp the distance.
vf2d pointToCursor = {game->GetWorldMousePos().x-GetX(),game->GetWorldMousePos().y-GetY()};
pointToCursor=pointToCursor.norm()*ability.precastInfo.range;