Cambiados muchos DEFINEs por variables de param

This commit is contained in:
2024-09-06 08:41:10 +02:00
parent c5bab7019c
commit 62b1ba84ac
23 changed files with 215 additions and 158 deletions

View File

@@ -2,13 +2,16 @@
#include "player.h"
// Constructor
Player::Player(float x, int y, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
Player::Player(float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
{
// Reserva memoria para los objetos
playerSprite = new AnimatedSprite(texture[0], "", animations[0]);
powerSprite = new AnimatedSprite(texture[1], "", animations[1]);
powerSprite->getTexture()->setAlpha(224);
// Rectangulo con la zona de juego
this->playArea = playArea;
// Establece la posición inicial del jugador
defaultPosX = posX = x;
defaultPosY = posY = y;
@@ -110,7 +113,7 @@ void Player::move()
posX += velX;
// Si el jugador abandona el area de juego por los laterales
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5))
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > playArea->w + 5))
{
// Restaura su posición
posX -= velX;
@@ -127,7 +130,7 @@ void Player::move()
playerSprite->update();
// Si el cadaver abandona el area de juego por los laterales
if ((playerSprite->getPosX() < PLAY_AREA_LEFT) || (playerSprite->getPosX() + width > PLAY_AREA_RIGHT))
if ((playerSprite->getPosX() < PLAY_AREA_LEFT) || (playerSprite->getPosX() + width > playArea->w))
{
// Restaura su posición
const float vx = playerSprite->getVelX();