Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plataformas/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Actor::Actor(string filename, float x, float y, int width, int height, Game* gam
this->height = height;
}

void Actor::draw(float scrollX) {
void Actor::draw(float scrollX, float scrollY) {
// Recorte en el fichero de la imagen
SDL_Rect source;
source.x = 0;
Expand All @@ -31,7 +31,7 @@ void Actor::draw(float scrollX) {
// Donde se va a pegar en el renderizador
SDL_Rect destination;
destination.x = x - width / 2 - scrollX;
destination.y = y - height / 2;
destination.y = y - height / 2 - scrollY;
destination.w = width;
destination.h = height;
// Modificar para que la referencia sea el punto central
Expand Down
2 changes: 1 addition & 1 deletion plataformas/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Actor
public:
Actor(string filename, float x, float y, int width, int height, Game* game);
~Actor();
virtual void draw(float scrollX = 0);
virtual void draw(float scrollX = 0, float scrollY = 0);
bool isOverlap(Actor* actor);
bool isInRender(float scrollX = 0);
bool containsPoint(int pointX, int pointY); // contiene punto
Expand Down
12 changes: 11 additions & 1 deletion plataformas/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Background::update() {
}
}

void Background::draw(float scrollX) {
void Background::draw(float scrollX, float scrollY) {
Actor::draw(); // llamar al metodo del hijo

if (backgroundAux != NULL) {
Expand All @@ -46,6 +46,16 @@ void Background::draw(float scrollX) {
// pintar aux por la derecha
backgroundAux->x = x + width;
}
// zona sin cubrir por abajo
if (y - height / 2 > 0) {
// pintar aux por abajo
backgroundAux->y = y - height;
}
// zona sin cubrir por arriba
if (y + height / 2 < HEIGHT) {
// pintar aux por arriba
backgroundAux->y = y + height;
}
backgroundAux->draw();
}

Expand Down
2 changes: 1 addition & 1 deletion plataformas/Background.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Background : public Actor
public:
Background(string filename, float x, float y, Game* game);
Background(string filename, float x, float y, float vx, Game* game);
void draw(float scrollX = 0) override; // Va a sobrescribir
void draw(float scrollX = 0, float scrollY = 0) override; // Va a sobrescribir
void update();
Background* backgroundAux = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion plataformas/Debug/plataformas.exe.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\uo276406\Desktop\plataformas\Debug\plataformas.exe</FullPath>
<FullPath>C:\Users\diego\OneDrive\Escritorio\SEV\plataformas\Debug\plataformas.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
Expand Down
Binary file modified plataformas/Debug/plataformas.ilk
Binary file not shown.
127 changes: 28 additions & 99 deletions plataformas/Debug/plataformas.log

Large diffs are not rendered by default.

Binary file modified plataformas/Debug/plataformas.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified plataformas/Debug/plataformas.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified plataformas/Debug/plataformas.tlog/CL.write.1.tlog
Binary file not shown.
Binary file modified plataformas/Debug/plataformas.tlog/link.command.1.tlog
Binary file not shown.
Binary file modified plataformas/Debug/plataformas.tlog/link.read.1.tlog
Binary file not shown.
Binary file modified plataformas/Debug/plataformas.tlog/link.write.1.tlog
Binary file not shown.
4 changes: 2 additions & 2 deletions plataformas/Debug/plataformas.tlog/plataformas.lastbuildstate
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30037:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\uo276406\Desktop\plataformas\|
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.18362.0:
Debug|Win32|C:\Users\diego\OneDrive\Escritorio\SEV\plataformas\|
Binary file modified plataformas/Debug/vc142.idb
Binary file not shown.
Binary file modified plataformas/Debug/vc142.pdb
Binary file not shown.
6 changes: 4 additions & 2 deletions plataformas/Enemy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Actor.h"
#include "Enemy.h"


Enemy::Enemy(float x, float y, Game* game)
: Actor("res/enemigo.png", x, y, 36, 40, game) {

Expand Down Expand Up @@ -61,8 +63,8 @@ void Enemy::impacted() {
}


void Enemy::draw(float scrollX) {
animation->draw(x - scrollX, y);
void Enemy::draw(float scrollX, float scrollY) {
animation->draw(x - scrollX, y-scrollY);
}


3 changes: 2 additions & 1 deletion plataformas/Enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Enemy : public Actor
{
public:
Enemy(float x, float y, Game* game);
void draw(float scrollX = 0) override; // Va a sobrescribir

void draw(float scrollX = 0, float scrollY = 0) override; // Va a sobrescribir
void update();
void impacted(); // Recibe impacto y pone animaci�n de morir
float vxIntelligence;
Expand Down
140 changes: 131 additions & 9 deletions plataformas/GameLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void GameLayer::init() {

space = new Space(1);
scrollX = 0;
scrollY = 0;
tiles.clear();

audioBackground = new Audio("res/musica_ambiente.mp3", true);
Expand All @@ -24,13 +25,20 @@ void GameLayer::init() {
textPoints = new Text("hola", WIDTH * 0.92, HEIGHT * 0.04, game);
textPoints->content = to_string(points);


pointsRecolectable = 0;
textPointsRecolectable = new Text("hola", WIDTH * 0.92, HEIGHT * 0.14, game);
textPointsRecolectable->content = to_string(pointsRecolectable);

background = new Background("res/fondo_2.png", WIDTH * 0.5, HEIGHT * 0.5, -1, game);
backgroundPoints = new Actor("res/icono_puntos.png",
WIDTH * 0.85, HEIGHT * 0.05, 24, 24, game);

recolectable = new Item(WIDTH * 0.85, HEIGHT * 0.15, game);

enemies.clear(); // Vaciar por si reiniciamos el juego
recolectables.clear();
projectiles.clear(); // Vaciar por si reiniciamos el juego
destructibles.clear();

loadMap("res/" + to_string(game->currentLevel) + ".txt");
}
Expand Down Expand Up @@ -73,6 +81,22 @@ void GameLayer::loadMapObject(char character, float x, float y)
space->addDynamicActor(cup); // Realmente no hace falta
break;
}
case 'R': {
Tile* recolectable = new Tile("res/icono_recolectable.png", x, y, game);
// modificaci�n para empezar a contar desde el suelo.
recolectable->y = recolectable->y - recolectable->height / 2;
recolectables.push_back(recolectable);
space->addDynamicActor(recolectable);
break;
}
case 'W': {
Tile* destructible = new Tile("res/bloque_metal.png", x, y, game);
// modificaci�n para empezar a contar desde el suelo.
destructible->y = destructible->y - destructible->height / 2;
destructibles.push_back(destructible);
space->addStaticActor(destructible);
break;
}
case 'E': {
Enemy* enemy = new Enemy(x, y, game);
// modificaci�n para empezar a contar desde el suelo.
Expand Down Expand Up @@ -245,18 +269,18 @@ void GameLayer::update() {
}


// Colisiones
for (auto const& enemy : enemies) {

if (player->isOverlap(enemy)) {
player->loseLife();
player->loseLife();

if (player->lifes <= 0) {
init();
return;
}
}
}

// Colisiones , Enemy - Projectile

list<Enemy*> deleteEnemies;
list<Projectile*> deleteProjectiles;
Expand All @@ -273,7 +297,33 @@ void GameLayer::update() {
}
}

//Colisiones, Player - Recolectable
list<Tile*> deleteRecolectables;
for (auto const& recolectable : recolectables) {
if (player->isOverlap(recolectable)) {
bool rInList = std::find(deleteRecolectables.begin(),
deleteRecolectables.end(),
recolectable) != deleteRecolectables.end();

if (!rInList) {
deleteRecolectables.push_back(recolectable);
}


pointsRecolectable++;
if (pointsRecolectable % 4 == 0) {
textPointsRecolectable->content = to_string(pointsRecolectable/4);
this->recolectable->idle->currentFrame = 2;
}

this->recolectable->update();

}

}

// Colisiones , Enemy - Projectile
// Player(saltando) - enemy

for (auto const& enemy : enemies) {
for (auto const& projectile : projectiles) {
Expand All @@ -294,8 +344,43 @@ void GameLayer::update() {

}
}
if (player->vy > 0 && player->y < enemy->y
&& player->isOverlap(enemy)
&& player->lifes > 0) {

enemy->impacted();
player->lifes++;
player->invulnerableTime = 0;
points++;
textPoints->content = to_string(points);
}
}

//Tiles destructibles
list<Tile*> deleteDestructibles;
for (auto const& destructible : destructibles) {

if ((player->y - destructible->y) < 10 &&
abs(player->x - destructible->x) < 10 &&
destructionTime % 10 == 0) {

space->addDynamicActor(destructible);
space->removeStaticActor(destructible);

bool dInList = std::find(deleteDestructibles.begin(),
deleteDestructibles.end(),
destructible) != deleteDestructibles.end();

if (!dInList) {
deleteDestructibles.push_back(destructible);
}

destructionTime = 10;
}
}

destructionTime--;

for (auto const& enemy : enemies) {
if (enemy->state == game->stateDead) {
bool eInList = std::find(deleteEnemies.begin(),
Expand All @@ -308,6 +393,18 @@ void GameLayer::update() {
}
}

for (auto const& delRecolectable : deleteRecolectables) {
recolectables.remove(delRecolectable);
space->removeDynamicActor(delRecolectable);
}
deleteRecolectables.clear();

for (auto const& delDestructible : deleteDestructibles) {
destructibles.remove(delDestructible);
space->removeDynamicActor(delDestructible);
}
deleteDestructibles.clear();

for (auto const& delEnemy : deleteEnemies) {
enemies.remove(delEnemy);
space->removeDynamicActor(delEnemy);
Expand Down Expand Up @@ -339,6 +436,20 @@ void GameLayer::calculateScroll() {
scrollX = player->x - WIDTH * 0.7;
}
}

// limite abajo
if (player->y > HEIGHT * 0.3) {
if (player->y - scrollY < HEIGHT * 0.3) {
scrollY = player->y - HEIGHT * 0.3;
}
}

// limite arriba
if (player->y < mapWidth - HEIGHT * 0.3) {
if (player->y - scrollY > HEIGHT * 0.7) {
scrollY = player->y - HEIGHT * 0.7;
}
}
}


Expand All @@ -347,23 +458,34 @@ void GameLayer::draw() {

background->draw();
for (auto const& tile : tiles) {
tile->draw(scrollX);
tile->draw(scrollX, scrollY);
}

for (auto const& recolectable : recolectables) {
recolectable->draw(scrollX, scrollY);
}

for (auto const& destructible : destructibles) {
destructible->draw(scrollX, scrollY);
}

for (auto const& projectile : projectiles) {
projectile->draw(scrollX);
projectile->draw(scrollX, scrollY);
}

cup->draw(scrollX);
player->draw(scrollX);
cup->draw(scrollX, scrollY);
player->draw(scrollX, scrollY);

for (auto const& enemy : enemies) {
enemy->draw(scrollX);
enemy->draw(scrollX, scrollY);
}

backgroundPoints->draw();
textPoints->draw();

textPointsRecolectable->draw();
recolectable->draw();

// HUD
if (game->input == game->inputMouse) {
buttonJump->draw(); // NO TIENEN SCROLL, POSICION FIJA
Expand Down
13 changes: 12 additions & 1 deletion plataformas/GameLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Audio.h"
#include "Space.h" // importar
#include "Item.h"

#include "Pad.h"

Expand All @@ -35,17 +36,27 @@ class GameLayer : public Layer
void calculateScroll();
Space* space;
float scrollX;
float scrollY;
int mapWidth;
list<Tile*> tiles;

list<Tile*> destructibles;
int destructionTime = 9;

Audio* audioBackground;
Text* textPoints;
int points;

Text* textPointsRecolectable;
int pointsRecolectable;
Item* recolectable;

int newEnemyTime = 0;
Player* player;
Background* background;
Actor* backgroundPoints;
list<Enemy*> enemies;
list<Tile*> recolectables;
list<Projectile*> projectiles;
Tile* cup; // Elemento de final de nivel

Expand All @@ -56,7 +67,7 @@ class GameLayer : public Layer
// Elementos de interfaz
Actor* buttonJump;
Actor* buttonShoot;
Pad* pad;
Pad* pad;

};

1 change: 1 addition & 0 deletions plataformas/GenericEnemy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "GenericEnemy.h"
13 changes: 13 additions & 0 deletions plataformas/GenericEnemy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "Actor.h"
class GenericEnemy :
public Actor
{

void virtual draw() = 0; // Va a sobrescribir
void virtual update() = 0;

GenericEnemy(string filename, float x, float y, int width, int height, Game* game);

};

Loading