diff --git a/Crawler/Bullet.cpp b/Crawler/Bullet.cpp index 609d3e10..9f526c69 100644 --- a/Crawler/Bullet.cpp +++ b/Crawler/Bullet.cpp @@ -36,8 +36,8 @@ void Bullet::Draw(){ if(animated){ game->view.DrawPartialRotatedDecal(pos,GetFrame().GetSourceImage()->Decal(),rotates?atan2(vel.y,vel.x)-PI/2:0,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,scale,fadeOutTime==0?col:Pixel{col.r,col.g,col.b,lerp(col.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime))}); } else { - game->view.DrawDecal(pos,game->GFX_BulletCircle.Decal(),{radius,radius},fadeOutTime==0?col:Pixel{col.r,col.g,col.b,lerp(col.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime))}); - game->view.DrawDecal(pos,game->GFX_BulletCircleOutline.Decal(),{radius,radius},fadeOutTime==0?WHITE:Pixel{WHITE.r,WHITE.g,WHITE.b,lerp(WHITE.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime))}); + game->view.DrawDecal(pos-game->GFX_BulletCircle.Sprite()->Size()*scale/2,game->GFX_BulletCircle.Decal(),scale,fadeOutTime==0?col:Pixel{col.r,col.g,col.b,lerp(col.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime))}); + game->view.DrawDecal(pos-game->GFX_BulletCircle.Sprite()->Size()*scale/2,game->GFX_BulletCircleOutline.Decal(),scale,fadeOutTime==0?WHITE:Pixel{WHITE.r,WHITE.g,WHITE.b,lerp(WHITE.a,0,1-((fadeOutTime-fadeOutTimer)/fadeOutTime))}); } } diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index a650a571..a7e88175 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -430,14 +430,19 @@ void Crawler::UpdateBullets(float fElapsedTime){ b->Update(fElapsedTime); b->animation.UpdateState(b->internal_animState,fElapsedTime); if(!b->deactivated){ + float totalDistance=(b->vel*fElapsedTime).mag(); vf2d moveStep=b->vel*fElapsedTime; - int stepCount=1; if((b->vel*fElapsedTime).mag()>1){ moveStep=(b->vel*fElapsedTime).norm(); - stepCount=b->vel.x*fElapsedTime/moveStep.x; } - for(;stepCount>0;stepCount--){ - b->pos+=moveStep; + while(totalDistance>0){ + if(totalDistance>=1){ + b->pos+=moveStep; + totalDistance--; + } else { + b->pos+=moveStep*totalDistance; + totalDistance=0; + } if(b->friendly){ for(Monster&m:MONSTER_LIST){ if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b->pos,b->radius))){ diff --git a/Crawler/MonsterStrategyHelpers.h b/Crawler/MonsterStrategyHelpers.h index e5d85cc9..4e449dd7 100644 --- a/Crawler/MonsterStrategyHelpers.h +++ b/Crawler/MonsterStrategyHelpers.h @@ -1,7 +1,7 @@ #pragma once -#define GetInt(param) _GetInt(m,param,strategyNumber) -#define GetFloat(param) _GetFloat(m,param,strategyNumber) -#define GetString(param) _GetString(m,param,strategyNumber) -#define GetIntArr(param,ind) _GetInt(m,param,strategyNumber,ind) -#define GetFloatArr(param,ind) _GetFloat(m,param,strategyNumber,ind) -#define GetStringArr(param,ind) _GetString(m,param,strategyNumber,ind) \ No newline at end of file +#define ConfigInt(param) _GetInt(m,param,strategyNumber) +#define ConfigFloat(param) _GetFloat(m,param,strategyNumber) +#define ConfigString(param) _GetString(m,param,strategyNumber) +#define ConfigIntArr(param,ind) _GetInt(m,param,strategyNumber,ind) +#define ConfigFloatArr(param,ind) _GetFloat(m,param,strategyNumber,ind) +#define ConfigStringArr(param,ind) _GetString(m,param,strategyNumber,ind) \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index a69b0b0f..40fb62e3 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -169,7 +169,6 @@ void Player::Knockback(vf2d vel){ } void Player::Update(float fElapsedTime){ - Ability&rightClickAbility=GetRightClickAbility(), &ability=GetAbility1(), &ability2=GetAbility2(), diff --git a/Crawler/RunTowards.cpp b/Crawler/RunTowards.cpp index b4aa3ef8..4661f535 100644 --- a/Crawler/RunTowards.cpp +++ b/Crawler/RunTowards.cpp @@ -9,12 +9,12 @@ INCLUDE_MONSTER_DATA void Monster::STRATEGY::RUN_TOWARDS(Monster&m,float fElapsedTime,int strategyNumber){ m.targetAcquireTimer=std::max(0.f,m.targetAcquireTimer-fElapsedTime); if(m.targetAcquireTimer==0){ - m.targetAcquireTimer=GetFloat("WaitTime"); + m.targetAcquireTimer=ConfigFloat("WaitTime"); auto desiredTargetLine = geom2d::line(m.pos,game->GetPlayer()->GetPos()); - if(desiredTargetLine.length()>=GetInt("MaxDistance")/100.f*24){ + if(desiredTargetLine.length()>=ConfigInt("MaxDistance")/100.f*24){ //Trim to max distance desired. - m.target=desiredTargetLine.rpoint(GetInt("MaxDistance")/100.f*24); + m.target=desiredTargetLine.rpoint(ConfigInt("MaxDistance")/100.f*24); } else { m.target=desiredTargetLine.upoint(1.2); } diff --git a/Crawler/ShootAfar.cpp b/Crawler/ShootAfar.cpp index fb5250e0..972eecfb 100644 --- a/Crawler/ShootAfar.cpp +++ b/Crawler/ShootAfar.cpp @@ -14,14 +14,14 @@ void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime,int strategyNumb if(m.queueShotTimer<0){ m.queueShotTimer=0; { - BULLET_LIST.push_back(std::make_unique(Bullet(m.pos + vf2d{ 0,-4 }, geom2d::line(m.pos + vf2d{ 0,-4 }, game->GetPlayer()->GetPos()).vector().norm() * 24 * GetInt("BulletSpeed")/100.f, 24.f*GetInt("BulletSize")/100.f, m.GetAttack(),m.upperLevel,false, { uint8_t(GetIntArr("BulletColor",0)),uint8_t(GetIntArr("BulletColor",1)),uint8_t(GetIntArr("BulletColor",2)),uint8_t(GetIntArr("BulletColor",3) )}))); + BULLET_LIST.push_back(std::make_unique(Bullet(m.pos + vf2d{ 0,-4 }, geom2d::line(m.pos + vf2d{ 0,-4 }, game->GetPlayer()->GetPos()).vector().norm() * 24 * ConfigInt("BulletSpeed")/100.f, 12.f*ConfigInt("BulletSize")/100.f, m.GetAttack(),m.upperLevel,false, { uint8_t(ConfigIntArr("BulletColor",0)),uint8_t(ConfigIntArr("BulletColor",1)),uint8_t(ConfigIntArr("BulletColor",2)),uint8_t(ConfigIntArr("BulletColor",3) )},{ConfigInt("BulletSize")/100.f*8,ConfigInt("BulletSize")/100.f*8}))); } } } geom2d::line line(m.pos,game->GetPlayer()->GetPos()); if(m.targetAcquireTimer==0&&m.queueShotTimer==0){ m.targetAcquireTimer=1; - if(line.length()<24.f*GetInt("Range")/100.f){ + if(line.length()<24.f*ConfigInt("Range")/100.f){ m.target=line.upoint(-1.2); if(m.canMove){ m.SetState(MOVE_AWAY); @@ -29,7 +29,7 @@ void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime,int strategyNumb m.SetState(NORMAL); } } else - if(line.length()>24.f*GetInt("CloseInRange")/100.0f){ + if(line.length()>24.f*ConfigInt("CloseInRange")/100.0f){ m.target=line.upoint(1.2); m.SetState(MOVE_TOWARDS); } else { @@ -51,7 +51,7 @@ void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime,int strategyNumb if(!pathfindingDecision){ m.StartPathfinding(2.5); }else - if(line.length()<=24.f*GetInt("CloseInRange")/100.0f){ + if(line.length()<=24.f*ConfigInt("CloseInRange")/100.0f){ m.SetState(NORMAL); } if(moveTowardsLine.vector().x>0){ @@ -72,7 +72,7 @@ void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime,int strategyNumb if(!pathfindingDecision){ m.StartPathfinding(2.5); }else - if(line.length()>=24.f*GetInt("Range")/100.f){ + if(line.length()>=24.f*ConfigInt("Range")/100.f){ m.SetState(NORMAL); } if(moveTowardsLine.vector().x>0){ @@ -87,7 +87,7 @@ void Monster::STRATEGY::SHOOT_AFAR(Monster&m,float fElapsedTime,int strategyNumb }break; default:{ if(m.attackCooldownTimer==0){ - m.attackCooldownTimer=GetFloat("ShootingSpeed"); + m.attackCooldownTimer=ConfigFloat("ShootingSpeed"); m.queueShotTimer=std::min(m.attackCooldownTimer-0.001,0.7); m.PerformShootAnimation(); } diff --git a/Crawler/Turret.cpp b/Crawler/Turret.cpp index ff180bee..e7966742 100644 --- a/Crawler/Turret.cpp +++ b/Crawler/Turret.cpp @@ -1,6 +1,29 @@ #include "Monster.h" #include "MonsterStrategyHelpers.h" +#include "DEFINES.h" +#include "Crawler.h" +#include "utils.h" + +INCLUDE_game +INCLUDE_BULLET_LIST void Monster::STRATEGY::TURRET(Monster&m,float fElapsedTime,int strategyNumber){ - + m.attackCooldownTimer=std::max(0.f,m.attackCooldownTimer-fElapsedTime); + + if(m.queueShotTimer>0){ + m.queueShotTimer-=fElapsedTime; + if(m.queueShotTimer<0){ + m.queueShotTimer=0; + BULLET_LIST.push_back(std::make_unique(Bullet(m.pos + vf2d{ 0,-4 }, geom2d::line(m.pos + vf2d{ 0,-4 }, game->GetPlayer()->GetPos()).vector().norm() * 24 * ConfigInt("BulletSpeed")/100.f, 12.f*ConfigInt("BulletSize")/100.f, m.GetAttack(),m.upperLevel,false, { uint8_t(ConfigIntArr("BulletColor",0)),uint8_t(ConfigIntArr("BulletColor",1)),uint8_t(ConfigIntArr("BulletColor",2)),uint8_t(ConfigIntArr("BulletColor",3) )},{ConfigInt("BulletSize")/100.f*8,ConfigInt("BulletSize")/100.f*8}))); + } + } + + auto dist=geom2d::line(m.GetPos(),game->GetPlayer()->GetPos()).length(); + if(dist