|
|
@ -7,10 +7,13 @@ |
|
|
|
#include "Monster.h" |
|
|
|
#include "Monster.h" |
|
|
|
#include "Animation.h" |
|
|
|
#include "Animation.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//192x192
|
|
|
|
const vi2d WINDOW_SIZE={24*8,24*8}; |
|
|
|
const vi2d WINDOW_SIZE={24*8,24*8}; |
|
|
|
|
|
|
|
|
|
|
|
extern std::map<MonsterName,MonsterData>MONSTER_DATA; |
|
|
|
extern std::map<MonsterName,MonsterData>MONSTER_DATA; |
|
|
|
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; |
|
|
|
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; |
|
|
|
|
|
|
|
std::vector<Monster>MONSTER_LIST; |
|
|
|
|
|
|
|
std::vector<MonsterSpawner>SPAWNER_LIST; |
|
|
|
|
|
|
|
|
|
|
|
struct Player{ |
|
|
|
struct Player{ |
|
|
|
private: |
|
|
|
private: |
|
|
@ -85,6 +88,15 @@ struct Player{ |
|
|
|
Key GetLastReleasedMovementKey(){ |
|
|
|
Key GetLastReleasedMovementKey(){ |
|
|
|
return lastReleasedMovementKey; |
|
|
|
return lastReleasedMovementKey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Triggers when the player has moved.
|
|
|
|
|
|
|
|
void Moved(){ |
|
|
|
|
|
|
|
for(MonsterSpawner&spawner:SPAWNER_LIST){ |
|
|
|
|
|
|
|
if(!spawner.SpawnTriggered()&&geom2d::overlaps(geom2d::circle<float>(pos,size*12),geom2d::circle<float>(spawner.GetPos(),spawner.GetRange()))){ |
|
|
|
|
|
|
|
spawner.SetTriggered(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class Crawler : public olc::PixelGameEngine |
|
|
|
class Crawler : public olc::PixelGameEngine |
|
|
@ -94,8 +106,6 @@ class Crawler : public olc::PixelGameEngine |
|
|
|
TileTransformedView view; |
|
|
|
TileTransformedView view; |
|
|
|
Player player=Player{{}}; |
|
|
|
Player player=Player{{}}; |
|
|
|
Renderable GFX_Pl_Sheet,GFX_Slime_Sheet; |
|
|
|
Renderable GFX_Pl_Sheet,GFX_Slime_Sheet; |
|
|
|
std::vector<MonsterSpawner>spawners; |
|
|
|
|
|
|
|
std::vector<Monster>monsters; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
Crawler() |
|
|
|
Crawler() |
|
|
@ -133,7 +143,7 @@ public: |
|
|
|
player.SetPos({4*24,4*24}); |
|
|
|
player.SetPos({4*24,4*24}); |
|
|
|
player.UpdateAnimation(AnimationState::IDLE_S); |
|
|
|
player.UpdateAnimation(AnimationState::IDLE_S); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SPAWNER_LIST.push_back(MonsterSpawner({336,96},4*24,{{{MonsterName::SLIME_GREEN,{-32,-40}},{MonsterName::SLIME_GREEN,{64,20}}}})); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -142,11 +152,14 @@ public: |
|
|
|
{ |
|
|
|
{ |
|
|
|
HandleUserInput(fElapsedTime); |
|
|
|
HandleUserInput(fElapsedTime); |
|
|
|
player.Update(fElapsedTime); |
|
|
|
player.Update(fElapsedTime); |
|
|
|
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
|
|
|
m.Update(fElapsedTime); |
|
|
|
|
|
|
|
} |
|
|
|
UpdateCamera(fElapsedTime); |
|
|
|
UpdateCamera(fElapsedTime); |
|
|
|
RenderWorld(); |
|
|
|
RenderWorld(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void InitializeAnimations(){ |
|
|
|
void InitializeAnimations(){ |
|
|
|
Animate2D::FrameSequence pl_walk_s{0.2}; |
|
|
|
Animate2D::FrameSequence pl_walk_s{0.2}; |
|
|
|
pl_walk_s.AddFrame({&GFX_Pl_Sheet,{vi2d{0,0}*24,{24,24}}}); |
|
|
|
pl_walk_s.AddFrame({&GFX_Pl_Sheet,{vi2d{0,0}*24,{24,24}}}); |
|
|
@ -307,6 +320,9 @@ public: |
|
|
|
player.UpdateAnimation(AnimationState::IDLE_S); |
|
|
|
player.UpdateAnimation(AnimationState::IDLE_S); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//We have moved.
|
|
|
|
|
|
|
|
player.Moved(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -322,7 +338,10 @@ public: |
|
|
|
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY); |
|
|
|
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
view.DrawPartialDecal(player.GetPos()-vi2d{12,12},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size); |
|
|
|
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){ |
|
|
|
|
|
|
|
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())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|