|
|
|
@ -4,12 +4,14 @@ |
|
|
|
|
#include "olcPGEX_TransformedView.h" |
|
|
|
|
#include "Crawler.h" |
|
|
|
|
#include "olcUTIL_Camera2D.h" |
|
|
|
|
#include "DamageNumber.h" |
|
|
|
|
|
|
|
|
|
//192x192
|
|
|
|
|
const vi2d WINDOW_SIZE={24*8,24*8}; |
|
|
|
|
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; |
|
|
|
|
std::vector<Monster>MONSTER_LIST; |
|
|
|
|
std::vector<MonsterSpawner>SPAWNER_LIST; |
|
|
|
|
std::vector<DamageNumber>DAMAGENUMBER_LIST; |
|
|
|
|
Crawler*game; |
|
|
|
|
|
|
|
|
|
Crawler::Crawler() |
|
|
|
@ -57,7 +59,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
m.Update(fElapsedTime); |
|
|
|
|
} |
|
|
|
|
UpdateCamera(fElapsedTime); |
|
|
|
|
RenderWorld(); |
|
|
|
|
RenderWorld(fElapsedTime); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -236,17 +238,40 @@ void Crawler::UpdateCamera(float fElapsedTime){ |
|
|
|
|
view.SetWorldOffset(vi2d(camera.GetViewPosition())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Crawler::RenderWorld(){ |
|
|
|
|
void Crawler::RenderWorld(float fElapsedTime){ |
|
|
|
|
Clear({100,180,100}); |
|
|
|
|
for (int x = view.GetTopLeftTile().x/24-1; x <= view.GetBottomRightTile().x/24; x++){ |
|
|
|
|
for (int y = view.GetTopLeftTile().y/24-1; y <= view.GetBottomRightTile().y/24; y++){ |
|
|
|
|
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::vector<Monster>monstersBefore,monstersAfter; |
|
|
|
|
Player&pl=player; |
|
|
|
|
std::copy_if(MONSTER_LIST.begin(),MONSTER_LIST.end(),std::back_inserter(monstersBefore),[&pl](Monster&m){return m.GetPos().y<pl.GetPos().y;}); |
|
|
|
|
std::copy_if(MONSTER_LIST.begin(),MONSTER_LIST.end(),std::back_inserter(monstersAfter),[&pl](Monster&m){return m.GetPos().y>=pl.GetPos().y;}); |
|
|
|
|
std::sort(monstersBefore.begin(),monstersBefore.end(),[](Monster&m1,Monster&m2){return m1.GetPos().y<m2.GetPos().y;}); |
|
|
|
|
std::sort(monstersAfter.begin(),monstersAfter.end(),[](Monster&m1,Monster&m2){return m1.GetPos().y<m2.GetPos().y;}); |
|
|
|
|
for(Monster&m:monstersBefore){ |
|
|
|
|
view.DrawPartialDecal(m.GetPos()-vi2d{12,12}*m.GetSizeMult(),m.GetFrame().GetSourceImage()->Decal(),m.GetFrame().GetSourceRect().pos,m.GetFrame().GetSourceRect().size,vf2d(m.GetSizeMult(),m.GetSizeMult())); |
|
|
|
|
} |
|
|
|
|
view.DrawPartialDecal(player.GetPos()-vi2d{12,12}*player.GetSizeMult(),player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size,vf2d(player.GetSizeMult(),player.GetSizeMult())); |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
for(Monster&m:monstersAfter){ |
|
|
|
|
view.DrawPartialDecal(m.GetPos()-vi2d{12,12}*m.GetSizeMult(),m.GetFrame().GetSourceImage()->Decal(),m.GetFrame().GetSourceRect().pos,m.GetFrame().GetSourceRect().size,vf2d(m.GetSizeMult(),m.GetSizeMult())); |
|
|
|
|
} |
|
|
|
|
for(std::vector<DamageNumber>::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){ |
|
|
|
|
DamageNumber&dn=*it; |
|
|
|
|
dn.lifeTime+=fElapsedTime; |
|
|
|
|
if(dn.lifeTime>1){ |
|
|
|
|
it=DAMAGENUMBER_LIST.erase(it); |
|
|
|
|
if(it==DAMAGENUMBER_LIST.end()){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
dn.pos.y-=20*fElapsedTime; |
|
|
|
|
std::string text=std::to_string(dn.damage); |
|
|
|
|
view.DrawStringPropDecal(dn.pos-GetTextSizeProp(text)/2,text,DARK_RED); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|