Auto attacking now based on click position. Damage numbers will stop when they reach a certain height. Monsters not counted in range if dead.

pull/28/head
sigonasr2 1 year ago
parent 3aebde6287
commit 7c542740cc
  1. 27
      Crawler/Crawler.cpp
  2. 1
      Crawler/Crawler.h
  3. 2
      Crawler/DamageNumber.cpp
  4. 4
      Crawler/DamageNumber.h
  5. 9
      Crawler/Monster.cpp
  6. 15
      Crawler/Player.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<std::pair<MonsterName,vf2d>>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.lifeTime<DamageNumber::MOVE_UP_TIME){
dn.pos.y-=20*fElapsedTime;
}
std::string text=std::to_string(dn.damage);
view.DrawStringPropDecal(dn.pos-GetTextSizeProp(text)/2,text,DARK_RED);
}
@ -343,6 +364,10 @@ void Crawler::AddEffect(Effect foreground,Effect background){
backgroundEffects.push_back(background);
}
vf2d Crawler::GetWorldMousePos(){
return GetMousePos()+view.GetWorldOffset();
}
int main()
{
Crawler demo;

@ -32,4 +32,5 @@ public:
void RenderHud();
void AddEffect(Effect foreground,Effect background);
void HurtEnemies(vf2d pos,float radius,int damage);
vf2d GetWorldMousePos();
};

@ -1,5 +1,7 @@
#include "DamageNumber.h"
const float DamageNumber::MOVE_UP_TIME=0.4;
DamageNumber::DamageNumber(){
}

@ -4,8 +4,8 @@
struct DamageNumber{
vf2d pos;
int damage;
float moveUpTime;
float lifeTime;
float lifeTime=0;
const static float MOVE_UP_TIME;
DamageNumber();
DamageNumber(vf2d pos,int damage);
};

@ -1,10 +1,11 @@
#include "Monster.h"
#include "DamageNumber.h"
#include "DEFINES.h"
extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
extern std::map<MonsterName,MonsterData>MONSTER_DATA;
extern std::vector<Monster>MONSTER_LIST;
extern std::vector<DamageNumber>DAMAGENUMBER_LIST;
INCLUDE_ANIMATION_DATA
INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_LIST
INCLUDE_DAMAGENUMBER_LIST
MonsterData::MonsterData(){}
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy):

@ -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<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(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<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))
&&geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length()<closest_dist){
closest_dist=geom2d::line<float>(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));
}

Loading…
Cancel
Save