Skip to content

Commit

Permalink
tentacles moving with the player
Browse files Browse the repository at this point in the history
  • Loading branch information
knela96 committed Apr 18, 2018
1 parent 91c8a6b commit a55b1f8
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 64 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 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
21 changes: 19 additions & 2 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 "SDL/include/SDL.h"

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

current_animation = &idle;



}

ModulePlayer::~ModulePlayer()
Expand All @@ -75,6 +78,19 @@ bool ModulePlayer::Start()
powerup[PARABOLA_SHOOT] = true;


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 @@ -128,14 +144,15 @@ update_status ModulePlayer::Update()
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);
}

}

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
21 changes: 11 additions & 10 deletions ModuleSceneStage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ModuleParticles.h"
#include "ModuleAudio.h"
#include "ModuleCollision.h"
#include "ModuleTentacles.h"

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

bool ret = true;


App->tentacles->Enable();
App->player->Enable();
App->particles->Enable();
App->collision->Enable();
Expand All @@ -57,15 +58,15 @@ bool ModuleSceneStage1::Start()
App->collision->AddCollider({ 1380, 140, 100, 120 }, COLLIDER_WALL);

// Enemies
App->enemies->AddEnemy(BROWN_WORM, 300, 50);
App->enemies->AddEnemy(BROWN_WORM, 300, 100);
App->enemies->AddEnemy(BROWN_WORM, 300, 150);
App->enemies->AddEnemy(BROWN_WORM, 300, 200);
App->enemies->AddEnemy(LITTLE_SHRIMP, 400, 200);
App->enemies->AddEnemy(LITTLE_SHRIMP, 415, 200);
App->enemies->AddEnemy(LITTLE_SHRIMP, 440, 200);
App->enemies->AddEnemy(LITTLE_SHRIMP, 465, 200);
App->enemies->AddEnemy(NEMONA_TENTACLE, 520, 148);
/*app->enemies->addenemy(brown_worm, 300, 50);
app->enemies->addenemy(brown_worm, 300, 100);
app->enemies->addenemy(brown_worm, 300, 150);
app->enemies->addenemy(brown_worm, 300, 200);
app->enemies->addenemy(little_shrimp, 400, 200);
app->enemies->addenemy(little_shrimp, 415, 200);
app->enemies->addenemy(little_shrimp, 440, 200);
app->enemies->addenemy(little_shrimp, 465, 200);
app->enemies->addenemy(nemona_tentacle, 520, 148);*/

//POWERUPS
App->enemies->AddEnemy(POWERUPSHIP, 400, 150);
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 a55b1f8

Please sign in to comment.