Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/knela96/Project1
Browse files Browse the repository at this point in the history
  • Loading branch information
knela96 committed Apr 18, 2018
2 parents a55b1f8 + 7990508 commit ea6624c
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Enemy_PowerupShip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ void Enemy_PowerupShip::Move()

void Enemy_PowerupShip::OnCollision(Collider* collider)
{
App->particles->AddParticle(App->particles->explosion, position.x, position.y);
App->particles->AddParticle(App->particles->Powerup, position.x, position.y);

App->particles->AddParticle(App->particles->Powerup, position.x, position.y,COLLIDER_POWERUP);
}
Binary file added Game/Assets/TileMap1.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Game/Assets/TileMap1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions ModuleCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,42 @@ ModuleCollision::ModuleCollision()
matrix[COLLIDER_WALL][COLLIDER_ENEMY] = true;
matrix[COLLIDER_WALL][COLLIDER_PLAYER_SHOT] = true;
matrix[COLLIDER_WALL][COLLIDER_ENEMY_SHOT] = true;
matrix[COLLIDER_WALL][COLLIDER_POWERUP] = false;

matrix[COLLIDER_PLAYER][COLLIDER_WALL] = true;
matrix[COLLIDER_PLAYER][COLLIDER_PLAYER] = false;
matrix[COLLIDER_PLAYER][COLLIDER_ENEMY] = true;
matrix[COLLIDER_PLAYER][COLLIDER_PLAYER_SHOT] = false;
matrix[COLLIDER_PLAYER][COLLIDER_ENEMY_SHOT] = true;
matrix[COLLIDER_PLAYER][COLLIDER_POWERUP] = true;

matrix[COLLIDER_ENEMY][COLLIDER_WALL] = true;
matrix[COLLIDER_ENEMY][COLLIDER_PLAYER] = true;
matrix[COLLIDER_ENEMY][COLLIDER_ENEMY] = false;
matrix[COLLIDER_ENEMY][COLLIDER_PLAYER_SHOT] = true;
matrix[COLLIDER_ENEMY][COLLIDER_ENEMY_SHOT] = false;
matrix[COLLIDER_ENEMY][COLLIDER_POWERUP] = false;

matrix[COLLIDER_PLAYER_SHOT][COLLIDER_WALL] = true;
matrix[COLLIDER_PLAYER_SHOT][COLLIDER_PLAYER] = false;
matrix[COLLIDER_PLAYER_SHOT][COLLIDER_ENEMY] = true;
matrix[COLLIDER_PLAYER_SHOT][COLLIDER_PLAYER_SHOT] = false;
matrix[COLLIDER_PLAYER_SHOT][COLLIDER_ENEMY_SHOT] = false;
matrix[COLLIDER_PLAYER_SHOT][COLLIDER_POWERUP] = false;

matrix[COLLIDER_ENEMY_SHOT][COLLIDER_WALL] = true;
matrix[COLLIDER_ENEMY_SHOT][COLLIDER_PLAYER] = true;
matrix[COLLIDER_ENEMY_SHOT][COLLIDER_ENEMY] = false;
matrix[COLLIDER_ENEMY_SHOT][COLLIDER_PLAYER_SHOT] = false;
matrix[COLLIDER_ENEMY_SHOT][COLLIDER_ENEMY_SHOT] = false;
matrix[COLLIDER_ENEMY_SHOT][COLLIDER_POWERUP] = false;

matrix[COLLIDER_POWERUP][COLLIDER_WALL] = false;
matrix[COLLIDER_POWERUP][COLLIDER_PLAYER] = true;
matrix[COLLIDER_POWERUP][COLLIDER_ENEMY] = false;
matrix[COLLIDER_POWERUP][COLLIDER_PLAYER_SHOT] = false;
matrix[COLLIDER_POWERUP][COLLIDER_ENEMY_SHOT] = false;
matrix[COLLIDER_POWERUP][COLLIDER_POWERUP] = false;
}

// Destructor
Expand Down Expand Up @@ -133,6 +145,9 @@ void ModuleCollision::DebugDraw()
case COLLIDER_ENEMY_SHOT: // magenta
App->render->DrawQuad(colliders[i]->rect, 0, 255, 255, alpha);
break;
case COLLIDER_POWERUP:
App->render->DrawQuad(colliders[i]->rect, 255, 0, 255, alpha);
break;
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion ModuleCollision.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum COLLIDER_TYPE
COLLIDER_ENEMY,
COLLIDER_PLAYER_SHOT,
COLLIDER_ENEMY_SHOT,
COLLIDER_POWERUP,

COLLIDER_MAX
};
Expand All @@ -29,16 +30,26 @@ struct Collider
type(type),
callback(callback)
{}

COLLIDER_TYPE gettype() { return type; }

void SetPos(int x, int y)
{
rect.x = x;
rect.y = y;
}




bool CheckCollision(const SDL_Rect& r) const;
};

/*
bool operator==(const Collider &o1, const Collider &o2)
{
return o1.gettype() == o2.gettype();
}
*/
class ModuleCollision : public Module
{
public:
Expand Down
41 changes: 37 additions & 4 deletions ModuleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,25 @@ bool ModuleParticles::Start()
shoot1.life = 2000;
shoot1.common_fx = App->audio->LoadS("Assets/Audio Files/SFX in WAV/xmultipl-114.wav");

shoot2.id = 1;

shoot2.anim.PushBack({ 50, 82, 12, 18 });
shoot2.anim.loop = false;
shoot2.anim.speed = 3.0f;
shoot2.life = 2000;
shoot2.common_fx = App->audio->LoadS("Assets/Audio Files/SFX in WAV/xmultipl-114.wav");

animation = &shoot2.anim;

path->PushBack({ 0 , 0 }, 1, &shoot2.anim);
path->PushBack({ 1 , 1 }, 1, &shoot2.anim);
path->PushBack({ 1.41f , 2 }, 1, &shoot2.anim);
path->PushBack({ 1.73f, 3 }, 1, &shoot2.anim);
path->PushBack({ 2, 4 }, 1, &shoot2.anim);
path->PushBack({ 2.24f , 5}, 1, &shoot2.anim);



explosion.anim.PushBack({ 0, 144, 16, 16 });
explosion.anim.PushBack({ 17, 144, 16, 16 });
explosion.anim.PushBack({ 33, 144, 16, 16 });
Expand All @@ -56,7 +69,7 @@ bool ModuleParticles::Start()
explosion_bullet.anim.speed = 0.2f;

Powerup.anim.PushBack({ 0, 120, 16, 16 });
Powerup.anim.loop = false;
Powerup.anim.loop = true;
Powerup.anim.speed = 0.2f;

return ret;
Expand All @@ -71,7 +84,7 @@ bool ModuleParticles::CleanUp()

for (uint i = 0; i < MAX_ACTIVE_PARTICLES; ++i)
{
if (active[i] != nullptr)
if (active[i] != nullptr && active[i] != &Powerup)
{
delete active[i];
active[i] = nullptr;
Expand Down Expand Up @@ -117,6 +130,21 @@ void ModuleParticles::AddParticle(const Particle& particle, int x, int y, COLLID
{
if (active[i] == nullptr)
{
/* if(particle.id != 0){
Particle* p = new Particle(particle);
p->born = SDL_GetTicks() + delay;
p->position.x = x;
p->position.y = y;
p->position = p->position + path->GetCurrentPosition(&animation);
if (collider_type != COLLIDER_NONE)
p->collider = App->collision->AddCollider(p->anim.GetCurrentFrame(), collider_type, this);
active[i] = p;
break;
}else { */
Particle* p = new Particle(particle);
p->born = SDL_GetTicks() + delay;
p->position.x = x;
Expand All @@ -125,9 +153,12 @@ void ModuleParticles::AddParticle(const Particle& particle, int x, int y, COLLID
p->collider = App->collision->AddCollider(p->anim.GetCurrentFrame(), collider_type, this);
active[i] = p;
break;

}
}
}
}
//}


void ModuleParticles::OnCollision(Collider* c1, Collider* c2)
{
Expand All @@ -137,10 +168,12 @@ void ModuleParticles::OnCollision(Collider* c1, Collider* c2)
if (active[i] != nullptr && active[i]->collider == c1)
{
AddParticle(explosion_bullet, c1->rect.x, c1->rect.y, COLLIDER_NONE);

delete active[i];
active[i] = nullptr;
break;
}

}
}

Expand All @@ -160,7 +193,7 @@ Particle::Particle(const Particle& p) :

Particle::~Particle()
{
if (collider != nullptr)
if (collider != nullptr /*&& collider->gettype != COLLIDER_POWERUP*/)
collider->to_delete = true;
}

Expand Down
15 changes: 13 additions & 2 deletions ModuleParticles.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ModuleAudio.h"
#include "ModulePlayer.h"
#include "ModuleCollision.h"
#include "Path.h"

#define MAX_ACTIVE_PARTICLES 100

Expand All @@ -32,13 +33,21 @@ struct Particle {
Uint32 born = 0;
Uint32 life = 0;
bool fx_played = false;
int id = 0;

Particle();
Particle(const Particle& p);
~Particle();
bool Update();

Mix_Chunk* common_fx = nullptr;

bool operator==(const Particle &g) const
{
return this->id == g.id;
}



};

Expand All @@ -55,7 +64,8 @@ class ModuleParticles : public Module
void OnCollision(Collider* c1, Collider* c2);

void AddParticle(const Particle& particle, int x, int y, COLLIDER_TYPE collider_type = COLLIDER_NONE, Uint32 delay = 0);



public:
Uint32 * start_time = 0;
Uint32* shooting_delay;
Expand All @@ -64,7 +74,8 @@ class ModuleParticles : public Module
Particle explosion;
Particle explosion_bullet;
Particle Powerup;

Animation* animation = nullptr;
Path* path = new Path();
private:
SDL_Texture * graphics = nullptr;
Particle * active[MAX_ACTIVE_PARTICLES];
Expand Down
2 changes: 1 addition & 1 deletion ModulePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ update_status ModulePlayer::Update()

if (powerup[PARABOLA_SHOOT] == true) {
App->particles->AddParticle(App->particles->shoot1, position.x + 40, position.y, COLLIDER_PLAYER_SHOT);
App->particles->AddParticle(App->particles->shoot2, position.x + 40, position.y, COLLIDER_PLAYER_SHOT);

}
}

Expand Down
39 changes: 35 additions & 4 deletions ModuleSceneStage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool ModuleSceneStage1::Start()
App->collision->Enable();
App->enemies->Enable();

graphics = App->textures->Load("Assets/TileMap1.png");
graphics = App->textures->Load("Assets/TileMap1.1.png");

back = App->textures->Load("Assets/FirstLvlMap3.png");

Expand All @@ -53,9 +53,40 @@ bool ModuleSceneStage1::Start()
App->audio->PlayMusic(music);

// Colliders ---
App->collision->AddCollider({ 0, 208, 3930, 16 }, COLLIDER_WALL);
App->collision->AddCollider({ 1380, 0, 100, 100 }, COLLIDER_WALL);
App->collision->AddCollider({ 1380, 140, 100, 120 }, COLLIDER_WALL);
App->collision->AddCollider({ 0, 213, 2540, 10 }, COLLIDER_WALL);
App->collision->AddCollider({ 503, 0, 2025, 10 }, COLLIDER_WALL);
App->collision->AddCollider({ 412, 195, 50, 30 }, COLLIDER_WALL);
App->collision->AddCollider({ 422, 184, 19, 12 }, COLLIDER_WALL);
App->collision->AddCollider({ 499, 189, 80, 36 }, COLLIDER_WALL);
App->collision->AddCollider({ 578, 201, 19, 25 }, COLLIDER_WALL);
App->collision->AddCollider({ 642, 1, 66, 24 }, COLLIDER_WALL);
App->collision->AddCollider({ 764, 1, 50, 30 }, COLLIDER_WALL);
App->collision->AddCollider({ 773, 31, 19, 12 }, COLLIDER_WALL);
App->collision->AddCollider({ 1026, 201, 67, 24 }, COLLIDER_WALL);
App->collision->AddCollider({ 1011, 1, 80, 36 }, COLLIDER_WALL);
App->collision->AddCollider({ 1091, 1, 19, 25 }, COLLIDER_WALL);
App->collision->AddCollider({ 1154, 1, 67, 24 }, COLLIDER_WALL);
App->collision->AddCollider({ 1267, 189, 80, 36 }, COLLIDER_WALL);
App->collision->AddCollider({ 1347, 201, 19, 25 }, COLLIDER_WALL);
App->collision->AddCollider({ 1484, 1, 63, 96 }, COLLIDER_WALL);
App->collision->AddCollider({ 1484, 129, 63, 96 }, COLLIDER_WALL);
App->collision->AddCollider({ 1450, 1, 34, 89 }, COLLIDER_WALL);
App->collision->AddCollider({ 1450, 136, 34, 99 }, COLLIDER_WALL);
App->collision->AddCollider({ 1422, 190, 28, 35 }, COLLIDER_WALL);
App->collision->AddCollider({ 1422, 1, 28, 35 }, COLLIDER_WALL);
App->collision->AddCollider({ 1667, 1, 67, 24 }, COLLIDER_WALL);
App->collision->AddCollider({ 1788, 197, 50, 30 }, COLLIDER_WALL);
App->collision->AddCollider({ 1797, 184, 19, 12 }, COLLIDER_WALL);
App->collision->AddCollider({ 2010, 1, 129, 95 }, COLLIDER_WALL);
App->collision->AddCollider({ 2010, 130, 129, 95 }, COLLIDER_WALL);
App->collision->AddCollider({ 2139, 1, 39, 62 }, COLLIDER_WALL);
App->collision->AddCollider({ 2139, 164, 39, 62 }, COLLIDER_WALL);
App->collision->AddCollider({ 2178, 1, 33, 52 }, COLLIDER_WALL);
App->collision->AddCollider({ 2178, 172, 33, 52 }, COLLIDER_WALL);
App->collision->AddCollider({ 2428, 1, 50, 30 }, COLLIDER_WALL);
App->collision->AddCollider({ 2437, 31, 19, 12 }, COLLIDER_WALL);
App->collision->AddCollider({ 2545, 189, 80, 36 }, COLLIDER_WALL);
App->collision->AddCollider({ 2617, 201, 19, 25 }, COLLIDER_WALL);

// Enemies
/*app->enemies->addenemy(brown_worm, 300, 50);
Expand Down

0 comments on commit ea6624c

Please sign in to comment.