diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index db460fec..42f19ae1 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -2,6 +2,7 @@ #include "Crawler.h" #include "olcUTIL_Camera2D.h" #include "DamageNumber.h" +#include "DEFINES.h" //192x192 const vi2d WINDOW_SIZE={24*8,24*8}; @@ -47,7 +48,25 @@ bool Crawler::OnUserCreate(){ player.SetPos({4*24,4*24}); player.UpdateAnimation(AnimationState::IDLE_S); + + SPAWNER_LIST.push_back(MonsterSpawner({336,96},4*24,{{{MonsterName::SLIME_BLUE,{-32,-40}},{MonsterName::SLIME_GREEN,{64,20}}}})); + std::vector>circleSpawn; + for(int i=0;i<12;i++){ + float angle=(2*PI)*(i/12.f); + switch(i%3){ + case 0:{ + circleSpawn.push_back({MonsterName::SLIME_BLUE,{cos(angle)*32,sin(angle)*32}}); + }break; + case 1:{ + circleSpawn.push_back({MonsterName::SLIME_GREEN,{cos(angle)*32,sin(angle)*32}}); + }break; + case 2:{ + circleSpawn.push_back({MonsterName::SLIME_RED,{cos(angle)*32,sin(angle)*32}}); + }break; + } + } + SPAWNER_LIST.push_back(MonsterSpawner({540,96},4*24,circleSpawn)); return true; } @@ -321,7 +340,9 @@ void Crawler::RenderWorld(float fElapsedTime){ break; } } else { - dn.pos.y-=20*fElapsedTime; + if(dn.lifeTimeANIMATION_DATA; -extern std::mapMONSTER_DATA; -extern std::vectorMONSTER_LIST; -extern std::vectorDAMAGENUMBER_LIST; +INCLUDE_ANIMATION_DATA +INCLUDE_MONSTER_DATA +INCLUDE_MONSTER_LIST +INCLUDE_DAMAGENUMBER_LIST MonsterData::MonsterData(){} MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vectoranimations,float moveSpd,float size,MonsterStrategy strategy): diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index ae472146..95818171 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -133,21 +133,24 @@ void Player::Update(float fElapsedTime){ groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime); if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){ bool attack=false; + Monster*closest=nullptr; + float closest_dist=999999; for(Monster&m:MONSTER_LIST){ - if(geom2d::overlaps(geom2d::circle(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))){ - if(m.Hurt(atk)){ - attack=true; - break; - } + if(m.IsAlive() + &&geom2d::overlaps(geom2d::circle(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12)) + &&geom2d::line(game->GetWorldMousePos(),m.GetPos()).length()(game->GetWorldMousePos(),m.GetPos()).length(); + closest=&m; } } - if(attack){ + if(closest!=nullptr&&closest->Hurt(atk)){ attack_cooldown_timer=ATTACK_COOLDOWN; } } } void Player::Hurt(int damage){ + if(hp<=0) return; hp=std::max(0,hp-damage); DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage)); }