Wizard energy bolt attack implemented.

pull/28/head
sigonasr2 1 year ago
parent 9a8859ffe8
commit db7744dad3
  1. 1
      Crawler/Animation.h
  2. 10
      Crawler/Bullet.cpp
  3. 8
      Crawler/Bullet.h
  4. 23
      Crawler/Crawler.cpp
  5. 4
      Crawler/Crawler.h
  6. 3
      Crawler/DEFINES.h
  7. 5
      Crawler/Effect.cpp
  8. 3
      Crawler/Effect.h
  9. 37
      Crawler/Player.cpp
  10. 2
      Crawler/Version.h
  11. BIN
      Crawler/assets/energy_bolt.png
  12. BIN
      Crawler/assets/energy_particle.png
  13. BIN
      Crawler/assets/nico-wizard.png
  14. BIN
      Crawler/assets/nico-wizard.xcf

@ -17,4 +17,5 @@ enum AnimationState{
WARRIOR_SWINGSONICSWORD_S,WARRIOR_SWINGSONICSWORD_E,WARRIOR_SWINGSONICSWORD_N,WARRIOR_SWINGSONICSWORD_W,
WIZARD_IDLE_ATTACK_S,WIZARD_IDLE_ATTACK_E,WIZARD_IDLE_ATTACK_N,WIZARD_IDLE_ATTACK_W,
WIZARD_ATTACK_S,WIZARD_ATTACK_E,WIZARD_ATTACK_N,WIZARD_ATTACK_W,
ENERGY_BOLT,ENERGY_PARTICLE
};

@ -18,6 +18,16 @@ Animate2D::Frame Bullet::GetFrame(){
return animation.GetFrame(internal_animState);
}
void Bullet::Update(float fElapsedTime){
if(animated){
lastParticleSpawn=std::max(0.f,lastParticleSpawn-fElapsedTime);
if(lastParticleSpawn==0&&animation.GetFrame(internal_animState).GetSourceImage()==&game->GFX_EnergyBolt){
lastParticleSpawn=0.03;
game->AddEffect(Effect(pos,float(rand()%500)/500,AnimationState::ENERGY_PARTICLE,float(rand()%1000)/500,0.5,{float(rand()%60)-30,float(rand()%60)-30}));
}
}
}
void Bullet::Draw(){
if(animated){
game->view.DrawPartialRotatedDecal(pos,GetFrame().GetSourceImage()->Decal(),rotates?atan2(vel.y,vel.x)-PI/2:0,GetFrame().GetSourceRect().size/2,GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,{1,1},col);

@ -4,23 +4,27 @@
#include "olcUTIL_Animate2D.h"
#include "Monster.h"
#define INFINITE 999999
struct Bullet{
vf2d pos;
vf2d vel;
float radius;
int damage;
Pixel col;
float lifetime=99999;
float lifetime=INFINITE;
bool hitsMultiple=false;
bool rotates=false;
bool animated=false;
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
std::map<Monster*,bool>hitList;
float lastParticleSpawn=0;
Bullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE);
//Initializes a bullet with an animation.
Bullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=999999,bool rotatesWithAngle=false,Pixel col=WHITE);
Bullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,Pixel col=WHITE);
public:
void Update(float fElapsedTime);
Animate2D::Frame GetFrame();
void Draw();
};

@ -54,6 +54,8 @@ bool Crawler::OnUserCreate(){
GFX_SonicSlash.Load("assets/sonicslash.png");
GFX_BulletCircle.Load("assets/circle.png");
GFX_BulletCircleOutline.Load("assets/circle_outline.png");
GFX_EnergyBolt.Load("assets/energy_bolt.png");
GFX_EnergyParticle.Load("assets/energy_particle.png");
//Animations
InitializeAnimations();
@ -284,7 +286,7 @@ void Crawler::InitializeAnimations(){
ANIMATION_DATA[AnimationState::WIZARD_ATTACK_S]=pl_wizard_attack_s;
Animate2D::FrameSequence pl_wizard_attack_e(0.2);
for(int i=0;i<3;i++){
pl_wizard_attack_e.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,3}*24,{24,24}}});
pl_wizard_attack_e.AddFrame({&GFX_Wizard_Sheet,{vi2d{4+i,3}*24,{24,24}}});
if(i==1){
pl_wizard_attack_e.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,3}*24,{24,24}}});
}
@ -292,7 +294,7 @@ void Crawler::InitializeAnimations(){
ANIMATION_DATA[AnimationState::WIZARD_ATTACK_E]=pl_wizard_attack_e;
Animate2D::FrameSequence pl_wizard_attack_w(0.2);
for(int i=0;i<3;i++){
pl_wizard_attack_w.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,2}*24,{24,24}}});
pl_wizard_attack_w.AddFrame({&GFX_Wizard_Sheet,{vi2d{4+i,2}*24,{24,24}}});
if(i==1){
pl_wizard_attack_w.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,2}*24,{24,24}}});
}
@ -300,7 +302,7 @@ void Crawler::InitializeAnimations(){
ANIMATION_DATA[AnimationState::WIZARD_ATTACK_W]=pl_wizard_attack_w;
Animate2D::FrameSequence pl_wizard_attack_n(0.2);
for(int i=0;i<3;i++){
pl_wizard_attack_n.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,1}*24,{24,24}}});
pl_wizard_attack_n.AddFrame({&GFX_Wizard_Sheet,{vi2d{4+i,1}*24,{24,24}}});
if(i==1){
pl_wizard_attack_n.AddFrame({&GFX_Wizard_Sheet,{vi2d{4,1}*24,{24,24}}});
}
@ -340,6 +342,15 @@ void Crawler::InitializeAnimations(){
sonicslash_effect.AddFrame({&GFX_SonicSlash,{{i*60,0},{60,60}}});
}
ANIMATION_DATA[AnimationState::SONICSLASH]=sonicslash_effect;
Animate2D::FrameSequence energy_bolt;
energy_bolt.AddFrame({&GFX_EnergyBolt,{{0,0},{24,24}}});
ANIMATION_DATA[AnimationState::ENERGY_BOLT]=energy_bolt;
Animate2D::FrameSequence energy_particle;
for(int i=0;i<3;i++){
energy_particle.AddFrame({&GFX_EnergyParticle,{{i*3,0},{3,3}}});
}
ANIMATION_DATA[AnimationState::ENERGY_PARTICLE]=energy_particle;
}
bool Crawler::LeftHeld(){
@ -582,6 +593,7 @@ void Crawler::UpdateEffects(float fElapsedTime){
void Crawler::UpdateBullets(float fElapsedTime){
for(std::vector<Bullet>::iterator it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){
Bullet&b=*it;
b.Update(fElapsedTime);
b.pos+=b.vel*fElapsedTime;
if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){
if(player.Hurt(b.damage)){
@ -608,6 +620,7 @@ void Crawler::UpdateBullets(float fElapsedTime){
}
for(std::vector<Bullet>::iterator it=PLAYER_BULLET_LIST.begin();it!=PLAYER_BULLET_LIST.end();++it){
Bullet&b=*it;
b.Update(fElapsedTime);
b.pos+=b.vel*fElapsedTime;
for(Monster&m:MONSTER_LIST){
if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b.pos,b.radius))){
@ -615,7 +628,7 @@ void Crawler::UpdateBullets(float fElapsedTime){
if(!b.hitsMultiple){
it=PLAYER_BULLET_LIST.erase(it);
if(it==PLAYER_BULLET_LIST.end()){
break;
goto outsidePlayerBulletLoop;
}
}
b.hitList[&m]=true;
@ -637,6 +650,8 @@ void Crawler::UpdateBullets(float fElapsedTime){
}
b.animation.UpdateState(b.internal_animState,fElapsedTime);
}
outsidePlayerBulletLoop:
int a;
}
void Crawler::HurtEnemies(vf2d pos,float radius,int damage){
for(Monster&m:MONSTER_LIST){

@ -22,9 +22,9 @@ class Crawler : public olc::PixelGameEngine
Renderable GFX_Warrior_Sheet,GFX_Slime_Sheet,GFX_Circle,
GFX_Effect_GroundSlam_Back,GFX_Effect_GroundSlam_Front,
GFX_Heart,GFX_BLOCK_BUBBLE,GFX_Ranger_Sheet,GFX_Wizard_Sheet,
GFX_Battlecry_Effect,GFX_Mana,GFX_SonicSlash;
GFX_Battlecry_Effect,GFX_Mana,GFX_SonicSlash,GFX_EnergyParticle;
public:
Renderable GFX_BulletCircle,GFX_BulletCircleOutline;
Renderable GFX_BulletCircle,GFX_BulletCircleOutline,GFX_EnergyBolt;
private:
std::vector<Effect>foregroundEffects,backgroundEffects;
std::map<MapName,Map>MAP_DATA;

@ -7,4 +7,5 @@
#define INCLUDE_MONSTER_DATA extern std::map<MonsterName,MonsterData>MONSTER_DATA;
#define INCLUDE_BULLET_LIST extern std::vector<Bullet>BULLET_LIST;
#define INCLUDE_CLASS_DATA extern std::map<Class,ClassData>CLASS_DATA;
#define INCLUDE_PLAYER_BULLET_LIST extern std::vector<Bullet>PLAYER_BULLET_LIST;
#define INCLUDE_PLAYER_BULLET_LIST extern std::vector<Bullet>PLAYER_BULLET_LIST;
#define INCLUDE_PARTICLE_LIST extern std::vector<Particle>PARTICLE_LIST;

@ -5,8 +5,8 @@
INCLUDE_ANIMATION_DATA
INCLUDE_game
Effect::Effect(vf2d pos,float lifetime,AnimationState animation,float size,float fadeout)
:pos(pos),lifetime(lifetime),size(size),fadeout(fadeout),original_fadeoutTime(fadeout){
Effect::Effect(vf2d pos,float lifetime,AnimationState animation,float size,float fadeout,vf2d spd)
:pos(pos),lifetime(lifetime),size(size),fadeout(fadeout),original_fadeoutTime(fadeout),spd(spd){
this->animation.AddState(animation,ANIMATION_DATA[animation]);
}
@ -18,6 +18,7 @@ bool Effect::Update(float fElapsedTime){
return false;
}
}
pos+=spd*fElapsedTime;
animation.UpdateState(internal_animState,fElapsedTime);
return true;
}

@ -8,7 +8,8 @@ struct Effect{
float lifetime=0;
float fadeout=0;
float size=1;
Effect(vf2d pos,float lifetime,AnimationState animation,float size=1.0f,float fadeout=0.0f);
vf2d spd={};
Effect(vf2d pos,float lifetime,AnimationState animation,float size=1.0f,float fadeout=0.0f,vf2d spd={});
bool Update(float fElapsedTime);
Animate2D::Frame GetFrame();
void Draw();

@ -147,6 +147,40 @@ void Player::Update(float fElapsedTime){
if(it==buffList.end())break;
}
}
//Class-specific update events.
switch (cl) {
case WARRIOR: {
}break;
case THIEF: {
}break;
case RANGER: {
}break;
case BARD: {
}break;
case WIZARD: {
if(attack_cooldown_timer>0){
CLASS_DATA[cl].idle_n=AnimationState::WIZARD_IDLE_ATTACK_N;
CLASS_DATA[cl].idle_e=AnimationState::WIZARD_IDLE_ATTACK_E;
CLASS_DATA[cl].idle_s=AnimationState::WIZARD_IDLE_ATTACK_S;
CLASS_DATA[cl].idle_w=AnimationState::WIZARD_IDLE_ATTACK_W;
CLASS_DATA[cl].walk_n=AnimationState::WIZARD_ATTACK_N;
CLASS_DATA[cl].walk_e=AnimationState::WIZARD_ATTACK_E;
CLASS_DATA[cl].walk_s=AnimationState::WIZARD_ATTACK_S;
CLASS_DATA[cl].walk_w=AnimationState::WIZARD_ATTACK_W;
} else {
CLASS_DATA[cl].idle_n=AnimationState::WIZARD_IDLE_N;
CLASS_DATA[cl].idle_e=AnimationState::WIZARD_IDLE_E;
CLASS_DATA[cl].idle_s=AnimationState::WIZARD_IDLE_S;
CLASS_DATA[cl].idle_w=AnimationState::WIZARD_IDLE_W;
CLASS_DATA[cl].walk_n=AnimationState::WIZARD_WALK_N;
CLASS_DATA[cl].walk_e=AnimationState::WIZARD_WALK_E;
CLASS_DATA[cl].walk_s=AnimationState::WIZARD_WALK_S;
CLASS_DATA[cl].walk_w=AnimationState::WIZARD_WALK_W;
}
}break;
case WITCH: {
}break;
}
switch(state){
case SPIN:{
switch(facingDirection){
@ -292,7 +326,8 @@ void Player::Update(float fElapsedTime){
}break;
case WIZARD: {
attack_cooldown_timer=MAGIC_ATTACK_COOLDOWN;
//PLAYER_BULLET_LIST.push_back(Bullet();
float angleToCursor=atan2(game->GetWorldMousePos().y-pos.y,game->GetWorldMousePos().x-pos.x);
PLAYER_BULLET_LIST.push_back(Bullet(pos,{cos(angleToCursor)*200,sin(angleToCursor)*200},12,GetAttack(),AnimationState::ENERGY_BOLT,false,INFINITE,true));
}break;
case WITCH: {
}break;

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 301
#define VERSION_BUILD 316
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.
Loading…
Cancel
Save