Ya coge los diamantes, aunque no los recuerda

This commit is contained in:
2022-08-27 14:15:46 +02:00
parent 2e102160e6
commit 58b238fa45
25 changed files with 173 additions and 22 deletions
+10
View File
@@ -0,0 +1,10 @@
frames_per_row=8
frame_width=16
frame_height=16
[animation]
name=default
speed=8
loop=0
frames=0,1,2,3,4,5,6,7
[/animation]
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 B

After

Width:  |  Height:  |  Size: 251 B

+30 -3
View File
@@ -33,14 +33,41 @@ tileset=moving_platform.png
animation=moving_platform.ani animation=moving_platform.ani
width=16 width=16
height=8 height=8
x=19 x=20
y=14 y=14
vx=0 vx=0
vy=0.3 vy=0.3
x1=19 x1=20
y1=14 y1=14
x2=19 x2=20
y2=21 y2=21
[/moving platform] [/moving platform]
[diamond]
tileset=diamond.png
animation=diamond.ani
width=16
height=16
x=1
y=10
[/diamond]
[diamond]
tileset=diamond.png
animation=diamond.ani
width=16
height=16
x=24
y=10
[/diamond]
[diamond]
tileset=diamond.png
animation=diamond.ani
width=16
height=16
x=25
y=12
[/diamond]
[/actors] [/actors]
+9 -9
View File
@@ -14,19 +14,19 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,51,52,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,51,52,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,159,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,159,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,191,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 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0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,239,240,0,0,0,0,0,0,615,616,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,239,240,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,257,258,257,258,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,366,367,367,368,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,289,290,289,290,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,430,431,431,432,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,615,616,69,70,0,0,0,93,94,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,615,616,69,70,0,0,0,93,94,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0,
263,264,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,0,0,0,0,281,282,277,278,279,274,280,0,0,0,157,158,0,0,0,0,0,0, 363,364,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,0,0,0,0,362,282,277,278,279,274,364,0,0,0,157,158,0,0,0,0,0,0,
295,296,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,281,275,275,275,275,313,314,309,310,311,312,304,0,0,0,189,190,0,0,0,0,0,0, 295,396,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,362,275,275,275,275,313,314,309,310,311,312,396,0,0,0,189,190,0,0,0,0,0,0,
265,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,266,266,266,283,284,266,265,266,264,263,264,263,264,263,264,263,264,263,264,263,264, 265,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,266,266,266,283,284,266,265,266,264,263,264,263,264,263,264,263,264,263,264,263,264,
295,296,295,296,295,296,295,296,295,265,295,296,295,296,295,296,295,296,295,296,295,296,315,316,298,297,298,296,295,296,295,296,295,296,295,296,295,296,295,296 295,296,295,296,295,296,295,296,295,265,295,296,295,296,295,296,295,296,295,296,295,296,315,316,298,297,298,296,295,296,295,296,295,296,295,296,295,296,295,296
</data> </data>
+2 -2
View File
@@ -27,8 +27,8 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,264,264,264,264,264,0,0,0,0,264,264,264,264,264,264,264,264,264,264, 363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,364,0,0,0,0,362,363,363,363,363,363,363,363,363,363,
295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,296,296,296,296,296,0,0,0,0,296,296,296,296,296,296,296,296,296,296 295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,296,296,296,296,396,0,0,0,0,394,296,296,296,296,296,296,296,296,296
</data> </data>
</layer> </layer>
</map> </map>
+2 -2
View File
@@ -3,14 +3,14 @@
<tileset firstgid="1" source="surface.tsx"/> <tileset firstgid="1" source="surface.tsx"/>
<layer id="1" name="Capa de patrones 1" width="40" height="26"> <layer id="1" name="Capa de patrones 1" width="40" height="26">
<data encoding="csv"> <data encoding="csv">
265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,0,0,0,0,265,265,265,265,265,265,265,265,265,265, 265,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,428,0,0,0,0,426,427,427,427,427,427,427,427,427,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,257,257,257,257,258,257,258,258,258,257,257,257,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,369,370,370,370,370,370,370,370,370,370,370,371,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265, 265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,265,
Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

+4
View File
@@ -0,0 +1,4 @@
[ViewState]
Mode=
Vid=
FolderType=Generic
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
#include "actor_diamond.h"
#include <fstream>
#include <sstream>
// Constructor
ActorDiamond::ActorDiamond(actor_t actor) : Actor(actor)
{
}
// Destructor
ActorDiamond::~ActorDiamond()
{
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <SDL2/SDL.h>
#include "actor.h"
#include <string>
#ifndef ACTOR_DIAMOND_H
#define ACTOR_DIAMOND_H
// Clase Actor
class ActorDiamond : public Actor
{
private:
public:
// Constructor
ActorDiamond(actor_t actor);
// Destructor
~ActorDiamond();
};
#endif
+3
View File
@@ -193,6 +193,9 @@ void Game::renderDebugInfo()
text = "hookedOn = " + std::to_string(player->hookedOnMovingPlatform); text = "hookedOn = " + std::to_string(player->hookedOnMovingPlatform);
debugText->write(0, line += 6, text, -1); debugText->write(0, line += 6, text, -1);
text = "DIAMONDS = " + std::to_string(player->diamonds);
debugText->write(0, line += 6, text, -1);
// Pinta mascaras // Pinta mascaras
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 128); SDL_SetRenderDrawColor(renderer, 0, 255, 0, 128);
+46 -2
View File
@@ -135,10 +135,40 @@ bool Map::load(std::string file_path)
} while (line != "[/moving platform]"); } while (line != "[/moving platform]");
printf("actor loaded\n"); printf("** actor moving platform loaded\n");
actors.push_back(new ActorMovingPlatform(actor, p1, p2)); actors.push_back(new ActorMovingPlatform(actor, p1, p2));
} }
if (line == "[diamond]")
{
actor_t actor;
actor.asset = asset;
actor.renderer = renderer;
actor.name = a_diamond;
actor.vx = 0.0f;
actor.vy = 0.0f;
SDL_Point p1, p2;
do
{
std::getline(file, line);
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setActor(&actor, &p1, &p2, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
success = false;
}
} while (line != "[/diamond]");
printf("** actor diamond loaded\n");
actors.push_back(new ActorDiamond(actor));
}
} while (line != "[/actors]"); } while (line != "[/actors]");
/*actor_t actor; /*actor_t actor;
actor.asset = asset; actor.asset = asset;
@@ -305,7 +335,7 @@ bool Map::setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var
{ {
p2->y = std::stoi(value) * tile_size; p2->y = std::stoi(value) * tile_size;
} }
else if (var == "[/moving platform]") else if ((var == "[/moving platform]") || (var == "[/diamond]"))
{ {
} }
else else
@@ -554,4 +584,18 @@ int Map::getActorIncX(int index)
} }
return shift; return shift;
}
// Elimina un actor
bool Map::deleteActor(int index)
{
bool success = false;
if (actors[index] != nullptr)
{
delete actors[index];
success = true;
}
actors.erase(actors.begin() + index);
return success;
} }
+4
View File
@@ -5,6 +5,7 @@
#include "asset.h" #include "asset.h"
#include "const.h" #include "const.h"
#include "actor_moving_platform.h" #include "actor_moving_platform.h"
#include "actor_diamond.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
@@ -106,6 +107,9 @@ public:
// Devuelve el desplazamiento relativo del actor // Devuelve el desplazamiento relativo del actor
int getActorIncX(int index); int getActorIncX(int index);
// Elimina un actor
bool deleteActor(int index);
}; };
#endif #endif
+19 -1
View File
@@ -41,6 +41,7 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map)
collider.insert(collider.end(), {p, p, p, p, p, p, p, p, p, p, p, p}); collider.insert(collider.end(), {p, p, p, p, p, p, p, p, p, p, p, p});
underFeet.insert(underFeet.end(), {p, p, p}); underFeet.insert(underFeet.end(), {p, p, p});
hookedOnMovingPlatform = -1; hookedOnMovingPlatform = -1;
diamonds = 0;
} }
// Destructor // Destructor
@@ -106,6 +107,7 @@ void Player::checkInput()
vy -= jumpStrenght; vy -= jumpStrenght;
state = jumping; state = jumping;
jumpPressed = true; jumpPressed = true;
JA_PlaySound(sound_jump);
} }
} }
else if (state == jumping) else if (state == jumping)
@@ -356,6 +358,12 @@ bool Player::isOnMovingPlatform()
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform); onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
hookedOnMovingPlatform = std::max(hookedOnMovingPlatform, (map->actorCollision(f))); hookedOnMovingPlatform = std::max(hookedOnMovingPlatform, (map->actorCollision(f)));
} }
if (!onMovingPlatform)
{
hookedOnMovingPlatform = -1;
}
return onMovingPlatform; return onMovingPlatform;
} }
@@ -433,5 +441,15 @@ void Player::setMap(Map *map)
int Player::checkActors() int Player::checkActors()
{ {
SDL_Rect rect = sprite->getRect(); SDL_Rect rect = sprite->getRect();
return map->actorCollision(rect); const int index = map->actorCollision(rect);
const int name = map->getActorName(index);
if (name == a_diamond)
{
diamonds++;
JA_PlaySound(sound_coin);
map->deleteActor(index);
}
return index;
} }
+1
View File
@@ -49,6 +49,7 @@ public:
float maxVX; // Velocidad mazima de desplazamiento horizontal float maxVX; // Velocidad mazima de desplazamiento horizontal
float maxVY; // Velocidad mazima de desplazamiento vertical float maxVY; // Velocidad mazima de desplazamiento vertical
int diamonds; // Cantidad de diamantes recogidos por el jugador
std::vector<bool> key; // Indica las llaves que posee el jugador std::vector<bool> key; // Indica las llaves que posee el jugador
std::vector<SDL_Point> collider; // Contiene los puntos de colisión del jugador con el mapa std::vector<SDL_Point> collider; // Contiene los puntos de colisión del jugador con el mapa
std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
+2
View File
@@ -190,6 +190,8 @@ bool Prog::setFileList()
// Ficheros de actores // Ficheros de actores
asset->add("/data/actors/moving_platform.png", bitmap); asset->add("/data/actors/moving_platform.png", bitmap);
asset->add("/data/actors/moving_platform.ani", data); asset->add("/data/actors/moving_platform.ani", data);
asset->add("/data/actors/items/diamond.png", bitmap);
asset->add("/data/actors/items/diamond.ani", data);
// Ficheros del logo // Ficheros del logo
asset->add("/data/logo/logo.png", bitmap); asset->add("/data/logo/logo.png", bitmap);
+3 -3
View File
@@ -57,9 +57,9 @@ void Text::init()
offset[i].y = ((i - 32) / 15) * boxHeight; offset[i].y = ((i - 32) / 15) * boxHeight;
} }
printf("Cargando %s\n", file.c_str()); //printf("Cargando %s\n", file.c_str());
const std::string texto = "w = "+ std::to_string(boxWidth) + ", h = " + std::to_string(boxHeight); //const std::string texto = "w = "+ std::to_string(boxWidth) + ", h = " + std::to_string(boxHeight);
printf("%s\n",texto.c_str()); //printf("%s\n",texto.c_str());
} }
// Escribe texto en pantalla // Escribe texto en pantalla