Added Bullet shooting

This commit is contained in:
2023-06-16 01:41:38 -05:00
parent a2308914a2
commit 01d1e44839
9 changed files with 84 additions and 3 deletions
+29 -2
View File
@@ -1,6 +1,7 @@
#include "Monster.h"
#include "DamageNumber.h"
#include "Crawler.h"
#include "Bullet.h"
#include "DEFINES.h"
INCLUDE_ANIMATION_DATA
@@ -8,6 +9,7 @@ INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_LIST
INCLUDE_DAMAGENUMBER_LIST
INCLUDE_game
INCLUDE_BULLET_LIST
MonsterData::MonsterData(){}
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy,int collisionDmg):
@@ -82,6 +84,19 @@ void Monster::PerformJumpAnimation(){
}break;
}
}
void Monster::PerformShootAnimation(){
switch(type){
case SLIME_GREEN:{
animation.ChangeState(internal_animState,AnimationState::GREEN_SLIME_SPIT);
}break;
case SLIME_BLUE:{
animation.ChangeState(internal_animState,AnimationState::BLUE_SLIME_SPIT);
}break;
case SLIME_RED:{
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_SPIT);
}break;
}
}
void Monster::SetX(float x){
if(x-12*size>0&&x+12*size<game->WORLD_SIZE.x*24){
pos.x=x;
@@ -143,8 +158,16 @@ bool Monster::Update(float fElapsedTime){
}break;
case SHOOT_AFAR:{
targetAcquireTimer=std::max(0.f,targetAcquireTimer-fElapsedTime);
attackCooldownTimer=std::max(0.f,attackCooldownTimer-fElapsedTime);
if(queueShotTimer>0){
queueShotTimer-=fElapsedTime;
if(queueShotTimer<0){
queueShotTimer=0;
BULLET_LIST.push_back(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,atk,{75/2,162/2,225/2}));
}
}
geom2d::line line(pos,game->GetPlayer().GetPos());
if(targetAcquireTimer==0){
if(targetAcquireTimer==0&&queueShotTimer==0){
targetAcquireTimer=1;
if(line.length()<24*6){
target=line.upoint(-1.2);
@@ -209,7 +232,11 @@ bool Monster::Update(float fElapsedTime){
PerformJumpAnimation();
}break;
default:{
UpdateAnimation(MONSTER_DATA[type].GetAnimations()[0]);
if(attackCooldownTimer==0){
attackCooldownTimer=1;
queueShotTimer=0.7;
PerformShootAnimation();
}
}
}
}break;