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
Rafefix committed Apr 18, 2018
2 parents 87d86bd + ea6624c commit 9a6877f
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 57 deletions.
3 changes: 3 additions & 0 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ModuleSceneStage2.h"
#include "ModuleSceneCongrats.h"
#include "ModuleCollision.h"
#include "ModuleTentacles.h"
#include "ModuleFonts.h"

Application::Application()
Expand All @@ -30,6 +31,7 @@ Application::Application()
modules[i++] = scene_stage1 = new ModuleSceneStage1();
modules[i++] = scene_stage2 = new ModuleSceneStage2();
modules[i++] = scene_congrats = new ModuleSceneCongrats();
modules[i++] = tentacles = new ModuleTentacles();
modules[i++] = player = new ModulePlayer();
modules[i++] = enemies = new ModuleEnemies();
modules[i++] = particles = new ModuleParticles();
Expand Down Expand Up @@ -58,6 +60,7 @@ bool Application::Init()
scene_congrats->Disable();


tentacles->Disable();
player->Disable();
enemies->Disable();

Expand Down
4 changes: 3 additions & 1 deletion Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Globals.h"

#define NUM_MODULES 16
#define NUM_MODULES 17

class Module;
class ModuleWindow;
Expand All @@ -22,6 +22,7 @@ class ModuleSceneStage1;
class ModuleSceneStage2;
class ModuleSceneCongrats;
class ModuleCollision;
class ModuleTentacles;

class Application
{
Expand All @@ -44,6 +45,7 @@ class Application
ModuleSceneStage2* scene_stage2 = nullptr;
ModuleSceneCongrats* scene_congrats = nullptr;
ModuleCollision* collision = nullptr;
ModuleTentacles* tentacles = nullptr;

public:

Expand Down
2 changes: 1 addition & 1 deletion Enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ void Enemy::Draw(SDL_Texture* sprites)
void Enemy::OnCollision(Collider* collider)
{
App->particles->AddParticle(App->particles->explosion, position.x, position.y);
App->player->score += 1;
App->player->score += 13;

}
2 changes: 1 addition & 1 deletion ModuleAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Mix_Chunk *const ModuleAudio::LoadS(const char* path)
bool ModuleAudio::UnloadS(Mix_Chunk * sound)
{
if (sound != nullptr)
Mix_FreeChunk(sound);
//Mix_FreeChunk(sound);
return true;
}

Expand Down
25 changes: 22 additions & 3 deletions ModulePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ModuleCollision.h"
#include "ModuleFadeToBlack.h"
#include "ModuleFonts.h"
#include "Tentacles.h"
#include "ModuleTentacles.h"

#include<stdio.h>

Expand Down Expand Up @@ -55,6 +55,9 @@ ModulePlayer::ModulePlayer()
downwardreturn.speed = 0.075f;

current_animation = &idle;



}

ModulePlayer::~ModulePlayer()
Expand All @@ -76,9 +79,24 @@ bool ModulePlayer::Start()
powerup[BASIC_SHOOT] = true;
powerup[PARABOLA_SHOOT] = true;


font_score = App->font->Load("Assets/fonts.1.png", "0123456789í.-=éè()óòáú`´!?abcdefghijklmnopqrstuvwxyz", 2);


App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, false);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);
App->tentacles->AddTentacle(App->tentacles->tentacle, position.x, position.y, true);



return ret;
}

Expand Down Expand Up @@ -132,14 +150,15 @@ update_status ModulePlayer::Update()
App->particles->AddParticle(App->particles->shoot1, position.x + 40, position.y, COLLIDER_PLAYER_SHOT);
//score += 13;
}

}

if (App->input->keyboard[SDL_SCANCODE_S] == KEY_STATE::KEY_IDLE
&& App->input->keyboard[SDL_SCANCODE_W] == KEY_STATE::KEY_IDLE && (downwardreturn.islastframe() && upwardreturn.islastframe()))
current_animation = &idle;

collider->SetPos(position.x, position.y);


// Draw everything --------------------------------------
if (!dead)
App->render->Blit(graphics, position.x, position.y, &current_animation->GetCurrentFrame());
Expand Down
6 changes: 3 additions & 3 deletions ModuleRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool ModuleRender::CleanUp()
// return ret;
//}

bool ModuleRender::Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, float speed, bool use_camera, bool flip_horizontal)
bool ModuleRender::Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, float speed, float angle , bool use_camera, bool flip_horizontal)
{
bool ret = true;
SDL_Rect rect;
Expand Down Expand Up @@ -151,9 +151,9 @@ bool ModuleRender::Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, f
int result = 0;

if (flip_horizontal == true)
result = SDL_RenderCopyEx(renderer, texture, section, &rect, 0.0, NULL, SDL_FLIP_HORIZONTAL);
result = SDL_RenderCopyEx(renderer, texture, section, &rect, angle, NULL, SDL_FLIP_HORIZONTAL);
else
result = SDL_RenderCopy(renderer, texture, section, &rect);
result = SDL_RenderCopyEx(renderer, texture, section, &rect, angle, NULL, SDL_FLIP_NONE);

if (result != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion ModuleRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ModuleRender : public Module
update_status PreUpdate();
bool CleanUp();

bool Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, float speed = 1.0f, bool use_camera = true, bool flip_horizontal = false);
bool Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, float speed = 1.0f, float angle = 0.0f, bool use_camera = true, bool flip_horizontal = false);
bool DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera = true);

public:
Expand Down
4 changes: 3 additions & 1 deletion ModuleSceneStage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "ModuleAudio.h"
#include "ModuleCollision.h"
#include "ModuleFonts.h"
#include "ModuleTentacles.h"


ModuleSceneStage1::ModuleSceneStage1()
{
Expand All @@ -38,7 +40,7 @@ bool ModuleSceneStage1::Start()

bool ret = true;


App->tentacles->Enable();
App->player->Enable();
App->particles->Enable();
App->collision->Enable();
Expand Down
139 changes: 139 additions & 0 deletions ModuleTentacles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "Application.h"
#include "ModuleRender.h"
#include "ModuleTextures.h"
#include "ModuleTentacles.h"
#include "ModulePlayer.h"

ModuleTentacles::ModuleTentacles()
{}

ModuleTentacles::~ModuleTentacles()
{}

bool ModuleTentacles::Start() {

LOG("Loading tentacle textures");

graphics = App->textures->Load("Assets/Player.png");
tentacle.anim.PushBack({ 6, 19, 4, 11 });
tentacle.anim.loop = false;
tentacle.anim.speed = 0.0f;
/*
tentacle.anim->PushBack({ 17,0,16,16 });
tentacle.anim->PushBack({ 33,0,16,16 });
tentacle.anim->PushBack({ 49,0,16,16 });
tentacle.anim->PushBack({ 65,0,16,16 });*/
return true;
}

bool ModuleTentacles::CleanUp()
{
LOG("Unloading particles");
App->textures->Unload(graphics);

for (uint i = 0; i < MAX_TENTACLES; ++i)
{
if (tentacles[i] != nullptr)
{
delete tentacles[i];
tentacles[i] = nullptr;
}
}

return true;
}

update_status ModuleTentacles::Update() {
for (uint i = 0; i < MAX_TENTACLES; ++i)
{
Tentacle* p = tentacles[i];

if (p == nullptr)
continue;

if (p->Update() == false)
{
delete p;
tentacles[i] = nullptr;
}else{
setPosition(App->player->position.x, App->player->position.y);
if(!p->flip)
App->render->Blit(graphics, p->first_point.x, p->first_point.y, &p->anim.GetCurrentFrame(),1.0f, 0.0f);
else
App->render->Blit(graphics, p->first_point.x, p->first_point.y, &p->anim.GetCurrentFrame(), 1.0f, 180.0f);

}
}
return UPDATE_CONTINUE;
}

void ModuleTentacles::AddTentacle(const Tentacle& tentacle, int x, int y, bool flip)
{
for (uint i = 0; i < MAX_TENTACLES; ++i)
{
if (tentacles[i] == nullptr)
{
Tentacle* p = new Tentacle(tentacle);
p->flip = flip;
tentacles[i] = p;
break;
}
}
}

void ModuleTentacles::setPosition(int x, int y) {
for (uint i = 0; i < MAX_TENTACLES; ++i)
{
if (tentacles[i] != nullptr)
{
int invert = 0;
Tentacle* p = tentacles[i];
if (tentacles[i]->flip)
invert = -1;
else
invert = 1;

if (i != 0 && i != MAX_TENTACLES/2) {
p->first_point.x = tentacles[i - 1]->second_point.x;
p->first_point.y = tentacles[i - 1]->second_point.y;
p->second_point.x = p->first_point.x;
p->second_point.y = p->first_point.y - p->anim.GetCurrentFrame().h * invert;
}
else {
if (tentacles[i]->flip) {
p->first_point.y = y + 9;
}
else {
p->first_point.y = y - 4;
}
p->first_point.x = x + 20;

p->second_point.x = p->first_point.x;
p->second_point.y = p->first_point.y - p->anim.GetCurrentFrame().h * invert;
}
tentacles[i] = p;
}
}
}


//--------------------------------------------
//--------------------------------------------

Tentacle::Tentacle()
{
first_point.SetToZero();
}

Tentacle::Tentacle(const Tentacle& p) :
first_point(p.first_point), second_point(p.second_point),
anchor(p.anchor), anim(p.anim)
{}

bool Tentacle::Update()
{
bool ret = true;


return ret;
}
45 changes: 45 additions & 0 deletions ModuleTentacles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef __MODULETENTACLES_H__
#define __MODULETENTACLES_H__

#include "p2Point.h"
#include "Animation.h"
#include "ModuleCollision.h"

#define MAX_TENTACLES 12

struct SDL_Texture;
struct SDL_Rect;
struct Collider;

struct Tentacle {
Collider* collider = nullptr;
iPoint first_point;
iPoint second_point;
bool anchor = false;
Animation anim;
bool flip = false;

Tentacle();
Tentacle(const Tentacle& p);
bool Update();
};


class ModuleTentacles : public Module
{
public:
Tentacle tentacle;
Tentacle* tentacles[MAX_TENTACLES];
private:
SDL_Texture * graphics = nullptr;
public:
ModuleTentacles();
~ModuleTentacles();
bool Start();
update_status Update();
bool CleanUp();
void AddTentacle(const Tentacle& tentacle, int x, int y,bool flip);
void setPosition(int x, int y);
};

#endif // __ENEMY_H__
16 changes: 0 additions & 16 deletions Tentacles.cpp

This file was deleted.

Loading

0 comments on commit 9a6877f

Please sign in to comment.