|
|
@ -15,6 +15,7 @@ std::vector<Monster>MONSTER_LIST; |
|
|
|
std::vector<MonsterSpawner>SPAWNER_LIST; |
|
|
|
std::vector<MonsterSpawner>SPAWNER_LIST; |
|
|
|
std::vector<DamageNumber>DAMAGENUMBER_LIST; |
|
|
|
std::vector<DamageNumber>DAMAGENUMBER_LIST; |
|
|
|
std::vector<Bullet>BULLET_LIST; |
|
|
|
std::vector<Bullet>BULLET_LIST; |
|
|
|
|
|
|
|
std::vector<Bullet>PLAYER_BULLET_LIST; |
|
|
|
Crawler*game; |
|
|
|
Crawler*game; |
|
|
|
|
|
|
|
|
|
|
|
Crawler::Crawler() |
|
|
|
Crawler::Crawler() |
|
|
@ -43,6 +44,7 @@ bool Crawler::OnUserCreate(){ |
|
|
|
GFX_Wizard_Sheet.Load("assets/nico-wizard.png"); |
|
|
|
GFX_Wizard_Sheet.Load("assets/nico-wizard.png"); |
|
|
|
GFX_Battlecry_Effect.Load("assets/battlecry_effect.png"); |
|
|
|
GFX_Battlecry_Effect.Load("assets/battlecry_effect.png"); |
|
|
|
GFX_Mana.Load("assets/mana.png"); |
|
|
|
GFX_Mana.Load("assets/mana.png"); |
|
|
|
|
|
|
|
GFX_SonicSlash.Load("assets/sonicslash.png"); |
|
|
|
|
|
|
|
|
|
|
|
//Animations
|
|
|
|
//Animations
|
|
|
|
InitializeAnimations(); |
|
|
|
InitializeAnimations(); |
|
|
@ -55,6 +57,14 @@ bool Crawler::OnUserCreate(){ |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_E); |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_E); |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_S); |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_S); |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_W); |
|
|
|
player.AddAnimation(AnimationState::WARRIOR_IDLE_W); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSWORD_E); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSWORD_S); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSWORD_N); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSWORD_W); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_E); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_N); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_W); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_N); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_N); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_E); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_E); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_S); |
|
|
|
player.AddAnimation(AnimationState::RANGER_WALK_S); |
|
|
@ -71,10 +81,6 @@ bool Crawler::OnUserCreate(){ |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_E); |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_E); |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_S); |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_S); |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_W); |
|
|
|
player.AddAnimation(AnimationState::WIZARD_IDLE_W); |
|
|
|
player.AddAnimation(AnimationState::SWINGSWORD_E); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::SWINGSWORD_S); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::SWINGSWORD_N); |
|
|
|
|
|
|
|
player.AddAnimation(AnimationState::SWINGSWORD_W); |
|
|
|
|
|
|
|
view=TileTransformedView{GetScreenSize(),{1,1}}; |
|
|
|
view=TileTransformedView{GetScreenSize(),{1,1}}; |
|
|
|
|
|
|
|
|
|
|
|
player.SetClass(WARRIOR); |
|
|
|
player.SetClass(WARRIOR); |
|
|
@ -177,22 +183,31 @@ void Crawler::InitializeAnimations(){ |
|
|
|
pl_warrior_idle_n.AddFrame({&GFX_Warrior_Sheet,{vi2d{0,1}*24,{24,24}}}); |
|
|
|
pl_warrior_idle_n.AddFrame({&GFX_Warrior_Sheet,{vi2d{0,1}*24,{24,24}}}); |
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_IDLE_N]=pl_warrior_idle_n; |
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_IDLE_N]=pl_warrior_idle_n; |
|
|
|
Animate2D::FrameSequence pl_warrior_swing_s(0.05),pl_warrior_swing_n(0.05),pl_warrior_swing_e(0.05),pl_warrior_swing_w(0.05); |
|
|
|
Animate2D::FrameSequence pl_warrior_swing_s(0.05),pl_warrior_swing_n(0.05),pl_warrior_swing_e(0.05),pl_warrior_swing_w(0.05); |
|
|
|
|
|
|
|
Animate2D::FrameSequence pl_warrior_sonic_swing_s(0.1,Animate2D::Style::OneShot),pl_warrior_sonic_swing_n(0.1,Animate2D::Style::OneShot),pl_warrior_sonic_swing_e(0.1,Animate2D::Style::OneShot),pl_warrior_sonic_swing_w(0.1,Animate2D::Style::OneShot); |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
pl_warrior_swing_s.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,0}*24,{24,24}}}); |
|
|
|
pl_warrior_swing_s.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,0}*24,{24,24}}}); |
|
|
|
|
|
|
|
pl_warrior_sonic_swing_s.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,4}*24,{24,24}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
pl_warrior_swing_n.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,1}*24,{24,24}}}); |
|
|
|
pl_warrior_swing_n.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,1}*24,{24,24}}}); |
|
|
|
|
|
|
|
pl_warrior_sonic_swing_n.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,5}*24,{24,24}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
pl_warrior_swing_w.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,2}*24,{24,24}}}); |
|
|
|
pl_warrior_swing_w.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,2}*24,{24,24}}}); |
|
|
|
|
|
|
|
pl_warrior_sonic_swing_w.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,6}*24,{24,24}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
for (int i=0;i<4;i++){ |
|
|
|
pl_warrior_swing_e.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,3}*24,{24,24}}}); |
|
|
|
pl_warrior_swing_e.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,3}*24,{24,24}}}); |
|
|
|
} |
|
|
|
pl_warrior_sonic_swing_e.AddFrame({&GFX_Warrior_Sheet,{vi2d{4+i,7}*24,{24,24}}}); |
|
|
|
ANIMATION_DATA[AnimationState::SWINGSWORD_N]=pl_warrior_swing_n; |
|
|
|
} |
|
|
|
ANIMATION_DATA[AnimationState::SWINGSWORD_E]=pl_warrior_swing_e; |
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSWORD_N]=pl_warrior_swing_n; |
|
|
|
ANIMATION_DATA[AnimationState::SWINGSWORD_S]=pl_warrior_swing_s; |
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSWORD_E]=pl_warrior_swing_e; |
|
|
|
ANIMATION_DATA[AnimationState::SWINGSWORD_W]=pl_warrior_swing_w; |
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSWORD_S]=pl_warrior_swing_s; |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSWORD_W]=pl_warrior_swing_w; |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSONICSWORD_N]=pl_warrior_sonic_swing_n; |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSONICSWORD_E]=pl_warrior_sonic_swing_e; |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSONICSWORD_S]=pl_warrior_sonic_swing_s; |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::WARRIOR_SWINGSONICSWORD_W]=pl_warrior_sonic_swing_w; |
|
|
|
|
|
|
|
|
|
|
|
//Ranger animations
|
|
|
|
//Ranger animations
|
|
|
|
Animate2D::FrameSequence pl_ranger_walk_s{0.2}; |
|
|
|
Animate2D::FrameSequence pl_ranger_walk_s{0.2}; |
|
|
@ -298,6 +313,11 @@ void Crawler::InitializeAnimations(){ |
|
|
|
battlecry_effect.AddFrame({&GFX_Battlecry_Effect,{{i*84,0},{84,84}}}); |
|
|
|
battlecry_effect.AddFrame({&GFX_Battlecry_Effect,{{i*84,0},{84,84}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
ANIMATION_DATA[AnimationState::BATTLECRY_EFFECT]=battlecry_effect; |
|
|
|
ANIMATION_DATA[AnimationState::BATTLECRY_EFFECT]=battlecry_effect; |
|
|
|
|
|
|
|
Animate2D::FrameSequence sonicslash_effect(0.04f,Animate2D::Style::OneShot); |
|
|
|
|
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
|
|
|
|
sonicslash_effect.AddFrame({&GFX_SonicSlash,{{i*60,0},{60,60}}}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ANIMATION_DATA[AnimationState::SONICSLASH]=sonicslash_effect; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Crawler::LeftHeld(){ |
|
|
|
bool Crawler::LeftHeld(){ |
|
|
@ -470,16 +490,16 @@ void Crawler::HandleUserInput(float fElapsedTime){ |
|
|
|
setIdleAnimation=false; |
|
|
|
setIdleAnimation=false; |
|
|
|
switch(player.GetFacingDirection()){ |
|
|
|
switch(player.GetFacingDirection()){ |
|
|
|
case UP:{ |
|
|
|
case UP:{ |
|
|
|
player.UpdateAnimation(AnimationState::SWINGSWORD_N); |
|
|
|
player.UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_N); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case DOWN:{ |
|
|
|
case DOWN:{ |
|
|
|
player.UpdateAnimation(AnimationState::SWINGSWORD_S); |
|
|
|
player.UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_S); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case LEFT:{ |
|
|
|
case LEFT:{ |
|
|
|
player.UpdateAnimation(AnimationState::SWINGSWORD_W); |
|
|
|
player.UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_W); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case RIGHT:{ |
|
|
|
case RIGHT:{ |
|
|
|
player.UpdateAnimation(AnimationState::SWINGSWORD_E); |
|
|
|
player.UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_E); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
} |
|
|
|
} |
|
|
|
player.SetSwordSwingTimer(player.GetSwordSwingTimer()-fElapsedTime); |
|
|
|
player.SetSwordSwingTimer(player.GetSwordSwingTimer()-fElapsedTime); |
|
|
@ -489,7 +509,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(player.GetState()==State::BLOCK){ |
|
|
|
if(player.GetState()!=State::NORMAL){ |
|
|
|
setIdleAnimation=false; |
|
|
|
setIdleAnimation=false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -518,6 +538,17 @@ void Crawler::HandleUserInput(float fElapsedTime){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Crawler::UpdateCamera(float fElapsedTime){ |
|
|
|
void Crawler::UpdateCamera(float fElapsedTime){ |
|
|
|
|
|
|
|
lastWorldShakeAdjust=std::max(0.f,lastWorldShakeAdjust-fElapsedTime); |
|
|
|
|
|
|
|
if(worldShakeTime-fElapsedTime>0){ |
|
|
|
|
|
|
|
if(lastWorldShakeAdjust==0){ |
|
|
|
|
|
|
|
lastWorldShakeAdjust=float(rand()%int(WORLD_SHAKE_ADJUST_MAX_TIME*1000))/1000+0.05; |
|
|
|
|
|
|
|
worldShakeVel={float(rand()%1000)/1000*100-50,float(rand()%1000)/1000*100-50}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
worldShake+=worldShakeVel*fElapsedTime; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
camera.SetTarget(player.GetPos()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
worldShakeTime=std::max(0.f,worldShakeTime-fElapsedTime); |
|
|
|
camera.Update(fElapsedTime); |
|
|
|
camera.Update(fElapsedTime); |
|
|
|
view.SetWorldOffset(vi2d(camera.GetViewPosition())); |
|
|
|
view.SetWorldOffset(vi2d(camera.GetViewPosition())); |
|
|
|
} |
|
|
|
} |
|
|
@ -560,6 +591,45 @@ void Crawler::UpdateBullets(float fElapsedTime){ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
b.lifetime-=fElapsedTime; |
|
|
|
|
|
|
|
if(b.lifetime<=0){ |
|
|
|
|
|
|
|
it=BULLET_LIST.erase(it); |
|
|
|
|
|
|
|
if(it==BULLET_LIST.end()){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
b.animation.UpdateState(b.internal_animState,fElapsedTime); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(std::vector<Bullet>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){ |
|
|
|
|
|
|
|
Bullet&b=*it; |
|
|
|
|
|
|
|
b.pos+=b.vel*fElapsedTime; |
|
|
|
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
|
|
|
if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b.pos,b.radius))){ |
|
|
|
|
|
|
|
if(b.hitList.find(&m)==b.hitList.end()&&m.Hurt(b.damage)){ |
|
|
|
|
|
|
|
if(!b.hitsMultiple){ |
|
|
|
|
|
|
|
it=PLAYER_BULLET_LIST.erase(it); |
|
|
|
|
|
|
|
if(it==PLAYER_BULLET_LIST.end()){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
b.hitList[&m]=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(b.pos.x<view.GetWorldTL().x||b.pos.x>view.GetWorldBR().x||b.pos.y<view.GetWorldTL().y||b.pos.y>view.GetWorldBR().y){ |
|
|
|
|
|
|
|
it=PLAYER_BULLET_LIST.erase(it); |
|
|
|
|
|
|
|
if(it==PLAYER_BULLET_LIST.end()){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
b.lifetime-=fElapsedTime; |
|
|
|
|
|
|
|
if(b.lifetime<=0){ |
|
|
|
|
|
|
|
it=PLAYER_BULLET_LIST.erase(it); |
|
|
|
|
|
|
|
if(it==PLAYER_BULLET_LIST.end()){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
b.animation.UpdateState(b.internal_animState,fElapsedTime); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
void Crawler::HurtEnemies(vf2d pos,float radius,int damage){ |
|
|
|
void Crawler::HurtEnemies(vf2d pos,float radius,int damage){ |
|
|
@ -606,8 +676,10 @@ void Crawler::RenderWorld(float fElapsedTime){ |
|
|
|
e.Draw(); |
|
|
|
e.Draw(); |
|
|
|
} |
|
|
|
} |
|
|
|
for(Bullet&b:BULLET_LIST){ |
|
|
|
for(Bullet&b:BULLET_LIST){ |
|
|
|
view.FillCircle(b.pos,b.radius,b.col); |
|
|
|
b.Draw(); |
|
|
|
view.DrawCircle(b.pos,b.radius,WHITE,0xAA); |
|
|
|
} |
|
|
|
|
|
|
|
for(Bullet&b:PLAYER_BULLET_LIST){ |
|
|
|
|
|
|
|
b.Draw(); |
|
|
|
} |
|
|
|
} |
|
|
|
for(std::vector<DamageNumber>::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){ |
|
|
|
for(std::vector<DamageNumber>::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){ |
|
|
|
DamageNumber&dn=*it; |
|
|
|
DamageNumber&dn=*it; |
|
|
@ -712,6 +784,12 @@ vf2d Crawler::GetWorldMousePos(){ |
|
|
|
return GetMousePos()+view.GetWorldOffset(); |
|
|
|
return GetMousePos()+view.GetWorldOffset(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Crawler::SetupWorldShake(float duration){ |
|
|
|
|
|
|
|
worldShakeTime=duration; |
|
|
|
|
|
|
|
worldShake=player.GetPos(); |
|
|
|
|
|
|
|
camera.SetTarget(worldShake); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
int main() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Crawler demo; |
|
|
|
Crawler demo; |
|
|
|