|
|
@ -10,8 +10,8 @@ INCLUDE_DAMAGENUMBER_LIST |
|
|
|
INCLUDE_game |
|
|
|
INCLUDE_game |
|
|
|
|
|
|
|
|
|
|
|
MonsterData::MonsterData(){} |
|
|
|
MonsterData::MonsterData(){} |
|
|
|
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy): |
|
|
|
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy,int collisionDmg): |
|
|
|
type(type),hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations){ |
|
|
|
type(type),hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations),collisionDmg(collisionDmg){ |
|
|
|
} |
|
|
|
} |
|
|
|
int MonsterData::GetHealth(){ |
|
|
|
int MonsterData::GetHealth(){ |
|
|
|
return hp; |
|
|
|
return hp; |
|
|
@ -25,6 +25,9 @@ float MonsterData::GetMoveSpdMult(){ |
|
|
|
float MonsterData::GetSizeMult(){ |
|
|
|
float MonsterData::GetSizeMult(){ |
|
|
|
return size; |
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int MonsterData::GetCollisionDmg(){ |
|
|
|
|
|
|
|
return collisionDmg; |
|
|
|
|
|
|
|
} |
|
|
|
MonsterName MonsterData::GetType(){ |
|
|
|
MonsterName MonsterData::GetType(){ |
|
|
|
return type; |
|
|
|
return type; |
|
|
|
} |
|
|
|
} |
|
|
@ -66,6 +69,33 @@ Animate2D::Frame Monster::GetFrame(){ |
|
|
|
void Monster::UpdateAnimation(AnimationState state){ |
|
|
|
void Monster::UpdateAnimation(AnimationState state){ |
|
|
|
animation.ChangeState(internal_animState,state); |
|
|
|
animation.ChangeState(internal_animState,state); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Monster::PerformJumpAnimation(){ |
|
|
|
|
|
|
|
switch(type){ |
|
|
|
|
|
|
|
case SLIME_GREEN:{ |
|
|
|
|
|
|
|
animation.ChangeState(internal_animState,AnimationState::GREEN_SLIME_JUMP); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case SLIME_BLUE:{ |
|
|
|
|
|
|
|
animation.ChangeState(internal_animState,AnimationState::BLUE_SLIME_JUMP); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case SLIME_RED:{ |
|
|
|
|
|
|
|
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_JUMP); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Monster::SetX(float x){ |
|
|
|
|
|
|
|
if(x-12*size>0&&x+12*size<game->WORLD_SIZE.x*24){ |
|
|
|
|
|
|
|
pos.x=x; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pos.x=std::min(game->WORLD_SIZE.x*24-12*size,std::max(12*size,pos.x)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Monster::SetY(float y){ |
|
|
|
|
|
|
|
if(y-12*size>0&&y+12*size<game->WORLD_SIZE.y*24){ |
|
|
|
|
|
|
|
pos.y=y; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pos.y=std::min(game->WORLD_SIZE.y*24-12*size,std::max(12*size,pos.y)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
bool Monster::Update(float fElapsedTime){ |
|
|
|
bool Monster::Update(float fElapsedTime){ |
|
|
|
if(IsAlive()){ |
|
|
|
if(IsAlive()){ |
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
@ -102,23 +132,86 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
state=MOVE_TOWARDS; |
|
|
|
state=MOVE_TOWARDS; |
|
|
|
} |
|
|
|
} |
|
|
|
if(state==MOVE_TOWARDS&&geom2d::line(pos,target).length()>100*fElapsedTime*moveSpd){ |
|
|
|
if(state==MOVE_TOWARDS&&geom2d::line(pos,target).length()>100*fElapsedTime*moveSpd){ |
|
|
|
pos+=geom2d::line(pos,target).vector().norm()*100*fElapsedTime*moveSpd; |
|
|
|
SetPosition(pos+geom2d::line(pos,target).vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
switch(type){ |
|
|
|
PerformJumpAnimation(); |
|
|
|
case SLIME_GREEN:{ |
|
|
|
|
|
|
|
animation.ChangeState(internal_animState,AnimationState::GREEN_SLIME_JUMP); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case SLIME_RED:{ |
|
|
|
|
|
|
|
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_JUMP); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if(state==MOVE_TOWARDS){ |
|
|
|
if(state==MOVE_TOWARDS){ |
|
|
|
state=NORMAL;//Revert state once we've finished moving towards target.
|
|
|
|
state=NORMAL;//Revert state once we've finished moving towards target.
|
|
|
|
|
|
|
|
UpdateAnimation(MONSTER_DATA[type].GetAnimations()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case SHOOT_AFAR:{ |
|
|
|
case SHOOT_AFAR:{ |
|
|
|
|
|
|
|
targetAcquireTimer=std::max(0.f,targetAcquireTimer-fElapsedTime); |
|
|
|
|
|
|
|
geom2d::line line(pos,game->GetPlayer().GetPos()); |
|
|
|
|
|
|
|
if(targetAcquireTimer==0){ |
|
|
|
|
|
|
|
targetAcquireTimer=1; |
|
|
|
|
|
|
|
if(line.length()<24*6){ |
|
|
|
|
|
|
|
target=line.upoint(-1.2); |
|
|
|
|
|
|
|
if(pos.x-12*size>1&&pos.x+12*size<game->WORLD_SIZE.x*24-1&& |
|
|
|
|
|
|
|
pos.y-12*size>1&&pos.y+12*size<game->WORLD_SIZE.y*24-1){ |
|
|
|
|
|
|
|
state=MOVE_AWAY; |
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(pos.x-12*size<=1||pos.x+12*size>=game->WORLD_SIZE.x*24-1){ |
|
|
|
|
|
|
|
geom2d::line moveTowardsLine=geom2d::line(pos,target); |
|
|
|
|
|
|
|
if(abs(moveTowardsLine.vector().norm().y)>=0.5){ |
|
|
|
|
|
|
|
std::cout<<moveTowardsLine.vector().norm().x<<std::endl; |
|
|
|
|
|
|
|
state=MOVE_AWAY; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
state=NORMAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(pos.y-12*size<=1||pos.y+12*size>=game->WORLD_SIZE.y*24-1){ |
|
|
|
|
|
|
|
geom2d::line moveTowardsLine=geom2d::line(pos,target); |
|
|
|
|
|
|
|
if(abs(moveTowardsLine.vector().norm().x)>=0.5){ |
|
|
|
|
|
|
|
std::cout<<moveTowardsLine.vector().norm().x<<std::endl; |
|
|
|
|
|
|
|
state=MOVE_AWAY; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
state=NORMAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
if(line.length()>24*7){ |
|
|
|
|
|
|
|
target=line.upoint(1.2); |
|
|
|
|
|
|
|
state=MOVE_TOWARDS; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
state=NORMAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
geom2d::line moveTowardsLine=geom2d::line(pos,target); |
|
|
|
|
|
|
|
switch(state){ |
|
|
|
|
|
|
|
case MOVE_TOWARDS:{ |
|
|
|
|
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
|
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(line.length()<=24*7){ |
|
|
|
|
|
|
|
state=NORMAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(moveTowardsLine.vector().x>0){ |
|
|
|
|
|
|
|
facingDirection=RIGHT; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
facingDirection=LEFT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PerformJumpAnimation(); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case MOVE_AWAY:{ |
|
|
|
|
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
|
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(line.length()>=24*6){ |
|
|
|
|
|
|
|
state=NORMAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(moveTowardsLine.vector().x>0){ |
|
|
|
|
|
|
|
facingDirection=RIGHT; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
facingDirection=LEFT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PerformJumpAnimation(); |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
default:{ |
|
|
|
|
|
|
|
UpdateAnimation(MONSTER_DATA[type].GetAnimations()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(vel.x>0){ |
|
|
|
if(vel.x>0){ |
|
|
@ -131,14 +224,8 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
vel.y=std::min(0.f,vel.y+friction*fElapsedTime); |
|
|
|
vel.y=std::min(0.f,vel.y+friction*fElapsedTime); |
|
|
|
} |
|
|
|
} |
|
|
|
float newX=pos.x+vel.x*fElapsedTime; |
|
|
|
SetX(pos.x+vel.x*fElapsedTime); |
|
|
|
if(newX-12*size>0&&newX+12*size<game->WORLD_SIZE.x*24){ |
|
|
|
SetY(pos.y+vel.y*fElapsedTime); |
|
|
|
pos.x=newX; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float newY=pos.y+vel.y*fElapsedTime; |
|
|
|
|
|
|
|
if(newY-12*size>0&&newY+12*size<game->WORLD_SIZE.y*24){ |
|
|
|
|
|
|
|
pos.y=newY; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(hp<=0){ |
|
|
|
if(hp<=0){ |
|
|
|
deathTimer+=fElapsedTime; |
|
|
|
deathTimer+=fElapsedTime; |
|
|
@ -159,12 +246,11 @@ void Monster::Draw(){ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult())); |
|
|
|
game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult())); |
|
|
|
} |
|
|
|
} |
|
|
|
if(GetTargetPos()!=vf2d{0,0}){ |
|
|
|
|
|
|
|
game->view.DrawLine(GetPos(),GetTargetPos(),RED,0xF4F4F4F4); |
|
|
|
|
|
|
|
game->view.DrawCircle(GetTargetPos(),6,RED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
void Monster::Collision(Player&p){ |
|
|
|
void Monster::Collision(Player&p){ |
|
|
|
|
|
|
|
if(MONSTER_DATA[type].GetCollisionDmg()>0){ |
|
|
|
|
|
|
|
p.Hurt(MONSTER_DATA[type].GetCollisionDmg()); |
|
|
|
|
|
|
|
} |
|
|
|
Collision(); |
|
|
|
Collision(); |
|
|
|
} |
|
|
|
} |
|
|
|
void Monster::Collision(Monster&m){ |
|
|
|
void Monster::Collision(Monster&m){ |
|
|
@ -179,7 +265,8 @@ void Monster::SetVelocity(vf2d vel){ |
|
|
|
this->vel=vel; |
|
|
|
this->vel=vel; |
|
|
|
} |
|
|
|
} |
|
|
|
void Monster::SetPosition(vf2d pos){ |
|
|
|
void Monster::SetPosition(vf2d pos){ |
|
|
|
this->pos=pos; |
|
|
|
SetX(pos.x); |
|
|
|
|
|
|
|
SetY(pos.y); |
|
|
|
} |
|
|
|
} |
|
|
|
AnimationState Monster::GetDeathAnimationName(){ |
|
|
|
AnimationState Monster::GetDeathAnimationName(){ |
|
|
|
switch(type){ |
|
|
|
switch(type){ |
|
|
|