Trabajando en las colisiones con plataformas moviles
This commit is contained in:
@@ -28,4 +28,19 @@ x2=15
|
|||||||
y2=11
|
y2=11
|
||||||
[/moving platform]
|
[/moving platform]
|
||||||
|
|
||||||
|
[moving platform]
|
||||||
|
tileset=moving_platform.png
|
||||||
|
animation=moving_platform.ani
|
||||||
|
width=16
|
||||||
|
height=8
|
||||||
|
x=19
|
||||||
|
y=14
|
||||||
|
vx=0
|
||||||
|
vy=0.3
|
||||||
|
x1=19
|
||||||
|
y1=14
|
||||||
|
x2=19
|
||||||
|
y2=21
|
||||||
|
[/moving platform]
|
||||||
|
|
||||||
[/actors]
|
[/actors]
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
0,263,264,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,264,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,295,296,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0,295,296,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,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,
|
||||||
0,0,0,0,239,240,0,0,0,0,0,0,0,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,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,257,258,257,258,0,0,0,0,0,0,0,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,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,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,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,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,
|
||||||
|
|||||||
@@ -185,6 +185,8 @@ void Game::renderDebugInfo()
|
|||||||
//text = "checkCollision = " + std::to_string(checkCollision(p, r));
|
//text = "checkCollision = " + std::to_string(checkCollision(p, r));
|
||||||
debugText->write(0, line += 6, text, -1);
|
debugText->write(0, line += 6, text, -1);
|
||||||
|
|
||||||
|
text = std::to_string(map->getActorCollider(0)) + " " + std::to_string(map->getActorCollider(1));
|
||||||
|
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);
|
||||||
SDL_Rect rect = player->sprite->getRect();
|
SDL_Rect rect = player->sprite->getRect();
|
||||||
|
|||||||
@@ -530,4 +530,16 @@ int Map::getActorName(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el rectangulo de colisión
|
||||||
|
int Map::getActorCollider(int index)
|
||||||
|
{
|
||||||
|
int y = 0;
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
y = actors[index]->getCollider().y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return y;
|
||||||
}
|
}
|
||||||
@@ -100,6 +100,9 @@ public:
|
|||||||
|
|
||||||
// Devuelve el nombre del actor a pàrtir de un índice
|
// Devuelve el nombre del actor a pàrtir de un índice
|
||||||
int getActorName(int index);
|
int getActorName(int index);
|
||||||
|
|
||||||
|
// Devuelve el rectangulo de colisión
|
||||||
|
int getActorCollider(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -255,6 +255,13 @@ void Player::move()
|
|||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
y -= ((int)y + h) % tileSize;
|
y -= ((int)y + h) % tileSize;
|
||||||
}
|
}
|
||||||
|
// Tiene uno de los pies sobre una plataforma móvil
|
||||||
|
else if (isOnMovingPlatform())
|
||||||
|
{
|
||||||
|
state = standing;
|
||||||
|
vy = 0.0f;
|
||||||
|
y = SDKJSGHK - h-1;
|
||||||
|
}
|
||||||
// Tiene ambos pies sobre el vacío
|
// Tiene ambos pies sobre el vacío
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -308,12 +315,17 @@ bool Player::isOnFloor()
|
|||||||
bool Player::isOnMovingPlatform()
|
bool Player::isOnMovingPlatform()
|
||||||
{
|
{
|
||||||
bool onMovingPlatform = false;
|
bool onMovingPlatform = false;
|
||||||
|
SDKJSGHK = 0;
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
|
|
||||||
for (auto f : underFeet)
|
for (auto f : underFeet)
|
||||||
{
|
{
|
||||||
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
|
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
|
||||||
|
if (onMovingPlatform)
|
||||||
|
{
|
||||||
|
SDKJSGHK = map->getActorCollider(map->actorCollision(f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return onMovingPlatform;
|
return onMovingPlatform;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public:
|
|||||||
JA_Sound sound_death; // Sonido al morir
|
JA_Sound sound_death; // Sonido al morir
|
||||||
JA_Sound sound_jump; // Sonido al saltar
|
JA_Sound sound_jump; // Sonido al saltar
|
||||||
|
|
||||||
|
int SDKJSGHK;
|
||||||
|
|
||||||
// Comprueba las entradas y modifica variables
|
// Comprueba las entradas y modifica variables
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user