Convertit "param" a variable global en lloc de anar marejant amb punterets i passant 8.000.000 de paràmetres

This commit is contained in:
2024-09-27 17:42:25 +02:00
parent c1bf0b8aed
commit 46b41757b2
28 changed files with 279 additions and 293 deletions

View File

@@ -1,10 +1,10 @@
#include "const.h"
#include "balloon.h"
#include "const.h"
#include "param.h"
// Constructor
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, param_t *param)
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation)
{
this->param = param;
sprite = new AnimatedSprite(texture, "", animation);
disable();
@@ -23,8 +23,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->velX = velx;
velY = 0;
maxVelY = 3.0f;
gravity = param->balloon1.grav;
defaultVelY = param->balloon1.vel;
gravity = param.balloon1.grav;
defaultVelY = param.balloon1.vel;
// Puntos que da el globo al ser destruido
score = BALLOON_SCORE_1;
@@ -45,8 +45,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->velX = velx;
velY = 0;
maxVelY = 3.0f;
gravity = param->balloon2.grav;
defaultVelY = param->balloon2.vel;
gravity = param.balloon2.grav;
defaultVelY = param.balloon2.vel;
// Puntos que da el globo al ser destruido
score = BALLOON_SCORE_2;
@@ -67,8 +67,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->velX = velx;
velY = 0;
maxVelY = 3.0f;
gravity = param->balloon3.grav;
defaultVelY = param->balloon3.vel;
gravity = param.balloon3.grav;
defaultVelY = param.balloon3.vel;
// Puntos que da el globo al ser destruido
score = BALLOON_SCORE_3;
@@ -89,8 +89,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->velX = velx;
velY = 0;
maxVelY = 3.0f;
gravity = param->balloon4.grav;
defaultVelY = param->balloon4.vel;
gravity = param.balloon4.grav;
defaultVelY = param.balloon4.vel;
// Puntos que da el globo al ser destruido
score = BALLOON_SCORE_4;
@@ -199,8 +199,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->velX = velx;
velY = 0;
maxVelY = 3.0f;
gravity = param->balloon4.grav;
defaultVelY = param->balloon4.vel;
gravity = param.balloon4.grav;
defaultVelY = param.balloon4.vel;
// Puntos que da el globo al ser destruido
score = 0;
@@ -285,9 +285,9 @@ void Balloon::allignTo(int x)
{
posX = PLAY_AREA_LEFT + 1;
}
else if ((posX + width) > param->game.playArea.rect.w)
else if ((posX + width) > param.game.playArea.rect.w)
{
posX = float(param->game.playArea.rect.w - width - 1);
posX = float(param.game.playArea.rect.w - width - 1);
}
// Posición X,Y del sprite
@@ -347,7 +347,7 @@ void Balloon::move()
posX += (velX * speed);
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
if ((posX < PLAY_AREA_LEFT) || (posX + width > param->game.playArea.rect.w))
if ((posX < PLAY_AREA_LEFT) || (posX + width > param.game.playArea.rect.w))
{
// Corrige posición
posX -= (velX * speed);
@@ -385,10 +385,10 @@ void Balloon::move()
}
// Si el globo se sale por la parte inferior
if (posY + height > param->game.playArea.rect.h)
if (posY + height > param.game.playArea.rect.h)
{
// Corrige
posY = param->game.playArea.rect.h - height;
posY = param.game.playArea.rect.h - height;
// Invierte colocando una velocidad por defecto
velY = -defaultVelY;
@@ -508,7 +508,7 @@ void Balloon::updateState()
posX += velX;
// Comprueba no se salga por los laterales
if ((posX < PLAY_AREA_LEFT) || (posX > (param->game.playArea.rect.w - width)))
if ((posX < PLAY_AREA_LEFT) || (posX > (param.game.playArea.rect.w - width)))
{
// Corrige y cambia el sentido de la velocidad
posX -= velX;