Added arrow simulation for bow goblins. Added perception levels which increase the accuracy of the shooting monster over time. Refactor bullet update code to be inside the bullet class itself. Release Build 9169.
This commit is contained in:
@@ -43,6 +43,8 @@ All rights reserved.
|
||||
INCLUDE_ANIMATION_DATA
|
||||
INCLUDE_game
|
||||
INCLUDE_GFX
|
||||
INCLUDE_MONSTER_LIST
|
||||
INCLUDE_WINDOW_SIZE
|
||||
|
||||
Bullet::Bullet(vf2d pos,vf2d vel,float radius,int damage,bool upperLevel,bool friendly,Pixel col,vf2d scale)
|
||||
:pos(pos),vel(vel),radius(radius),damage(damage),col(col),friendly(friendly),upperLevel(upperLevel),scale(scale){};
|
||||
@@ -68,6 +70,76 @@ void Bullet::UpdateFadeTime(float fElapsedTime)
|
||||
|
||||
void Bullet::Update(float fElapsedTime){}
|
||||
|
||||
void Bullet::SimulateUpdate(const float fElapsedTime){
|
||||
simulated=true;
|
||||
_Update(fElapsedTime);
|
||||
simulated=false;
|
||||
}
|
||||
|
||||
void Bullet::_Update(const float fElapsedTime){
|
||||
UpdateFadeTime(fElapsedTime);
|
||||
Update(fElapsedTime);
|
||||
animation.UpdateState(internal_animState,fElapsedTime);
|
||||
if(!deactivated){
|
||||
float totalDistance=(vel*fElapsedTime).mag();
|
||||
int iterations=int(std::max(1.f,(vel*fElapsedTime).mag()));
|
||||
int totalIterations=iterations;
|
||||
vf2d finalBulletPos=pos+vel*fElapsedTime;
|
||||
distanceTraveled+=totalDistance/24.f*100.f;
|
||||
const auto CollisionCheck=[&](){
|
||||
if(simulated)return true;
|
||||
if(friendly){
|
||||
for(std::unique_ptr<Monster>&m:MONSTER_LIST){
|
||||
if(geom2d::overlaps(m->Hitbox(),geom2d::circle(pos,radius))){
|
||||
if(hitList.find(&*m)==hitList.end()&&m->Hurt(damage,OnUpperLevel(),0)){
|
||||
if(!hitsMultiple){
|
||||
if(MonsterHit(*m)){
|
||||
dead=true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
hitList.insert(&*m);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(geom2d::overlaps(game->GetPlayer()->Hitbox(),geom2d::circle(pos,radius))){
|
||||
if(game->GetPlayer()->Hurt(damage,OnUpperLevel(),0)){
|
||||
if(PlayerHit(&*game->GetPlayer())){
|
||||
dead=true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
while(iterations>0){
|
||||
iterations--;
|
||||
pos+=(vel*fElapsedTime)/float(totalIterations);
|
||||
if(!CollisionCheck()){
|
||||
return;
|
||||
}
|
||||
}
|
||||
pos=finalBulletPos;
|
||||
if(!CollisionCheck()){
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
pos+=vel*fElapsedTime;
|
||||
}
|
||||
if(/*World size in PIXELS!*/vi2d worldSize=game->GetCurrentMapData().MapSize*game->GetCurrentMapData().TileSize;pos.x+radius<-WINDOW_SIZE.x||pos.x-radius>worldSize.x+WINDOW_SIZE.x||pos.y+radius<-WINDOW_SIZE.y||pos.y-radius>worldSize.y+WINDOW_SIZE.y){
|
||||
dead=true;
|
||||
return;
|
||||
}
|
||||
lifetime-=fElapsedTime;
|
||||
if(lifetime<=0){
|
||||
dead=true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Bullet::Draw()const{
|
||||
auto lerp=[](uint8_t f1,uint8_t f2,float t){return uint8_t((float(f2)*t)+f1*(1-t));};
|
||||
|
||||
@@ -81,4 +153,8 @@ void Bullet::Draw()const{
|
||||
|
||||
bool Bullet::PlayerHit(Player*player){return true;}
|
||||
bool Bullet::MonsterHit(Monster&monster){return true;}
|
||||
bool Bullet::OnUpperLevel(){return upperLevel;}
|
||||
bool Bullet::OnUpperLevel(){return upperLevel;}
|
||||
|
||||
const bool Bullet::IsDead()const{
|
||||
return dead;
|
||||
}
|
||||
Reference in New Issue
Block a user