Auto attacking now based on click position. Damage numbers will stop when they reach a certain height. Monsters not counted in range if dead.
This commit is contained in:
+26
-1
@@ -2,6 +2,7 @@
|
|||||||
#include "Crawler.h"
|
#include "Crawler.h"
|
||||||
#include "olcUTIL_Camera2D.h"
|
#include "olcUTIL_Camera2D.h"
|
||||||
#include "DamageNumber.h"
|
#include "DamageNumber.h"
|
||||||
|
#include "DEFINES.h"
|
||||||
|
|
||||||
//192x192
|
//192x192
|
||||||
const vi2d WINDOW_SIZE={24*8,24*8};
|
const vi2d WINDOW_SIZE={24*8,24*8};
|
||||||
@@ -47,7 +48,25 @@ bool Crawler::OnUserCreate(){
|
|||||||
|
|
||||||
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_BLUE,{-32,-40}},{MonsterName::SLIME_GREEN,{64,20}}}}));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -321,7 +340,9 @@ void Crawler::RenderWorld(float fElapsedTime){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
std::string text=std::to_string(dn.damage);
|
||||||
view.DrawStringPropDecal(dn.pos-GetTextSizeProp(text)/2,text,DARK_RED);
|
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);
|
backgroundEffects.push_back(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vf2d Crawler::GetWorldMousePos(){
|
||||||
|
return GetMousePos()+view.GetWorldOffset();
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Crawler demo;
|
Crawler demo;
|
||||||
|
|||||||
@@ -32,4 +32,5 @@ public:
|
|||||||
void RenderHud();
|
void RenderHud();
|
||||||
void AddEffect(Effect foreground,Effect background);
|
void AddEffect(Effect foreground,Effect background);
|
||||||
void HurtEnemies(vf2d pos,float radius,int damage);
|
void HurtEnemies(vf2d pos,float radius,int damage);
|
||||||
|
vf2d GetWorldMousePos();
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "DamageNumber.h"
|
#include "DamageNumber.h"
|
||||||
|
|
||||||
|
const float DamageNumber::MOVE_UP_TIME=0.4;
|
||||||
|
|
||||||
DamageNumber::DamageNumber(){
|
DamageNumber::DamageNumber(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
struct DamageNumber{
|
struct DamageNumber{
|
||||||
vf2d pos;
|
vf2d pos;
|
||||||
int damage;
|
int damage;
|
||||||
float moveUpTime;
|
float lifeTime=0;
|
||||||
float lifeTime;
|
const static float MOVE_UP_TIME;
|
||||||
DamageNumber();
|
DamageNumber();
|
||||||
DamageNumber(vf2d pos,int damage);
|
DamageNumber(vf2d pos,int damage);
|
||||||
};
|
};
|
||||||
+5
-4
@@ -1,10 +1,11 @@
|
|||||||
#include "Monster.h"
|
#include "Monster.h"
|
||||||
#include "DamageNumber.h"
|
#include "DamageNumber.h"
|
||||||
|
#include "DEFINES.h"
|
||||||
|
|
||||||
extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
|
INCLUDE_ANIMATION_DATA
|
||||||
extern std::map<MonsterName,MonsterData>MONSTER_DATA;
|
INCLUDE_MONSTER_DATA
|
||||||
extern std::vector<Monster>MONSTER_LIST;
|
INCLUDE_MONSTER_LIST
|
||||||
extern std::vector<DamageNumber>DAMAGENUMBER_LIST;
|
INCLUDE_DAMAGENUMBER_LIST
|
||||||
|
|
||||||
MonsterData::MonsterData(){}
|
MonsterData::MonsterData(){}
|
||||||
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy):
|
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy):
|
||||||
|
|||||||
+9
-6
@@ -133,21 +133,24 @@ void Player::Update(float fElapsedTime){
|
|||||||
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
|
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
|
||||||
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
||||||
bool attack=false;
|
bool attack=false;
|
||||||
|
Monster*closest=nullptr;
|
||||||
|
float closest_dist=999999;
|
||||||
for(Monster&m:MONSTER_LIST){
|
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.IsAlive()
|
||||||
if(m.Hurt(atk)){
|
&&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))
|
||||||
attack=true;
|
&&geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length()<closest_dist){
|
||||||
break;
|
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;
|
attack_cooldown_timer=ATTACK_COOLDOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Hurt(int damage){
|
void Player::Hurt(int damage){
|
||||||
|
if(hp<=0) return;
|
||||||
hp=std::max(0,hp-damage);
|
hp=std::max(0,hp-damage);
|
||||||
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user