Skip to content

Commit

Permalink
Particles fully implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigodpl committed May 31, 2016
1 parent 7b3e956 commit d792f9b
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Blood-bros-0.6/Enemy_Barrel_Guy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void Enemy_Barrel_Guy::Update()
}

if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->enemy_shot, position.x + 40, position.y - 100, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->enemy_shot_2, position.x + 40, position.y - 100, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->big_shot_flare, position.x, position.y - 120);
state = EN_ST_WALKING;
}
}
2 changes: 1 addition & 1 deletion Blood-bros-0.6/Enemy_Cart_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Enemy_Cart_001::Update()


if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->dynamite, position.x + 50, position.y - 80, COLLIDER_ENEMY_BOMB);
App->particles->AddParticle(App->particles->enemy_bomb, position.x + 50, position.y - 80, COLLIDER_ENEMY_BOMB);
state = EN_ST_WALKING;
}
}
Expand Down
1 change: 1 addition & 0 deletions Blood-bros-0.6/Enemy_Indian_002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void Enemy_Indian_002::Update()

if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->enemy_shot, position.x + 40, position.y - 100, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->shot_flare, position.x + 17, position.y - 100);
state = EN_ST_WALKING;
}
}
Expand Down
1 change: 1 addition & 0 deletions Blood-bros-0.6/Enemy_Indian_003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void Enemy_Indian_003::Update()

if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->enemy_shot, position.x + 40, position.y - 60, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->shot_flare, position.x + 7, position.y - 70);
state = EN_ST_WALKING;
}
}
Expand Down
1 change: 1 addition & 0 deletions Blood-bros-0.6/Enemy_Mounted_Indian_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void Enemy_Mounted_Indian_001::Update()

if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->enemy_shot, position.x + 25, position.y - 30, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->shot_flare, position.x + 15, position.y - 50);
state = EN_ST_WALKING;
}
}
Expand Down
1 change: 1 addition & 0 deletions Blood-bros-0.6/Enemy_indian_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void Enemy_Indian_001::Update()

if (state == EN_ST_SHOOTING && ((animation->current_frame) > (animation->last_frame / 2))){
App->particles->AddParticle(App->particles->enemy_shot, position.x + 40, position.y - 100, COLLIDER_ENEMY_SHOT);
App->particles->AddParticle(App->particles->shot_flare, position.x + 17, position.y - 100);
state = EN_ST_WALKING;
}
}
Expand Down
4 changes: 3 additions & 1 deletion Blood-bros-0.6/ModuleDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ update_status ModuleDebug::Update(){

}

if (App->input->keyboard[SDL_SCANCODE_F6] == KEY_DOWN)
if (App->input->keyboard[SDL_SCANCODE_F6] == KEY_DOWN){
activated_functions[INSTA_WIN_F6] = true;

if (activated_functions[INSTA_WIN_F6] == true){
if (App->player->current_animation != &App->player->victory_dance){
App->player->current_animation->Reset();
App->player->current_animation = &App->player->victory_dance;
App->audio->PlayMusic("Music/victorydance.wav");
}

if (App->player->current_animation->Finished()){
Mix_FadeOutMusic(1000);
App->fade->FadeToBlack((Module*) App->scene_space, (Module*)App->scene_score);
}
}
}

if (App->input->keyboard[SDL_SCANCODE_F7] == KEY_DOWN){
activated_functions[RAMBO_MODE_F7] = !(activated_functions[RAMBO_MODE_F7]);
Expand Down
6 changes: 3 additions & 3 deletions Blood-bros-0.6/ModuleEnemies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ void ModuleEnemies::OnCollision(Collider* c1, Collider* c2)
}
}

void ModuleEnemies::check_explosion(fPoint location){
void ModuleEnemies::check_explosion(int x, int y){

for (uint i = 0; i < MAX_ENEMIES; ++i)
{
if (enemies[i] != nullptr)
{
if ((enemies[i]->position.x > (location.x - 100) && enemies[i]->position.x < (location.x + 60)) &&
(enemies[i]->position.y - 30 > (location.y - 100) && enemies[i]->position.y - 30 < (location.y + 60)))
if ((enemies[i]->position.x + 40 > x && enemies[i]->position.x + 40 < (x + 175)) &&
(enemies[i]->position.y - 40 > y && enemies[i]->position.y - 40 < (y + 175)))
{
if (enemies[i]->state != EN_ST_PROTECTING && enemies[i]->state != EN_ST_DYING ){
enemies[i]->state = EN_ST_DYING;
Expand Down
2 changes: 1 addition & 1 deletion Blood-bros-0.6/ModuleEnemies.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ModuleEnemies : public Module
update_status PostUpdate();
bool CleanUp();
void OnCollision(Collider* c1, Collider* c2);
void check_explosion(fPoint location);
void check_explosion(int x, int y);

bool AddEnemy(ENEMY_TYPES type, int x, int y);

Expand Down
116 changes: 94 additions & 22 deletions Blood-bros-0.6/ModuleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "SDL/include/SDL_timer.h"

#define BASE_ENEMY_SHOT_SPEED 2

ModuleParticles::ModuleParticles()
{
for(uint i = 0; i < MAX_ACTIVE_PARTICLES; ++i)
Expand All @@ -25,25 +23,81 @@ ModuleParticles::ModuleParticles()
enemy_shot.anim.speed = 0.2f;
enemy_shot.life = 10000;

dynamite.anim.PushBack({ 14, 67, 23, 22 });
dynamite.anim.PushBack({ 49, 67, 23, 22 });
dynamite.anim.PushBack({ 14, 67, 23, 22 });
dynamite.anim.PushBack({ 49, 67, 23, 22 });
dynamite.anim.PushBack({ 14, 67, 23, 22 });
dynamite.anim.PushBack({ 49, 67, 23, 22 });
dynamite.anim.PushBack({ 14, 67, 23, 22 });
dynamite.anim.PushBack({ 49, 67, 23, 22 });
enemy_shot_2.anim.PushBack({ 72, 444, 48, 38 });
enemy_shot_2.anim.PushBack({ 121, 445, 48,38});
enemy_shot_2.anim.PushBack({ 164, 444, 48,38});
enemy_shot_2.anim.PushBack({ 222, 444,48,38 });
enemy_shot_2.anim.speed = 0.2f;
enemy_shot_2.life = 10000;

dynamite.anim.PushBack({ 26, 710, 48, 48 });
dynamite.anim.PushBack({ 95, 710, 15, 48 });
dynamite.anim.PushBack({ 131, 719, 45, 15 });
dynamite.anim.PushBack({ 188, 716, 33, 27 });
dynamite.anim.PushBack({ 245, 719, 30, 30 });
dynamite.anim.PushBack({ 299, 719, 12, 33 });
dynamite.anim.PushBack({ 344, 722, 24, 27 });
dynamite.anim.PushBack({ 392, 731, 27, 12 });
dynamite.anim.speed = 0.2f;

dynamite_explosion.anim.PushBack({ 14, 67, 23, 22 });
dynamite_explosion.anim.PushBack({ 49, 67, 23, 22 });
dynamite_explosion.anim.speed = 0.2f;


destroying_wall.anim.PushBack({ 232, 103, 16, 12 });
destroying_wall.anim.PushBack({ 232, 103, 16, 12 });
enemy_bomb.anim.PushBack({ 395, 666, 18, 21 });
enemy_bomb.anim.PushBack({ 349, 666, 15, 24 });
enemy_bomb.anim.PushBack({ 295, 663, 24, 30 });
enemy_bomb.anim.PushBack({ 241, 663, 33, 27 });
enemy_bomb.anim.PushBack({ 190, 663, 33, 27 });
enemy_bomb.anim.PushBack({ 136, 657, 36, 36 });
enemy_bomb.anim.PushBack({ 85, 654, 30, 42 });
enemy_bomb.anim.PushBack({ 34, 651, 36, 48 });
enemy_bomb.anim.speed = 0.225f;

explosion.anim.PushBack({ 7, 785, 108, 116 });
explosion.anim.PushBack({ 146, 804, 154, 154 });
explosion.anim.PushBack({ 305, 804, 154, 154 });
explosion.anim.PushBack({ 466, 804, 154, 154 });
explosion.anim.PushBack({ 637, 804, 154, 154 });
explosion.anim.loop = false;
explosion.anim.speed = 0.2f;

enemy_explosion.anim.PushBack({ 576, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 645, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 709, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 801, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 889, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 978, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 1065, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 1158, 441, 83, 168 });
enemy_explosion.anim.PushBack({ 1236, 441, 83, 168 });
enemy_explosion.anim.loop = false;
enemy_explosion.anim.speed = 0.2f;


destroying_wall.anim.PushBack({ 429, 33, 252, 101 });
destroying_wall.anim.PushBack({ 703, 30, 255, 98 });
destroying_wall.anim.PushBack({ 439, 163, 238, 94 });
destroying_wall.anim.PushBack({ 708, 166, 240, 91 });
destroying_wall.anim.speed = 0.2f;
destroying_wall.anim.loop = false;
destroying_wall.life = 2500;

shot_flare.anim.PushBack({ 408, 1008, 45, 42 });
shot_flare.anim.PushBack({ 461, 1009, 45, 42 });
shot_flare.anim.PushBack({ 513, 1008, 45, 42 });
shot_flare.anim.loop = false;
shot_flare.anim.speed = 0.2f;

big_shot_flare.anim.PushBack({ 86, 1017, 96, 48 });
big_shot_flare.anim.PushBack({ 173, 1006, 96, 48 });
big_shot_flare.anim.PushBack({ 265, 1012, 96, 48 });
big_shot_flare.anim.loop = false;
big_shot_flare.anim.speed = 0.2f;

fire.anim.PushBack({ 1022, 682, 48, 96 });
fire.anim.PushBack({ 1083, 682, 48, 96 });
fire.anim.PushBack({ 959, 682, 48, 96 });
fire.anim.PushBack({ 1141, 682, 48, 96 });
fire.anim.PushBack({ 1198, 682, 48, 96 });
fire.anim.PushBack({ 1265, 682, 48, 96 });
fire.anim.loop;
fire.anim.speed = 0.2f;
}


Expand All @@ -53,6 +107,10 @@ bool ModuleParticles::Start()
graphics = App->textures->Load("sprites/Particles_SpriteSheet.png");

//Load fx
enemy_bomb.fx = App->audio->LoadFx("FX/bomb-trhow.wav");
explosion.fx = App->audio->LoadFx("FX/explosion.wav");
destroying_wall.fx = App->audio->LoadFx("FX/building-collapse.wav");
enemy_explosion.fx = App->audio->LoadFx("FX/explosion.wav");

return true;
}
Expand All @@ -64,6 +122,10 @@ bool ModuleParticles::CleanUp()
App->textures->Unload(graphics);

// Unload fx
App->audio->UnLoadFx(enemy_bomb.fx);
App->audio->UnLoadFx(explosion.fx);
App->audio->UnLoadFx(enemy_explosion.fx);
App->audio->UnLoadFx(destroying_wall.fx);

for(uint i = 0; i < MAX_ACTIVE_PARTICLES; ++i)
{
Expand Down Expand Up @@ -123,7 +185,7 @@ void ModuleParticles::AddParticle(const Particle& particle, int x, int y, COLLID


if (collider_type == COLLIDER_ENEMY_SHOT)
p->speed = p->position.GetDirection(BASE_ENEMY_SHOT_SPEED, App->player->position);
p->speed = p->position.GetDirection(App->player->position);
else if (collider_type == COLLIDER_DYNAMITE)
p->speed = App->player->position.GetSpeed(App->reticle->position);
else if (collider_type == COLLIDER_ENEMY_BOMB)
Expand All @@ -145,6 +207,10 @@ void ModuleParticles::OnCollision(Collider* c1, Collider* c2)
if(active[i] != nullptr && active[i]->collider == c1)
{
if ((c2->type == COLLIDER_PLAYER_SHOT && (App->player->shooting)) || c2->type == COLLIDER_SCENARIO){

if (c1->type == COLLIDER_ENEMY_BOMB)
App->particles->AddParticle(App->particles->enemy_explosion, active[i]->position.x - 40, active[i]->position.y - 168);

delete active[i];
active[i] = nullptr;
break;
Expand Down Expand Up @@ -188,9 +254,15 @@ bool Particle::Update()
if (anim.Finished()){
ret = false;
if (collider != nullptr && (collider->type == COLLIDER_DYNAMITE || collider->type == COLLIDER_ENEMY_BOMB)){
App->particles->AddParticle(App->particles->dynamite_explosion, position.x, position.y);
App->enemies->check_explosion(position);
App->scenario->check_explosion(position);
if (collider->type == COLLIDER_DYNAMITE){
App->particles->AddParticle(App->particles->explosion, position.x - 75, position.y - 75);
App->enemies->check_explosion(position.x - 75, position.y - 75);
App->scenario->check_explosion(position.x - 75, position.y - 75);
}
else if (collider->type == COLLIDER_ENEMY_BOMB){
App->particles->AddParticle(App->particles->enemy_explosion, position.x - 40, position.y - 168);
App->player->check_explosion(position.x - 40, position.y - 168);
}
}

}
Expand Down
7 changes: 6 additions & 1 deletion Blood-bros-0.6/ModuleParticles.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ class ModuleParticles : public Module
public:

Particle enemy_shot;
Particle enemy_shot_2;
Particle destroying_wall;
Particle dynamite;
Particle dynamite_explosion;
Particle shot_flare;
Particle big_shot_flare;
Particle fire;
Particle explosion;
Particle enemy_explosion;
Particle enemy_bomb;

};
Expand Down
20 changes: 19 additions & 1 deletion Blood-bros-0.6/ModulePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,22 @@ void ModulePlayer::GetShootingAngle(uint state){
else if (state == ST_IDLE_SHOOTING)
current_animation = &idle_shooting;

}
}

void ModulePlayer::check_explosion(int x, int y){

if (position.x + 40 > x && position.x + 40 < (x + 83) && position.y - 40 > y && position.y - 40 < (y + 168)){

if (alive && App->fade->IsFading() == false && immune == false && App->debug->activated_functions[GOD_MODE_F2] == false
&& (SDL_GetTicks() - 1000) > invincibility_timer){

App->audio->PlayFx(player_dying_fx);

speed = 0;
current_animation = &killed;

alive = false;
shooting = false;
}
}
}
1 change: 1 addition & 0 deletions Blood-bros-0.6/ModulePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ModulePlayer : public Module
bool CleanUp();
void GetShootingAngle(uint state);
void OnCollision(Collider* c1, Collider* c2);
void check_explosion(int x, int y);

public:

Expand Down
6 changes: 3 additions & 3 deletions Blood-bros-0.6/ModuleScenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ void ModuleScenario::OnCollision(Collider* c1, Collider* c2)
}


void ModuleScenario::check_explosion(fPoint location){
void ModuleScenario::check_explosion(int x, int y){

for (uint i = 0; i < MAX_ELEMENTS; ++i)
{
if (elements[i] != nullptr)
{
if ((elements[i]->position.x >(location.x - 100) && elements[i]->position.x < (location.x + 60)) &&
(elements[i]->position.y - 30 >(location.y - 100) && elements[i]->position.y - 30 < (location.y + 60)))
if ((elements[i]->position.x + 40 > x && elements[i]->position.x + 40 < (x + 175)) &&
(elements[i]->position.y + 40 > y && elements[i]->position.y + 40 < (y + 175)))
{
if (elements[i]->animation != &(elements[i]->dying)){
elements[i]->health -= 1;
Expand Down
2 changes: 1 addition & 1 deletion Blood-bros-0.6/ModuleScenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ModuleScenario : public Module
update_status Update();
bool CleanUp();
void OnCollision(Collider* c1, Collider* c2);
void check_explosion(fPoint location);
void check_explosion(int x, int y);

bool AddElement(SCENARIO_ELEMENTS type, int x, int y);
uint bottle_index;
Expand Down
1 change: 1 addition & 0 deletions Blood-bros-0.6/ModuleSceneSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ update_status ModuleSceneSpace::Update()
{
if (defeated_enemies >= ENEMY_NUM_STG1 && is_backgr_destroyed){
if (App->player->current_animation != &App->player->victory_dance){
App->audio->PlayMusic("Music/victorydance.wav");
App->player->current_animation->Reset();
App->player->current_animation = &App->player->victory_dance;
App->enemies->Disable();
Expand Down
15 changes: 7 additions & 8 deletions Blood-bros-0.6/Scenario_Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@
Scenario_Light::Scenario_Light(int x, int y) : Scenario_elem(x, y)
{

idle.PushBack({ 36, 209, 106, 99 });
idle.PushBack({ 225, 209, 106, 99 });
idle.PushBack({ 37, 208, 106, 98 });
idle.PushBack({ 224, 208, 106, 98 });
idle.speed = 0.1f;

dying.PushBack({ 0, 0, 0, 0 });
dying.PushBack({ 0, 0, 0, 0 });
dying.PushBack({ 0, 0, 0, 0 });
dying.PushBack({ 353, 208, 106, 98 });
dying.PushBack({ 472, 208, 106, 98 });
dying.speed = 0.2f;
dying.loop = false;

anim_displacement_x = ((0 - 0) / 20); // = (greatest sprite size.x - idle sprite size.x) / dying_num_of_frames * 2
anim_displacement_y = ((0 - 0) / 20); // = (greatest sprite size.y - idle sprite size.y) / dying_num_of_frames * 2
anim_displacement_x = 0;
anim_displacement_y = 0;


collider = App->collision->AddCollider({ 0, 0, 106, 99 }, COLLIDER_TYPE::COLLIDER_SCENARIO, (Module*)App->scenario);

orig_pos.x = x;
orig_pos.y = y;

health = 100;
health = 30;

animation = &idle;

Expand Down
Loading

0 comments on commit d792f9b

Please sign in to comment.