Compare commits
23 Commits
2024-11-20
...
2024-12-05
| Author | SHA1 | Date | |
|---|---|---|---|
| e3d0145417 | |||
| f0863b3691 | |||
| 80e366b208 | |||
| 3c5bbf2ab0 | |||
| 1aa0dd3864 | |||
| ab45c984a2 | |||
| 020ee81479 | |||
| 0cd96aced5 | |||
| ad32bb7d45 | |||
| c3a5166ee1 | |||
| 687d329d23 | |||
| faba87c06d | |||
| eed45bdbc6 | |||
| 6ed37425bf | |||
| b987d06aca | |||
| 9c9cfdabc2 | |||
| 9f2448753b | |||
| 736bf7e544 | |||
| a2d4331430 | |||
| fd7beee5a1 | |||
| a36120cf0c | |||
| ad221243cb | |||
| b8d4c8f17c |
@@ -28,6 +28,10 @@ Les tecles son les següents:
|
||||
|
||||
- **Tecla F4**: Activa o desactiva els shaders
|
||||
|
||||
- **Tecla F5**: Activa o desactiva l'audio
|
||||
|
||||
- **Tecla F6**: Canvia el idioma del joc i reinicia
|
||||
|
||||
- **Tecla F10**: Reset
|
||||
|
||||
<p align="center">
|
||||
|
||||
@@ -359,4 +359,16 @@ SuperPoder!
|
||||
Temps!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Puntuacio
|
||||
Puntuacio
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMAT I DISSENYAT PER
|
||||
|
||||
## 122 - CREDITS
|
||||
GRAFICS DIBUIXATS PER
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSICA COMPOSADA PER
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTES DE SO
|
||||
@@ -359,4 +359,16 @@ PowerUp
|
||||
Stop!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Score
|
||||
Score
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMMED AND DESIGNED BY
|
||||
|
||||
## 122 - CREDITS
|
||||
PIXELART DRAWN BY
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSIC COMPOSED BY
|
||||
|
||||
## 124 - CREDITS
|
||||
SOUND EFFECTS
|
||||
@@ -359,4 +359,16 @@ Potenciador
|
||||
Tiempo!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Puntuacion
|
||||
Puntuacion
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMADO Y DISE{ADO POR
|
||||
|
||||
## 122 - CREDITS
|
||||
GRAFICOS DIBUJADOS POR
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSICA COMPUESTA POR
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTOS DE SONIDO
|
||||
BIN
data/music/credits.ogg
Normal file
BIN
data/music/credits.ogg
Normal file
Binary file not shown.
234
data/shaders/crtpi_240.glsl
Normal file
234
data/shaders/crtpi_240.glsl
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
crt-pi - A Raspberry Pi friendly CRT shader.
|
||||
|
||||
Copyright (C) 2015-2016 davej
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
|
||||
|
||||
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
|
||||
|
||||
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
|
||||
|
||||
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
|
||||
|
||||
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
|
||||
|
||||
BLOOM_FACTOR controls the increase in width for bright scanlines.
|
||||
|
||||
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
|
||||
|
||||
*/
|
||||
|
||||
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
|
||||
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
|
||||
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
|
||||
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
|
||||
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
|
||||
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
|
||||
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
|
||||
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
|
||||
|
||||
// Haven't put these as parameters as it would slow the code down.
|
||||
#define SCANLINES
|
||||
#define MULTISAMPLE
|
||||
#define GAMMA
|
||||
//#define FAKE_GAMMA
|
||||
//#define CURVATURE
|
||||
//#define SHARPER
|
||||
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
|
||||
#define MASK_TYPE 2
|
||||
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
precision mediump float;
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float CURVATURE_X;
|
||||
uniform COMPAT_PRECISION float CURVATURE_Y;
|
||||
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
|
||||
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
|
||||
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
|
||||
uniform COMPAT_PRECISION float BLOOM_FACTOR;
|
||||
uniform COMPAT_PRECISION float INPUT_GAMMA;
|
||||
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
|
||||
#else
|
||||
#define CURVATURE_X 0.05
|
||||
#define CURVATURE_Y 0.1
|
||||
#define MASK_BRIGHTNESS 0.80
|
||||
#define SCANLINE_WEIGHT 6.0
|
||||
#define SCANLINE_GAP_BRIGHTNESS 0.12
|
||||
#define BLOOM_FACTOR 3.5
|
||||
#define INPUT_GAMMA 2.4
|
||||
#define OUTPUT_GAMMA 2.2
|
||||
#endif
|
||||
|
||||
/* COMPATIBILITY
|
||||
- GLSL compilers
|
||||
*/
|
||||
|
||||
//uniform vec2 TextureSize;
|
||||
#if defined(CURVATURE)
|
||||
varying vec2 screenScale;
|
||||
#endif
|
||||
varying vec2 TEX0;
|
||||
varying float filterWidth;
|
||||
|
||||
#if defined(VERTEX)
|
||||
//uniform mat4 MVPMatrix;
|
||||
//attribute vec4 VertexCoord;
|
||||
//attribute vec2 TexCoord;
|
||||
//uniform vec2 InputSize;
|
||||
//uniform vec2 OutputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(CURVATURE)
|
||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||
#endif
|
||||
filterWidth = (768.0 / 240.0) / 3.0;
|
||||
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
uniform sampler2D Texture;
|
||||
|
||||
#if defined(CURVATURE)
|
||||
vec2 Distort(vec2 coord)
|
||||
{
|
||||
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
|
||||
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
|
||||
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
|
||||
coord *= screenScale;
|
||||
coord -= vec2(0.5);
|
||||
float rsq = coord.x * coord.x + coord.y * coord.y;
|
||||
coord += coord * (CURVATURE_DISTORTION * rsq);
|
||||
coord *= barrelScale;
|
||||
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
|
||||
coord = vec2(-1.0); // If out of bounds, return an invalid value.
|
||||
else
|
||||
{
|
||||
coord += vec2(0.5);
|
||||
coord /= screenScale;
|
||||
}
|
||||
|
||||
return coord;
|
||||
}
|
||||
#endif
|
||||
|
||||
float CalcScanLineWeight(float dist)
|
||||
{
|
||||
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
|
||||
}
|
||||
|
||||
float CalcScanLine(float dy)
|
||||
{
|
||||
float scanLineWeight = CalcScanLineWeight(dy);
|
||||
#if defined(MULTISAMPLE)
|
||||
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
|
||||
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
|
||||
scanLineWeight *= 0.3333333;
|
||||
#endif
|
||||
return scanLineWeight;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 TextureSize = vec2(320.0, 240.0);
|
||||
#if defined(CURVATURE)
|
||||
vec2 texcoord = Distort(TEX0);
|
||||
if (texcoord.x < 0.0)
|
||||
gl_FragColor = vec4(0.0);
|
||||
else
|
||||
#else
|
||||
vec2 texcoord = TEX0;
|
||||
#endif
|
||||
{
|
||||
vec2 texcoordInPixels = texcoord * TextureSize;
|
||||
#if defined(SHARPER)
|
||||
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
|
||||
vec2 coord = tempCoord / TextureSize;
|
||||
vec2 deltas = texcoordInPixels - tempCoord;
|
||||
float scanLineWeight = CalcScanLine(deltas.y);
|
||||
vec2 signs = sign(deltas);
|
||||
deltas.x *= 2.0;
|
||||
deltas = deltas * deltas;
|
||||
deltas.y = deltas.y * deltas.y;
|
||||
deltas.x *= 0.5;
|
||||
deltas.y *= 8.0;
|
||||
deltas /= TextureSize;
|
||||
deltas *= signs;
|
||||
vec2 tc = coord + deltas;
|
||||
#else
|
||||
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||
float yCoord = tempY / TextureSize.y;
|
||||
float dy = texcoordInPixels.y - tempY;
|
||||
float scanLineWeight = CalcScanLine(dy);
|
||||
float signY = sign(dy);
|
||||
dy = dy * dy;
|
||||
dy = dy * dy;
|
||||
dy *= 8.0;
|
||||
dy /= TextureSize.y;
|
||||
dy *= signY;
|
||||
vec2 tc = vec2(texcoord.x, yCoord + dy);
|
||||
#endif
|
||||
|
||||
vec3 colour = texture2D(Texture, tc).rgb;
|
||||
|
||||
#if defined(SCANLINES)
|
||||
#if defined(GAMMA)
|
||||
#if defined(FAKE_GAMMA)
|
||||
colour = colour * colour;
|
||||
#else
|
||||
colour = pow(colour, vec3(INPUT_GAMMA));
|
||||
#endif
|
||||
#endif
|
||||
scanLineWeight *= BLOOM_FACTOR;
|
||||
colour *= scanLineWeight;
|
||||
|
||||
#if defined(GAMMA)
|
||||
#if defined(FAKE_GAMMA)
|
||||
colour = sqrt(colour);
|
||||
#else
|
||||
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if MASK_TYPE == 0
|
||||
gl_FragColor = vec4(colour, 1.0);
|
||||
#else
|
||||
#if MASK_TYPE == 1
|
||||
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
|
||||
vec3 mask;
|
||||
if (whichMask < 0.5)
|
||||
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
|
||||
else
|
||||
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
|
||||
#elif MASK_TYPE == 2
|
||||
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
|
||||
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
|
||||
if (whichMask < 0.3333333)
|
||||
mask.x = 1.0;
|
||||
else if (whichMask < 0.6666666)
|
||||
mask.y = 1.0;
|
||||
else
|
||||
mask.z = 1.0;
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(colour * mask, 1.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -97,7 +97,6 @@ void main()
|
||||
#if defined(CURVATURE)
|
||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||
#endif
|
||||
//filterWidth = (768.0 / 240.0) / 3.0;
|
||||
filterWidth = (768.0 / 256.0) / 3.0;
|
||||
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
BIN
data/sound/logo.wav
Normal file
BIN
data/sound/logo.wav
Normal file
Binary file not shown.
@@ -7,7 +7,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_Rect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
x_(x),
|
||||
y_(y),
|
||||
@@ -19,7 +19,8 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
creation_counter_ini_(creation_timer),
|
||||
type_(type),
|
||||
size_(size),
|
||||
speed_(speed)
|
||||
speed_(speed),
|
||||
play_area_(play_area)
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
@@ -91,8 +92,8 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
void Balloon::alignTo(int x)
|
||||
{
|
||||
x_ = static_cast<float>(x - (w_ / 2));
|
||||
const int min_x = param.game.play_area.rect.x;
|
||||
const int max_x = param.game.play_area.rect.w - w_;
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.w - w_;
|
||||
x_ = std::clamp(x_, static_cast<float>(min_x), static_cast<float>(max_x));
|
||||
}
|
||||
|
||||
@@ -105,6 +106,7 @@ void Balloon::render()
|
||||
SDL_Point p = {24, 24};
|
||||
sprite_->setRotatingCenter(&p);
|
||||
sprite_->render();
|
||||
|
||||
// Añade la máscara del borde y los reflejos
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||
sp->setSpriteClip(BALLOON_SIZE[4], 0, BALLOON_SIZE[4], BALLOON_SIZE[4]);
|
||||
@@ -122,18 +124,8 @@ void Balloon::render()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bouncing_.enabled)
|
||||
{
|
||||
// Renderizado con efecto de bouncing
|
||||
sprite_->setPos(x_ + bouncing_.despX, y_ + bouncing_.despY);
|
||||
sprite_->render();
|
||||
// sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Renderizado normal
|
||||
sprite_->render();
|
||||
}
|
||||
// Renderizado normal
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,8 +141,8 @@ void Balloon::move()
|
||||
|
||||
// Colisión en las partes laterales de la zona de juego
|
||||
const int clip = 2;
|
||||
const float min_x = param.game.play_area.rect.x - clip;
|
||||
const float max_x = param.game.play_area.rect.w - w_ + clip;
|
||||
const float min_x = play_area_.x - clip;
|
||||
const float max_x = play_area_.x + play_area_.w - w_ + clip;
|
||||
if (x_ < min_x || x_ > max_x)
|
||||
{
|
||||
x_ = std::clamp(x_, min_x, max_x);
|
||||
@@ -170,9 +162,21 @@ void Balloon::move()
|
||||
y_ += vy_ * speed_;
|
||||
|
||||
// Colisión en la parte superior de la zona de juego excepto para la PowerBall
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
/*if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
const int min_y = param.game.play_area.rect.y;
|
||||
const int min_y = play_area_.y;
|
||||
if (y_ < min_y)
|
||||
{
|
||||
y_ = min_y;
|
||||
vy_ = -vy_;
|
||||
enableBounce();
|
||||
}
|
||||
}*/
|
||||
|
||||
// Colisión en la parte superior solo si el globo va de subida
|
||||
if (vy_ < 0)
|
||||
{
|
||||
const int min_y = play_area_.y;
|
||||
if (y_ < min_y)
|
||||
{
|
||||
y_ = min_y;
|
||||
@@ -182,7 +186,7 @@ void Balloon::move()
|
||||
}
|
||||
|
||||
// Colisión en la parte inferior de la zona de juego
|
||||
const int max_y = param.game.play_area.rect.h - h_;
|
||||
const int max_y = play_area_.y + play_area_.h - h_;
|
||||
if (y_ > max_y)
|
||||
{
|
||||
y_ = max_y;
|
||||
@@ -254,8 +258,8 @@ void Balloon::updateState()
|
||||
x_ += vx_;
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
const int min_x = param.game.play_area.rect.x;
|
||||
const int max_x = param.game.play_area.rect.w - w_;
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.w - w_;
|
||||
|
||||
if (x_ < min_x || x_ > max_x)
|
||||
{
|
||||
@@ -375,12 +379,10 @@ void Balloon::updateBounce()
|
||||
|
||||
zoomSprite();
|
||||
|
||||
const auto spriteClip = sprite_->getSpriteClip();
|
||||
bouncing_.despX = spriteClip.w * (1.0f - bouncing_.zoomW);
|
||||
bouncing_.despY = spriteClip.h * (1.0f - bouncing_.zoomH);
|
||||
|
||||
if (++bouncing_.counter / bouncing_.speed >= MAX_BOUNCE)
|
||||
{
|
||||
disableBounce();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture; // lines 10-10
|
||||
class Texture; // lines 9-9
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
constexpr int MAX_BOUNCE = 10;
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
float travel_y_ = 1.0f; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
||||
float speed_; // Velocidad a la que se mueven los globos
|
||||
Uint8 power_; // Cantidad de poder que alberga el globo
|
||||
SDL_Rect play_area_; // Zona por donde se puede mover el globo
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void shiftColliders();
|
||||
@@ -138,7 +140,17 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation);
|
||||
Balloon(
|
||||
float x,
|
||||
float y,
|
||||
BalloonType type,
|
||||
BalloonSize size,
|
||||
float vel_x,
|
||||
float speed,
|
||||
Uint16 creation_timer,
|
||||
SDL_Rect play_area,
|
||||
std::shared_ptr<Texture> texture,
|
||||
const std::vector<std::string> &animation);
|
||||
|
||||
// Destructor
|
||||
~Balloon() = default;
|
||||
|
||||
@@ -38,7 +38,6 @@ struct BalloonFormationUnit
|
||||
BalloonFormationUnit() : number_of_balloons(0), init() {}
|
||||
};
|
||||
|
||||
|
||||
using BalloonFormationPool = std::vector<const BalloonFormationUnit *>;
|
||||
|
||||
class BalloonFormations
|
||||
@@ -67,4 +66,5 @@ public:
|
||||
// Getters
|
||||
const BalloonFormationPool &getPool(int pool) { return balloon_formation_pool_.at(pool); }
|
||||
const BalloonFormationUnit &getSet(int pool, int set) { return *balloon_formation_pool_.at(pool).at(set); }
|
||||
const BalloonFormationUnit &getSet(int set) const { return balloon_formation_.at(set); }
|
||||
};
|
||||
|
||||
@@ -119,6 +119,30 @@ void BalloonManager::deployBalloonFormation(int stage)
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void BalloonManager::deploySet(int set_number)
|
||||
{
|
||||
const auto set = balloon_formations_->getSet(set_number);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void BalloonManager::deploySet(int set_number, int y)
|
||||
{
|
||||
const auto set = balloon_formations_->getSet(set_number);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void BalloonManager::freeBalloons()
|
||||
{
|
||||
@@ -150,7 +174,7 @@ int BalloonManager::calculateScreenPower()
|
||||
std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer)
|
||||
{
|
||||
const int index = static_cast<int>(size);
|
||||
balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, balloon_textures_.at(index), balloon_animations_.at(index)));
|
||||
balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, play_area_, balloon_textures_.at(index), balloon_animations_.at(index)));
|
||||
return balloons_.back();
|
||||
}
|
||||
|
||||
@@ -188,7 +212,7 @@ void BalloonManager::createPowerBall()
|
||||
const int x[values] = {left, left, center, center, right, right};
|
||||
const float vx[values] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE};
|
||||
|
||||
balloons_.emplace_back(std::make_unique<Balloon>(x[luck], pos_y, BalloonType::POWERBALL, BalloonSize::SIZE4, vx[luck], balloon_speed_, creation_time, balloon_textures_[4], balloon_animations_[4]));
|
||||
balloons_.emplace_back(std::make_unique<Balloon>(x[luck], pos_y, BalloonType::POWERBALL, BalloonSize::SIZE4, vx[luck], balloon_speed_, creation_time, play_area_, balloon_textures_[4], balloon_animations_[4]));
|
||||
|
||||
power_ball_enabled_ = true;
|
||||
power_ball_counter_ = POWERBALL_COUNTER;
|
||||
@@ -279,7 +303,7 @@ int BalloonManager::destroyAllBalloons()
|
||||
|
||||
balloon_deploy_counter_ = 300;
|
||||
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
||||
Screen::get()->flash(flash_color, 100);
|
||||
Screen::get()->flash(flash_color, 3);
|
||||
Screen::get()->shake();
|
||||
|
||||
return score;
|
||||
@@ -339,13 +363,7 @@ void BalloonManager::reLoad()
|
||||
// Crea dos globos gordos
|
||||
void BalloonManager::createTwoBigBalloons()
|
||||
{
|
||||
const auto set = balloon_formations_->getSet(0, 1);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
deploySet(1);
|
||||
}
|
||||
|
||||
// Obtiene el nivel de ameza actual generado por los globos
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "balloon.h" // Para BALLOON_SPEED, Balloon
|
||||
#include "balloon_formations.h" // Para BalloonFormations
|
||||
#include "explosions.h" // Para Explosions
|
||||
class Texture;
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "utils.h" // Para Zone
|
||||
class Texture; // lines 10-10
|
||||
|
||||
using Balloons = std::vector<std::shared_ptr<Balloon>>;
|
||||
|
||||
@@ -29,6 +32,7 @@ private:
|
||||
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
|
||||
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
SDL_Rect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos
|
||||
|
||||
// Inicializa
|
||||
void init();
|
||||
@@ -49,9 +53,13 @@ public:
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void freeBalloons();
|
||||
|
||||
// Crea una formación de enemigos
|
||||
// Crea una formación de enemigos al azar
|
||||
void deployBalloonFormation(int stage);
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void deploySet(int set);
|
||||
void deploySet(int set, int y);
|
||||
|
||||
// Actualiza la variable enemyDeployCounter
|
||||
void updateBalloonDeployCounter();
|
||||
|
||||
@@ -110,4 +118,5 @@ public:
|
||||
// Setters
|
||||
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }
|
||||
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }
|
||||
void setPlayArea(SDL_Rect play_area) { play_area_ = play_area; }
|
||||
};
|
||||
471
source/credits.cpp
Normal file
471
source/credits.cpp
Normal file
@@ -0,0 +1,471 @@
|
||||
#include "credits.h"
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <string> // Para basic_string, string
|
||||
#include <vector> // Para vector
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input
|
||||
#include "jail_audio.h" // Para JA_PlayMusic, JA_StopMusic
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h" // Para Color, no_color, shdw_txt_color, Zone
|
||||
#include "player.h"
|
||||
#include "fade.h"
|
||||
#include "lang.h"
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||
|
||||
// Constructor
|
||||
Credits::Credits()
|
||||
: balloon_manager_(std::make_unique<BalloonManager>()),
|
||||
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL)),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>())
|
||||
{
|
||||
if (!text_texture_)
|
||||
{
|
||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||
}
|
||||
section::name = section::Name::CREDITS;
|
||||
//top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
|
||||
//bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
|
||||
balloon_manager_->setPlayArea(play_area_);
|
||||
|
||||
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_in_->setType(FadeType::FULLSCREEN);
|
||||
fade_in_->setPost(50);
|
||||
fade_in_->setMode(FadeMode::IN);
|
||||
fade_in_->activate();
|
||||
|
||||
fade_out_->setColor(0, 0, 0);
|
||||
fade_out_->setType(FadeType::FULLSCREEN);
|
||||
fade_out_->setPost(400);
|
||||
|
||||
initPlayers();
|
||||
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
||||
fillTextTexture();
|
||||
steps_ = std::abs((top_black_rect_.h - param.game.game_area.center_y - 1) + ((left_black_rect_.w - param.game.game_area.center_x) / 4));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits()
|
||||
{
|
||||
SDL_DestroyTexture(text_texture_);
|
||||
resetVolume();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Credits::run()
|
||||
{
|
||||
while (section::name == section::Name::CREDITS)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Credits::update()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
ticks_ = SDL_GetTicks();
|
||||
tiled_bg_->update();
|
||||
balloon_manager_->update();
|
||||
updateTextureDstRects();
|
||||
throwBalloons();
|
||||
for (auto &player : players_)
|
||||
{
|
||||
player->update();
|
||||
}
|
||||
updateAllFades();
|
||||
Screen::get()->update();
|
||||
globalInputs::update();
|
||||
++counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja Credits::en patalla
|
||||
void Credits::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean();
|
||||
|
||||
// Dibuja el fondo, los globos y los jugadores
|
||||
tiled_bg_->render();
|
||||
balloon_manager_->render();
|
||||
for (auto const &player : players_)
|
||||
{
|
||||
player->render();
|
||||
}
|
||||
|
||||
// Dibuja los titulos de credito
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_);
|
||||
|
||||
// Dibuja el mini_logo
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||
|
||||
// Dibuja los rectangulos negros
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &top_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &bottom_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &left_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &right_black_rect_);
|
||||
|
||||
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
|
||||
if (mini_logo_on_position_)
|
||||
{
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||
}
|
||||
|
||||
// Dibuja el fade sobre el resto de elementos
|
||||
fade_in_->render();
|
||||
fade_out_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->blit();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::checkInput()
|
||||
{
|
||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
if (mini_logo_on_position_)
|
||||
{
|
||||
// Si el mini_logo ha llegado a su posición final, al pulsar cualquier tecla se activa el fundido
|
||||
fading_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si todavía estan los creditos en marcha, se pasan solos a toda pastilla
|
||||
want_to_pass_ = true;
|
||||
ticks_speed_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Crea la textura con el texto
|
||||
void Credits::fillTextTexture()
|
||||
{
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
|
||||
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
|
||||
std::vector<std::string> texts = {
|
||||
lang::getText(121),
|
||||
lang::getText(122),
|
||||
lang::getText(123),
|
||||
lang::getText(124),
|
||||
"JAILDESIGNER",
|
||||
"JAILDOCTOR (INTRO)",
|
||||
"ERIC MATYAS (SOUNDIMAGE.ORG)",
|
||||
"WWW.THEMOTIONMONKEY.CO.UK",
|
||||
"WWW.KENNEY.NL",
|
||||
"JAILDOCTOR"};
|
||||
|
||||
const int space_post_title = 3 + text->getCharacterSize();
|
||||
const int space_pre_title = text->getCharacterSize() * 4;
|
||||
const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title;
|
||||
credits_rect_dst_.h = credits_rect_src_.h = texts_height;
|
||||
|
||||
int y = (param.game.height - texts_height) / 2;
|
||||
y = 0;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(0), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(1), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(2), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(5), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(6), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(3), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(7), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(8), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(9), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
// Mini logo
|
||||
y += space_pre_title;
|
||||
mini_logo_rect_src_.y = y;
|
||||
auto mini_logo_sprite = std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"));
|
||||
mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y);
|
||||
Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(shdw_txt_color.r, shdw_txt_color.g, shdw_txt_color.b);
|
||||
mini_logo_sprite->render();
|
||||
|
||||
mini_logo_sprite->setPosition(param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, y);
|
||||
Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(255, 255, 255);
|
||||
mini_logo_sprite->render();
|
||||
|
||||
// Texto con el copyright
|
||||
y += mini_logo_sprite->getHeight() + 3;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXT_COPYRIGHT, 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
// Resetea el renderizador
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
|
||||
// Actualiza las variables
|
||||
mini_logo_rect_dst_.h = mini_logo_rect_src_.h = mini_logo_sprite->getHeight() + 3 + text->getCharacterSize();
|
||||
credits_rect_dst_.y = param.game.game_area.rect.h;
|
||||
mini_logo_rect_dst_.y = credits_rect_dst_.y + credits_rect_dst_.h + 30;
|
||||
mini_logo_final_pos_ = param.game.game_area.center_y - mini_logo_rect_src_.h / 2;
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas
|
||||
void Credits::updateTextureDstRects()
|
||||
{
|
||||
if (counter_ % 10 == 0)
|
||||
{
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y)
|
||||
{
|
||||
--credits_rect_dst_.y;
|
||||
}
|
||||
|
||||
// Comprueba la posición de la textura con el mini_logo
|
||||
if (mini_logo_rect_dst_.y == mini_logo_final_pos_)
|
||||
{
|
||||
mini_logo_on_position_ = true;
|
||||
|
||||
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
|
||||
if (want_to_pass_)
|
||||
{
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Se activa el contador para evitar que la sección sea infinita
|
||||
if (counter_prevent_endless_ == 1000)
|
||||
{
|
||||
fading_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
++counter_prevent_endless_;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
--mini_logo_rect_dst_.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario
|
||||
void Credits::throwBalloons()
|
||||
{
|
||||
constexpr int speed = 200;
|
||||
const std::vector<int> sets = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
|
||||
if (counter_ > ((sets.size() - 1) * speed) * 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (counter_ % speed == 0)
|
||||
{
|
||||
const int index = (counter_ / speed) % sets.size();
|
||||
balloon_manager_->deploySet(sets.at(index), -60);
|
||||
}
|
||||
|
||||
if (counter_ % (speed * 4) == 0 && counter_ > 0)
|
||||
{
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa los jugadores
|
||||
void Credits::initPlayers()
|
||||
{
|
||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
|
||||
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
|
||||
|
||||
// Texturas - Player1
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Texturas - Player2
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Animaciones -- Jugador
|
||||
{
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
}
|
||||
|
||||
// Crea los dos jugadores
|
||||
constexpr int player_width = 30;
|
||||
const int y = play_area_.y + play_area_.h - player_width;
|
||||
constexpr bool demo = false;
|
||||
constexpr int away_distance = 700;
|
||||
players_.emplace_back(std::make_unique<Player>(1, play_area_.x - away_distance - player_width, y, demo, play_area_, player_textures.at(0), player_animations));
|
||||
players_.back()->setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
players_.back()->setPlayingState(PlayerState::CREDITS);
|
||||
players_.back()->setInvulnerable(false);
|
||||
|
||||
players_.emplace_back(std::make_unique<Player>(2, play_area_.x + play_area_.w + away_distance, y, demo, play_area_, player_textures.at(1), player_animations));
|
||||
players_.back()->setWalkingState(PlayerState::WALKING_LEFT);
|
||||
players_.back()->setPlayingState(PlayerState::CREDITS);
|
||||
players_.back()->setInvulnerable(false);
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
void Credits::updateBlackRects()
|
||||
{
|
||||
static int current_step = steps_;
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1)
|
||||
{
|
||||
// Si los rectangulos superior e inferior no han llegado al centro
|
||||
if (counter_ % 4 == 0)
|
||||
{
|
||||
// Incrementa la altura del rectangulo superior
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
|
||||
|
||||
// Incrementa la altura y modifica la posición del rectangulo inferior
|
||||
++bottom_black_rect_.h;
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
|
||||
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si los rectangulos superior e inferior han llegado al centro
|
||||
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x)
|
||||
{
|
||||
// Si los rectangulos izquierdo y derecho no han llegado al centro
|
||||
// Incrementa la anchura del rectangulo situado a la izquierda
|
||||
left_black_rect_.w = std::min(left_black_rect_.w + 4, param.game.game_area.center_x);
|
||||
|
||||
// Incrementa la anchura y modifica la posición del rectangulo situado a la derecha
|
||||
right_black_rect_.w += 4;
|
||||
right_black_rect_.x = std::max(right_black_rect_.x - 4, param.game.game_area.center_x);
|
||||
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||
setVolume(0);
|
||||
JA_StopMusic();
|
||||
if (counter_pre_fade_ == 400)
|
||||
{
|
||||
fade_out_->activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
++counter_pre_fade_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade
|
||||
void Credits::updateAllFades()
|
||||
{
|
||||
if (fading_)
|
||||
{
|
||||
updateBlackRects();
|
||||
}
|
||||
|
||||
fade_in_->update();
|
||||
if (fade_in_->hasEnded())
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
|
||||
}
|
||||
}
|
||||
|
||||
fade_out_->update();
|
||||
if (fade_out_->hasEnded())
|
||||
{
|
||||
section::name = section::Name::LOGO;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el nivel de volumen
|
||||
void Credits::setVolume(int amount)
|
||||
{
|
||||
options.audio.music.volume = std::clamp(amount, 0, 100);
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
}
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void Credits::resetVolume()
|
||||
{
|
||||
options.audio.music.volume = initial_volume_;
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
}
|
||||
100
source/credits.h
Normal file
100
source/credits.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
class BalloonManager;
|
||||
class TiledBG;
|
||||
class Player;
|
||||
class Fade;
|
||||
|
||||
constexpr int PLAY_AREA_HEIGHT = 200;
|
||||
|
||||
class Credits
|
||||
{
|
||||
private:
|
||||
// Objetos
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
SDL_Texture *text_texture_; // Textura con el texto
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_in_; // Objeto para realizar el fundido de entrada
|
||||
std::unique_ptr<Fade> fade_out_; // Objeto para realizar el fundido de salida
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
|
||||
// Variables
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_ = 15; // Velocidad del bucle update
|
||||
Uint32 counter_ = 0; // Contador para la lógica de la clase
|
||||
Uint32 counter_pre_fade_ = 0; // Contador para activar el fundido final
|
||||
Uint32 counter_prevent_endless_ = 0; // Contador para evitar que el juego se quede para siempre en los creditos
|
||||
int black_bars_size_ = (param.game.game_area.rect.h - PLAY_AREA_HEIGHT) / 2; // Tamaño de las barras negras
|
||||
int mini_logo_final_pos_ = 0; // Ubicación donde se detiene el minilogo
|
||||
bool fading_ = false; // Indica si se está realizando el fade final
|
||||
bool want_to_pass_ = false; // Indica si el jugador quiere saltarse los titulos de crédito
|
||||
bool mini_logo_on_position_ = false; // Indica si el minilogo ya se ha quedado en su posición
|
||||
int initial_volume_ = options.audio.music.volume; // Volumen actual al crear el objeto
|
||||
int steps_ = 0; // Cantidad de pasos a dar para ir reduciendo el audio
|
||||
|
||||
// Rectangulos
|
||||
SDL_Rect credits_rect_src_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (origen)
|
||||
SDL_Rect credits_rect_dst_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (destino)
|
||||
SDL_Rect mini_logo_rect_src_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (origen)
|
||||
SDL_Rect mini_logo_rect_dst_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (destino)
|
||||
SDL_Rect play_area_ = {
|
||||
param.game.game_area.rect.x,
|
||||
param.game.game_area.rect.y + black_bars_size_,
|
||||
param.game.game_area.rect.w,
|
||||
PLAY_AREA_HEIGHT}; // Area visible para los creditos
|
||||
SDL_Rect top_black_rect_ = {play_area_.x, param.game.game_area.rect.y, play_area_.w, black_bars_size_}; // Rectangulo negro superior
|
||||
SDL_Rect bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_}; // Rectangulo negro inferior
|
||||
SDL_Rect left_black_rect_ = {play_area_.x, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la izquierda
|
||||
SDL_Rect right_black_rect_ = {play_area_.x + play_area_.w, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la derecha
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Dibuja en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Crea la textura con el texto
|
||||
void fillTextTexture();
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas
|
||||
void updateTextureDstRects();
|
||||
|
||||
// Tira globos al escenario
|
||||
void throwBalloons();
|
||||
|
||||
// Inicializa los jugadores
|
||||
void initPlayers();
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
void updateBlackRects();
|
||||
|
||||
// Actualiza el estado de fade
|
||||
void updateAllFades();
|
||||
|
||||
// Establece el nivel de volumen
|
||||
void setVolume(int amount);
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void resetVolume();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Credits();
|
||||
|
||||
// Destructor
|
||||
~Credits();
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
// IWYU pragma: no_include <bits/chrono.h>
|
||||
#include "director.h"
|
||||
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
|
||||
@@ -7,7 +8,7 @@
|
||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||
#include <bits/chrono.h> // Para duration, system_clock
|
||||
#include <chrono> // Para duration, system_clock
|
||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // Para printf, perror
|
||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <string> // Para operator+, char_traits, allocator
|
||||
#include <vector> // Para vector
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "credits.h" // Para Credits
|
||||
#include "dbgtxt.h" // Para dbg_init
|
||||
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
|
||||
#include "global_inputs.h" // Para init
|
||||
@@ -45,13 +47,6 @@
|
||||
#include <pwd.h> // para getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Inicia la semilla aleatoria
|
||||
void initRand()
|
||||
{
|
||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::srand(seed);
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, const char *argv[])
|
||||
{
|
||||
@@ -60,7 +55,7 @@ Director::Director(int argc, const char *argv[])
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
#elif DEBUG
|
||||
section::name = section::Name::LOGO;
|
||||
#else
|
||||
#else // NORMAL GAME
|
||||
section::name = section::Name::LOGO;
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||
#endif
|
||||
@@ -73,42 +68,36 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
initRand();
|
||||
// Inicia la semilla aleatoria
|
||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::srand(seed);
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
// Crea la carpeta del sistema donde guardar los datos persistentes
|
||||
createSystemFolder("jailgames");
|
||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executable_path_);
|
||||
init();
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
setFileList();
|
||||
Director::~Director()
|
||||
{
|
||||
close();
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
||||
// Inicializa todo
|
||||
void Director::init()
|
||||
{
|
||||
Asset::init(executable_path_); // Crea el objeto que controla los ficheros de recursos
|
||||
setFileList(); // Crea el indice de ficheros
|
||||
loadOptionsFile(Asset::get()->get("config.txt")); // Carga el fichero de configuración
|
||||
loadParams(); // Carga los parametros
|
||||
loadScoreFile(); // Carga el fichero de puntuaciones
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParamsFromFile(paramFilePath);
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
manager->clear();
|
||||
else
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
|
||||
// Inicializa todo
|
||||
// Inicializa y crea el resto de objetos
|
||||
initSDL();
|
||||
initJailAudio();
|
||||
dbg_init(renderer_);
|
||||
@@ -117,12 +106,12 @@ Director::Director(int argc, const char *argv[])
|
||||
Resource::init();
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud"), Asset::get()->get("notify.wav"));
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud"));
|
||||
OnScreenHelp::init();
|
||||
globalInputs::init();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
// Cierra todo
|
||||
void Director::close()
|
||||
{
|
||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||
|
||||
@@ -133,12 +122,38 @@ Director::~Director()
|
||||
Notifier::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
JA_Quit();
|
||||
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
// Carga los parametros
|
||||
void Director::loadParams()
|
||||
{
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParamsFromFile(paramFilePath);
|
||||
}
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void Director::loadScoreFile()
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
{
|
||||
manager->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
@@ -165,7 +180,8 @@ void Director::bindInputs()
|
||||
Input::get()->bindKey(InputType::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(InputType::VIDEO_SHADERS, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(InputType::MUTE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputType::CHANGE_LANG, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F7);
|
||||
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10);
|
||||
|
||||
// Asigna botones a inputs
|
||||
@@ -361,6 +377,7 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/credits.ogg", AssetType::MUSIC);
|
||||
|
||||
// Sonidos
|
||||
Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND);
|
||||
@@ -379,9 +396,11 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/sound/clock.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/powerball.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/notify.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/logo.wav", AssetType::SOUND);
|
||||
|
||||
// Shaders
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi_256.glsl", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi_240.glsl", AssetType::DATA);
|
||||
|
||||
// Texturas
|
||||
|
||||
@@ -630,6 +649,13 @@ void Director::runInstructions()
|
||||
instructions->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestran los creditos del programa
|
||||
void Director::runCredits()
|
||||
{
|
||||
auto credits = std::make_unique<Credits>();
|
||||
credits->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void Director::runHiScoreTable()
|
||||
{
|
||||
@@ -646,6 +672,16 @@ void Director::runDemoGame()
|
||||
game->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección init
|
||||
void Director::runInit()
|
||||
{
|
||||
if (section::options == section::Options::RELOAD)
|
||||
{
|
||||
Resource::get()->reload();
|
||||
}
|
||||
section::name = section::Name::LOGO;
|
||||
}
|
||||
|
||||
int Director::run()
|
||||
{
|
||||
// Bucle principal
|
||||
@@ -654,7 +690,7 @@ int Director::run()
|
||||
switch (section::name)
|
||||
{
|
||||
case section::Name::INIT:
|
||||
section::name = section::Name::LOGO;
|
||||
runInit();
|
||||
break;
|
||||
case section::Name::LOGO:
|
||||
runLogo();
|
||||
@@ -677,6 +713,9 @@ int Director::run()
|
||||
case section::Name::INSTRUCTIONS:
|
||||
runInstructions();
|
||||
break;
|
||||
case section::Name::CREDITS:
|
||||
runCredits();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -58,12 +58,18 @@ private:
|
||||
// Ejecuta la sección donde se muestran las instrucciones
|
||||
void runInstructions();
|
||||
|
||||
// Ejecuta la sección donde se muestran los creditos del programa
|
||||
void runCredits();
|
||||
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void runHiScoreTable();
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
void runDemoGame();
|
||||
|
||||
// Ejecuta la sección init
|
||||
void runInit();
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLangFile(lang::Code code);
|
||||
#ifdef ARCADE
|
||||
@@ -71,6 +77,18 @@ private:
|
||||
void shutdownSystem();
|
||||
#endif
|
||||
|
||||
// Inicializa todo
|
||||
void init();
|
||||
|
||||
// Cierra todo
|
||||
void close();
|
||||
|
||||
// Carga los parametros
|
||||
void loadParams();
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void loadScoreFile();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(int argc, const char *argv[]);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "balloon.h" // Para Balloon, BALLOON_SPEED
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
||||
#include "enter_name.h" // Para NAME_LENGHT
|
||||
#include "fade.h" // Para Fade, FadeType
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL...
|
||||
@@ -30,9 +31,8 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "smart_sprite.h" // Para SmartSprite
|
||||
#include "stage.h" // Para get, number, Stage, power
|
||||
#include "stage.h" // Para number, get, Stage, power, total_p...
|
||||
#include "text.h" // Para Text
|
||||
#include "dbgtxt.h" // Para dbg_print
|
||||
#include "texture.h" // Para Texture
|
||||
struct JA_Sound_t; // lines 37-37
|
||||
|
||||
@@ -253,7 +253,7 @@ void Game::updateStage()
|
||||
++Stage::number;
|
||||
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
||||
balloon_manager_->resetBalloonSpeed();
|
||||
screen_->flash(flash_color, 100);
|
||||
screen_->flash(flash_color, 3);
|
||||
screen_->shake();
|
||||
|
||||
// Escribe el texto por pantalla
|
||||
@@ -303,7 +303,16 @@ void Game::updateGameOverState()
|
||||
|
||||
if (fade_->hasEnded())
|
||||
{
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
if (game_completed_counter_ > 0)
|
||||
{
|
||||
// Los jugadores han completado el juego
|
||||
section::name = section::Name::CREDITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// La partida ha terminado con la derrota de los jugadores
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -860,6 +869,7 @@ void Game::update()
|
||||
|
||||
checkMusicStatus();
|
||||
screen_->update();
|
||||
globalInputs::update();
|
||||
fillCanvas();
|
||||
}
|
||||
}
|
||||
@@ -951,8 +961,7 @@ void Game::disableTimeStopItem()
|
||||
void Game::checkMusicStatus()
|
||||
{
|
||||
// Si la música no está sonando
|
||||
if (JA_GetMusicState() == JA_MUSIC_INVALID ||
|
||||
JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||
// Si se ha completado el juego o los jugadores han terminado, detiene la música
|
||||
state_ == GameState::COMPLETED || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(Resource::get()->getMusic("playing.ogg"));
|
||||
}
|
||||
@@ -1161,7 +1170,7 @@ void Game::checkEvents()
|
||||
}
|
||||
case SDLK_7: // Flash
|
||||
{
|
||||
screen_->flash(flash_color, 100);
|
||||
screen_->flash(flash_color, 3);
|
||||
break;
|
||||
}
|
||||
case SDLK_8:
|
||||
|
||||
@@ -15,30 +15,24 @@ GameLogo::GameLogo(int x, int y)
|
||||
coffee_texture_(Resource::get()->getTexture("title_coffee.png")),
|
||||
crisis_texture_(Resource::get()->getTexture("title_crisis.png")),
|
||||
arcade_edition_texture_(Resource::get()->getTexture("title_arcade_edition.png")),
|
||||
|
||||
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
|
||||
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
||||
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
||||
|
||||
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
||||
|
||||
x_(x),
|
||||
y_(y)
|
||||
{
|
||||
// Inicializa las variables
|
||||
init();
|
||||
}
|
||||
y_(y) { }
|
||||
|
||||
// Inicializa las variables
|
||||
void GameLogo::init()
|
||||
{
|
||||
const auto xp = x_ - coffee_sprite_->getWidth() / 2;
|
||||
const auto xp = x_ - coffee_texture_->getWidth() / 2;
|
||||
const auto desp = getInitialVerticalDesp();
|
||||
|
||||
// Variables
|
||||
status_ = Status::DISABLED;
|
||||
coffee_crisis_status_ = Status::DISABLED;
|
||||
arcade_edition_status_ = Status::DISABLED;
|
||||
|
||||
shake_.desp = 1;
|
||||
shake_.delay = 2;
|
||||
shake_.lenght = 8;
|
||||
@@ -46,6 +40,8 @@ void GameLogo::init()
|
||||
shake_.counter = shake_.delay;
|
||||
shake_.origin = xp;
|
||||
|
||||
zoom_ = 3.0f;
|
||||
|
||||
// Inicializa el bitmap de 'Coffee'
|
||||
coffee_sprite_->setPosX(xp);
|
||||
coffee_sprite_->setPosY(y_ - coffee_texture_->getHeight() - desp);
|
||||
@@ -90,6 +86,9 @@ void GameLogo::init()
|
||||
dust_left_sprite_->setPosY(y_);
|
||||
dust_left_sprite_->setWidth(16);
|
||||
dust_left_sprite_->setHeight(16);
|
||||
|
||||
// Inicializa el bitmap de 'Arcade Edition'
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
}
|
||||
|
||||
// Pinta la clase en pantalla
|
||||
@@ -99,8 +98,10 @@ void GameLogo::render()
|
||||
coffee_sprite_->render();
|
||||
crisis_sprite_->render();
|
||||
|
||||
if (status_ == Status::FINISHED)
|
||||
if (arcade_edition_status_ != Status::DISABLED)
|
||||
{
|
||||
arcade_edition_sprite_->render();
|
||||
}
|
||||
|
||||
// Dibuja el polvillo del logo
|
||||
dust_right_sprite_->render();
|
||||
@@ -110,17 +111,18 @@ void GameLogo::render()
|
||||
// Actualiza la lógica de la clase
|
||||
void GameLogo::update()
|
||||
{
|
||||
switch (status_)
|
||||
switch (coffee_crisis_status_)
|
||||
{
|
||||
case Status::MOVING:
|
||||
{
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
|
||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||
// Si los objetos han llegado a su destino, cambia el estado
|
||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished())
|
||||
{
|
||||
status_ = Status::SHAKING;
|
||||
coffee_crisis_status_ = Status::SHAKING;
|
||||
arcade_edition_status_ = Status::MOVING;
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||
@@ -151,7 +153,7 @@ void GameLogo::update()
|
||||
{
|
||||
coffee_sprite_->setPosX(shake_.origin);
|
||||
crisis_sprite_->setPosX(shake_.origin + 15);
|
||||
status_ = Status::FINISHED;
|
||||
coffee_crisis_status_ = Status::FINISHED;
|
||||
}
|
||||
|
||||
dust_right_sprite_->update();
|
||||
@@ -171,19 +173,37 @@ void GameLogo::update()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (arcade_edition_status_)
|
||||
{
|
||||
case Status::MOVING:
|
||||
{
|
||||
zoom_ -= 0.1f;
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
if (zoom_ <= 1.0f)
|
||||
{
|
||||
arcade_edition_status_ = Status::FINISHED;
|
||||
zoom_ = 1.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Activa la clase
|
||||
void GameLogo::enable()
|
||||
{
|
||||
init();
|
||||
status_ = Status::MOVING;
|
||||
coffee_crisis_status_ = Status::MOVING;
|
||||
}
|
||||
|
||||
// Indica si ha terminado la animación
|
||||
bool GameLogo::hasFinished() const
|
||||
{
|
||||
return status_ == Status::FINISHED;
|
||||
return coffee_crisis_status_ == Status::FINISHED && arcade_edition_status_ == Status::FINISHED;
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
@@ -192,6 +212,7 @@ void GameLogo::reLoad()
|
||||
dust_texture_->reLoad();
|
||||
coffee_texture_->reLoad();
|
||||
crisis_texture_->reLoad();
|
||||
arcade_edition_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Calcula el desplazamiento vertical inicial
|
||||
|
||||
@@ -43,11 +43,13 @@ private:
|
||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||
|
||||
// Variables
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
float zoom_; // Zoom aplicado al texto "ARCADE EDITION"
|
||||
|
||||
Status status_; // Estado en el que se encuentra la clase
|
||||
Shake shake_; // Estructura para generar el efecto de agitación
|
||||
Status coffee_crisis_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "COFFEE CRISIS"
|
||||
Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION"
|
||||
Shake shake_; // Estructura para generar el efecto de agitación
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "global_inputs.h"
|
||||
#include <string> // Para operator+, string
|
||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include <string> // Para operator+, string
|
||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "asset.h"
|
||||
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
|
||||
#include "lang.h" // Para getText
|
||||
#include "notifier.h" // Para Notifier
|
||||
@@ -13,18 +14,8 @@
|
||||
namespace globalInputs
|
||||
{
|
||||
// Variables
|
||||
std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init()
|
||||
{
|
||||
const auto num_inputs = Input::get()->getNumControllers() + 1;
|
||||
service_pressed_counter.reserve(num_inputs);
|
||||
for (int i = 0; i < num_inputs; ++i)
|
||||
{
|
||||
service_pressed_counter.push_back(0);
|
||||
}
|
||||
}
|
||||
int service_pressed_counter = 0;
|
||||
bool service_pressed = false;
|
||||
|
||||
// Termina
|
||||
void quit(section::Options code)
|
||||
@@ -33,11 +24,13 @@ namespace globalInputs
|
||||
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
||||
if (code_found)
|
||||
{
|
||||
// Si la notificación de salir está activa, cambia de sección
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = code;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si la notificación de salir no está activa, muestra la notificación
|
||||
#ifdef ARCADE
|
||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
|
||||
@@ -71,6 +64,50 @@ namespace globalInputs
|
||||
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLangFile(lang::Code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return Asset::get()->get("ba_BA.txt");
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return Asset::get()->get("es_ES.txt");
|
||||
break;
|
||||
default:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene una cadena a partir de un lang::Code
|
||||
std::string getLangName(lang::Code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return "ba_BA";
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return "es_ES";
|
||||
break;
|
||||
default:
|
||||
return "en_UK";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el idioma
|
||||
void changeLang()
|
||||
{
|
||||
options.game.language = lang::change(options.game.language);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
section::name = section::Name::INIT;
|
||||
section::options = section::Options::RELOAD;
|
||||
Notifier::get()->showText({getLangName(options.game.language)});
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check()
|
||||
{
|
||||
@@ -125,6 +162,13 @@ namespace globalInputs
|
||||
return;
|
||||
}
|
||||
|
||||
// Idioma
|
||||
if (Input::get()->checkInput(InputType::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
changeLang();
|
||||
return;
|
||||
}
|
||||
|
||||
// Shaders
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
@@ -143,17 +187,9 @@ namespace globalInputs
|
||||
// OnScreenHelp
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
service_pressed_counter[0]++;
|
||||
|
||||
if (service_pressed_counter[0] >= 3000)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
service_pressed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
|
||||
// Mandos
|
||||
@@ -203,18 +239,30 @@ namespace globalInputs
|
||||
// OnScreenHelp
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
service_pressed_counter[i + 1]++;
|
||||
|
||||
if (service_pressed_counter[i + 1] >= 3000)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
}
|
||||
service_pressed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza variables
|
||||
void update()
|
||||
{
|
||||
if (service_pressed)
|
||||
{
|
||||
++service_pressed_counter;
|
||||
if (service_pressed_counter >= 200)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
service_pressed_counter = 0;
|
||||
}
|
||||
|
||||
service_pressed = false;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <vector>
|
||||
namespace globalInputs
|
||||
{
|
||||
extern std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init();
|
||||
extern int service_pressed_counter;
|
||||
extern bool service_pressed;
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check();
|
||||
|
||||
// Actualiza variables
|
||||
void update();
|
||||
}
|
||||
@@ -77,6 +77,9 @@ void HiScoreTable::update()
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background_->update();
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ enum class InputType : int
|
||||
VIDEO_SHADERS,
|
||||
RESET,
|
||||
MUTE,
|
||||
CHANGE_LANG,
|
||||
SHOWINFO,
|
||||
CONFIG,
|
||||
SWAP_CONTROLLERS,
|
||||
|
||||
@@ -27,18 +27,16 @@ Instructions::Instructions()
|
||||
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::STATIC)),
|
||||
fade_(std::make_unique<Fade>())
|
||||
{
|
||||
// Crea un backbuffer para el renderizador
|
||||
// Configura las texturas
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea una textura para el texto fijo
|
||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
view_ = {0, 0, param.game.width, param.game.height};
|
||||
view_ = param.game.game_area.rect;
|
||||
|
||||
// Inicializa objetos
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
@@ -211,11 +209,16 @@ void Instructions::update()
|
||||
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||
}
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
|
||||
|
||||
@@ -382,6 +382,9 @@ void Intro::update()
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "item.h"
|
||||
#include <algorithm> // para std::clamp
|
||||
#include <stdlib.h> // para rand
|
||||
#include "animated_sprite.h" // para SpriteAnimated
|
||||
#include "param.h" // para param
|
||||
class Texture;
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para clamp
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
class Texture; // lines 6-6
|
||||
|
||||
Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
@@ -73,8 +73,6 @@ void Item::render()
|
||||
}
|
||||
}
|
||||
|
||||
#include <algorithm> // Necesario para std::clamp
|
||||
|
||||
void Item::move()
|
||||
{
|
||||
floor_collision_ = false;
|
||||
|
||||
@@ -40,4 +40,12 @@ namespace lang
|
||||
{
|
||||
return texts.at(index);
|
||||
}
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang)
|
||||
{
|
||||
auto index = static_cast<int>(current_lang);
|
||||
index = (index + 1) % 3;
|
||||
return static_cast<Code>(index);
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,7 @@ namespace lang
|
||||
|
||||
// Obtiene la cadena de texto del indice
|
||||
std::string getText(int index);
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang);
|
||||
}
|
||||
@@ -59,6 +59,7 @@ Logo::~Logo()
|
||||
{
|
||||
jail_texture_->setColor(255, 255, 255);
|
||||
since_texture_->setColor(255, 255, 255);
|
||||
JA_PauseChannel(-1);
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
@@ -113,6 +114,11 @@ void Logo::checkInput()
|
||||
// Gestiona el logo de JAILGAME
|
||||
void Logo::updateJAILGAMES()
|
||||
{
|
||||
if (counter_ == 30)
|
||||
{
|
||||
JA_PlaySound(Resource::get()->getSound("logo.wav"));
|
||||
}
|
||||
|
||||
if (counter_ > 30)
|
||||
{
|
||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||
@@ -195,6 +201,9 @@ void Logo::update()
|
||||
{
|
||||
section::name = section::Name::INTRO;
|
||||
}
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,15 @@
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include "resource.h"
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
||||
{
|
||||
Notifier::notifier_ = new Notifier(icon_file, text, sound_file);
|
||||
Notifier::notifier_ = new Notifier(icon_file, text);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
@@ -33,21 +34,14 @@ Notifier *Notifier::get()
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr),
|
||||
text_(text),
|
||||
bg_color_(param.notification.color),
|
||||
wait_time_(150),
|
||||
stack_(false),
|
||||
has_icons_(!icon_file.empty()),
|
||||
sound_(JA_LoadSound(sound_file.c_str())) {}
|
||||
|
||||
// Destructor
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
JA_DeleteSound(sound_);
|
||||
}
|
||||
has_icons_(!icon_file.empty()) {}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notifier::render()
|
||||
@@ -80,8 +74,9 @@ void Notifier::update()
|
||||
if (param.notification.sound)
|
||||
{
|
||||
if (notifications_[i].status == NotificationStatus::RISING)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
JA_PlaySound(sound_);
|
||||
{
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ private:
|
||||
std::vector<Notification> notifications_; // La lista de notificaciones activas
|
||||
bool stack_; // Indica si las notificaciones se apilan
|
||||
bool has_icons_; // Indica si el notificador tiene textura para iconos
|
||||
JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
@@ -73,14 +72,14 @@ private:
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||
|
||||
// Constructor
|
||||
Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
Notifier(std::string icon_file, std::shared_ptr<Text> text);
|
||||
|
||||
// Destructor
|
||||
~Notifier();
|
||||
~Notifier() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
||||
static void destroy();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "path_sprite.h"
|
||||
#include <cmath> // Para abs
|
||||
#include <stdlib.h> // Para abs
|
||||
#include <cstdlib> // Para abs
|
||||
#include <functional> // Para function
|
||||
#include <utility> // Para move
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#include "player.h"
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para max, min
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "input.h" // Para InputType
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
||||
#include "texture.h" // Para Texture
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para clamp, max, min
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "input.h" // Para InputType
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
||||
@@ -164,7 +162,7 @@ void Player::move()
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float min_x = param.game.play_area.rect.x - 5;
|
||||
const float min_x = play_area_.x - 5;
|
||||
const float max_x = play_area_.w + 5 - WIDTH_;
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
|
||||
@@ -174,13 +172,13 @@ void Player::move()
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
||||
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
if ((player_sprite_->getPosX() < play_area_.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
{
|
||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||
}
|
||||
|
||||
// Si el cadaver toca el suelo cambia el estado
|
||||
if (player_sprite_->getPosY() > param.game.play_area.rect.h - HEIGHT_)
|
||||
if (player_sprite_->getPosY() > play_area_.h - HEIGHT_)
|
||||
{
|
||||
if (player_sprite_->getVelY() < 2.0f)
|
||||
{
|
||||
@@ -194,7 +192,7 @@ void Player::move()
|
||||
else
|
||||
{
|
||||
// Decrementa las velocidades de rebote
|
||||
player_sprite_->setPosY(param.game.play_area.rect.h - HEIGHT_);
|
||||
player_sprite_->setPosY(play_area_.h - HEIGHT_);
|
||||
player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f);
|
||||
player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f);
|
||||
}
|
||||
@@ -224,6 +222,41 @@ void Player::move()
|
||||
setPlayingState(PlayerState::GAME_OVER);
|
||||
break;
|
||||
}
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
pos_x_ += vel_x_ / 2.0f;
|
||||
if (vel_x_ > 0)
|
||||
{
|
||||
// setInputPlaying(InputType::RIGHT);
|
||||
if (pos_x_ > param.game.game_area.rect.w - WIDTH_)
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.w - WIDTH_;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::LEFT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// setInputPlaying(InputType::LEFT);
|
||||
if (pos_x_ < param.game.game_area.rect.x)
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.x;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
if (pos_x_ > param.game.game_area.center_x - WIDTH_ / 2)
|
||||
{
|
||||
setWalkingState(PlayerState::WALKING_LEFT);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
}
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -254,6 +287,7 @@ void Player::setAnimation()
|
||||
case PlayerState::PLAYING:
|
||||
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
|
||||
case PlayerState::LEAVING_SCREEN:
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
const std::string a_walking = walking_state_ == PlayerState::WALKING_STOP ? "stand" : "walk";
|
||||
@@ -470,6 +504,11 @@ void Player::setPlayingState(PlayerState state)
|
||||
setScoreboardMode(ScoreboardMode::GAME_COMPLETED);
|
||||
break;
|
||||
}
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
vel_x_ = (walking_state_ == PlayerState::WALKING_RIGHT) ? BASE_SPEED_ : -BASE_SPEED_;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -615,9 +654,13 @@ void Player::decEnterNameCounter()
|
||||
{
|
||||
enter_name_counter_ = param.game.enter_name_seconds;
|
||||
if (playing_state_ == PlayerState::ENTERING_NAME)
|
||||
{
|
||||
setPlayingState(PlayerState::CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPlayingState(PlayerState::LEAVING_SCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,7 +668,9 @@ void Player::decEnterNameCounter()
|
||||
int Player::getRecordNamePos() const
|
||||
{
|
||||
if (enter_name_)
|
||||
{
|
||||
return enter_name_->getPosition();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "enter_name.h" // Para EnterName
|
||||
#include "utils.h" // Para Circle
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "options.h"
|
||||
|
||||
class Texture; // lines 12-12
|
||||
enum class InputType : int; // lines 13-13
|
||||
enum class ScoreboardMode; // lines 14-14
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "enter_name.h" // Para EnterName
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture; // lines 13-13
|
||||
enum class InputType : int; // lines 14-14
|
||||
enum class ScoreboardMode; // lines 15-15
|
||||
|
||||
// Estados del jugador
|
||||
enum class PlayerState
|
||||
@@ -40,6 +40,7 @@ enum class PlayerState
|
||||
CELEBRATING, // Poniendo pose de victoria
|
||||
ENTERING_NAME_GAME_COMPLETED, // Poniendo nombre en el tramo final del juego
|
||||
LEAVING_SCREEN, // Moviendose fuera de la pantalla
|
||||
CREDITS, // Estado para los creditos del juego
|
||||
};
|
||||
|
||||
// Clase Player
|
||||
|
||||
@@ -34,6 +34,24 @@ Resource *Resource::get()
|
||||
|
||||
// Constructor
|
||||
Resource::Resource()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear()
|
||||
{
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
animations_.clear();
|
||||
demos_.clear();
|
||||
}
|
||||
|
||||
// Carga todos los recursos
|
||||
void Resource::load()
|
||||
{
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
@@ -48,6 +66,13 @@ Resource::Resource()
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Recarga todos los recursos
|
||||
void Resource::reload()
|
||||
{
|
||||
clear();
|
||||
load();
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||
{
|
||||
@@ -307,3 +332,33 @@ void Resource::createText()
|
||||
printWithDots("Text : ", resource.first, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Vacía el vector de sonidos
|
||||
void Resource::clearSounds()
|
||||
{
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
|
||||
for (auto &sound : sounds_)
|
||||
{
|
||||
if (sound.sound)
|
||||
{
|
||||
JA_DeleteSound(sound.sound);
|
||||
sound.sound = nullptr;
|
||||
}
|
||||
}
|
||||
sounds_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
|
||||
// Vacía el vector de musicas
|
||||
void Resource::clearMusics()
|
||||
{
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
|
||||
for (auto &music : musics_)
|
||||
{
|
||||
if (music.music)
|
||||
{
|
||||
JA_DeleteMusic(music.music);
|
||||
music.music = nullptr;
|
||||
}
|
||||
}
|
||||
musics_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
@@ -117,6 +117,18 @@ private:
|
||||
// Crea los objetos de texto
|
||||
void createText();
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void clear();
|
||||
|
||||
// Carga todos los recursos
|
||||
void load();
|
||||
|
||||
// Vacía el vector de sonidos
|
||||
void clearSounds();
|
||||
|
||||
// Vacía el vector de musicas
|
||||
void clearMusics();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -155,4 +167,7 @@ public:
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||
DemoData &getDemoData(int index);
|
||||
|
||||
// Recarga todos los recursos
|
||||
void reload();
|
||||
};
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "asset.h" // Para Asset
|
||||
#include "dbgtxt.h" // Para dbg_print
|
||||
#include "global_inputs.h" // Para service_pressed_counter
|
||||
#include "jail_shader.h" // Para init, render
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "on_screen_help.h" // Para OnScreenHelp
|
||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||
@@ -89,10 +88,10 @@ void Screen::blit()
|
||||
fps_counter_++;
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
doFlash();
|
||||
renderFlash();
|
||||
|
||||
// Atenua la pantalla
|
||||
doAttenuate();
|
||||
renderAttenuate();
|
||||
|
||||
// Muestra la ayuda por pantalla
|
||||
OnScreenHelp::get()->render();
|
||||
@@ -201,7 +200,8 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
#ifndef NO_SHADERS
|
||||
std::ifstream f(Asset::get()->get("crtpi.glsl").c_str());
|
||||
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
shader::init(window_, shader_canvas_, source.c_str());
|
||||
@@ -255,6 +255,7 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
void Screen::update()
|
||||
{
|
||||
updateShakeEffect();
|
||||
updateFlash();
|
||||
Notifier::get()->update();
|
||||
updateFPS();
|
||||
OnScreenHelp::get()->update();
|
||||
@@ -313,21 +314,26 @@ void Screen::flash(Color color, int lenght)
|
||||
}
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void Screen::doFlash()
|
||||
void Screen::renderFlash()
|
||||
{
|
||||
if (flash_effect_.enabled)
|
||||
{
|
||||
// Dibuja el color del flash en la textura
|
||||
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica del efecto
|
||||
// Actualiza el efecto de flash
|
||||
void Screen::updateFlash()
|
||||
{
|
||||
if (flash_effect_.enabled)
|
||||
{
|
||||
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Atenua la pantalla
|
||||
void Screen::doAttenuate()
|
||||
void Screen::renderAttenuate()
|
||||
{
|
||||
if (attenuate_effect_)
|
||||
{
|
||||
@@ -387,7 +393,7 @@ void Screen::renderInfo()
|
||||
dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0);
|
||||
|
||||
// Contador de service_pressed_counter
|
||||
if (const int counter = globalInputs::service_pressed_counter[0]; counter > 0)
|
||||
if (const int counter = globalInputs::service_pressed_counter; counter > 0)
|
||||
dbg_print(0, 8, std::to_string(counter).c_str(), 255, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,11 +82,14 @@ private:
|
||||
// Actualiza la logica para agitar la pantalla
|
||||
void updateShakeEffect();
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void doFlash();
|
||||
// Dibuja el efecto de flash en la pantalla
|
||||
void renderFlash();
|
||||
|
||||
// Actualiza el efecto de flash
|
||||
void updateFlash();
|
||||
|
||||
// Atenua la pantalla
|
||||
void doAttenuate();
|
||||
void renderAttenuate();
|
||||
|
||||
// Calcula los frames por segundo
|
||||
void updateFPS();
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace section
|
||||
HI_SCORE_TABLE = 5,
|
||||
GAME_DEMO = 6,
|
||||
INSTRUCTIONS = 7,
|
||||
QUIT = 8,
|
||||
CREDITS = 8,
|
||||
QUIT = 9,
|
||||
};
|
||||
|
||||
// Opciones para la sección
|
||||
@@ -26,7 +27,8 @@ namespace section
|
||||
QUIT_WITH_KEYBOARD = 4,
|
||||
QUIT_WITH_CONTROLLER = 5,
|
||||
QUIT_FROM_EVENT = 6,
|
||||
NONE = 7,
|
||||
RELOAD = 7,
|
||||
NONE = 8,
|
||||
};
|
||||
|
||||
// Variables para el Attract Mode
|
||||
|
||||
@@ -19,31 +19,7 @@ Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_);
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getX() const
|
||||
{
|
||||
return pos_.x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getY() const
|
||||
{
|
||||
return pos_.y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth() const
|
||||
{
|
||||
return pos_.w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight() const
|
||||
{
|
||||
return pos_.h;
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
@@ -60,84 +36,6 @@ void Sprite::setPosition(SDL_Point p)
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPosition(SDL_Rect r)
|
||||
{
|
||||
pos_ = r;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setX(int x)
|
||||
{
|
||||
pos_.x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setY(int y)
|
||||
{
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
pos_.w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
pos_.h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip() const
|
||||
{
|
||||
return sprite_clip_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
sprite_clip_ = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
sprite_clip_ = (SDL_Rect){x, y, w, h};
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
std::shared_ptr<Texture> Sprite::getTexture() const
|
||||
{
|
||||
return texture_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
texture_ = texture;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getPosition() const
|
||||
{
|
||||
return pos_;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incX(int value)
|
||||
{
|
||||
pos_.x += value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incY(int value)
|
||||
{
|
||||
pos_.y += value;
|
||||
}
|
||||
|
||||
// Reinicia las variables a cero
|
||||
void Sprite::clear()
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ protected:
|
||||
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
|
||||
SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
double zoom_ = 1.0f; // Zoom aplicado a la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -28,40 +29,43 @@ public:
|
||||
// Reinicia las variables a cero
|
||||
virtual void clear();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getX() const;
|
||||
int getY() const;
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
// Obtiene la posición y el tamaño
|
||||
int getX() const { return pos_.x; }
|
||||
int getY() const { return pos_.y; }
|
||||
int getWidth() const { return pos_.w; }
|
||||
int getHeight() const { return pos_.h; }
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getPosition() const;
|
||||
SDL_Rect getPosition() const { return pos_; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setX(int x);
|
||||
void setY(int y);
|
||||
void setWidth(int w);
|
||||
void setHeight(int h);
|
||||
// Establece la posición y el tamaño
|
||||
void setX(int x) { pos_.x = x; }
|
||||
void setY(int y) { pos_.y = y; }
|
||||
void setWidth(int w) { pos_.w = w; }
|
||||
void setHeight(int h) { pos_.h = h; }
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(SDL_Point p);
|
||||
void setPosition(SDL_Rect r);
|
||||
void setPosition(SDL_Rect r) { pos_ = r; }
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incX(int value);
|
||||
void incY(int value);
|
||||
// Establece el nivel de zoom
|
||||
void setZoom(float zoom) { zoom_ = zoom; }
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip() const;
|
||||
// Aumenta o disminuye la posición
|
||||
void incX(int value) { pos_.x += value; }
|
||||
void incY(int value) { pos_.y += value; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
// Obtiene el rectangulo que se dibuja de la textura
|
||||
SDL_Rect getSpriteClip() const { return sprite_clip_; }
|
||||
|
||||
// Obten el valor de la variable
|
||||
std::shared_ptr<Texture> getTexture() const;
|
||||
// Establece el rectangulo que se dibuja de la textura
|
||||
void setSpriteClip(SDL_Rect rect) { sprite_clip_ = rect; }
|
||||
void setSpriteClip(int x, int y, int w, int h) { sprite_clip_ = (SDL_Rect){x, y, w, h}; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(std::shared_ptr<Texture> texture);
|
||||
// Obtiene un puntero a la textura
|
||||
std::shared_ptr<Texture> getTexture() const { return texture_; }
|
||||
|
||||
// Establece la textura a utilizar
|
||||
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "stage.h"
|
||||
#include <vector>
|
||||
#include <algorithm> // Para min
|
||||
#include <vector> // Para vector
|
||||
|
||||
namespace Stage
|
||||
{
|
||||
|
||||
@@ -264,4 +264,13 @@ void Text::reLoadTexture()
|
||||
void Text::setFixedWidth(bool value)
|
||||
{
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Establece una paleta
|
||||
void Text::setPalette(int number)
|
||||
{
|
||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
sprite_->getTexture()->setPalette(number);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
}
|
||||
@@ -78,4 +78,7 @@ public:
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void setFixedWidth(bool value);
|
||||
|
||||
// Establece una paleta
|
||||
void setPalette(int number);
|
||||
};
|
||||
@@ -190,8 +190,16 @@ void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, dou
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
// Calcula el zoom y las coordenadas
|
||||
if (zoomH != 1.0f || zoomW != 1.0f)
|
||||
{
|
||||
renderQuad.x = renderQuad.x + (renderQuad.w / 2);
|
||||
renderQuad.y = renderQuad.y + (renderQuad.h / 2);
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
renderQuad.x = renderQuad.x - (renderQuad.w / 2);
|
||||
renderQuad.y = renderQuad.y - (renderQuad.h / 2);
|
||||
}
|
||||
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer_, texture_, clip, &renderQuad, angle, center, flip);
|
||||
|
||||
@@ -29,15 +29,15 @@
|
||||
Title::Title()
|
||||
: text_(Resource::get()->getText("smb2")),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM)),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
||||
define_buttons_(std::make_unique<DefineButtons>()),
|
||||
num_controllers_(Input::get()->getNumControllers())
|
||||
{
|
||||
// Configura objetos
|
||||
game_logo_->enable();
|
||||
mini_logo_sprite_->setX(param.game.game_area.center_x - mini_logo_sprite_->getWidth() / 2);
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
@@ -69,7 +69,10 @@ void Title::update()
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Comprueba el fade_ y si se ha acabado
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Comprueba el fundido y si se ha acabado
|
||||
fade_->update();
|
||||
if (fade_->hasEnded())
|
||||
{
|
||||
|
||||
@@ -44,7 +44,6 @@ private:
|
||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||
std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
|
||||
std::unique_ptr<Sprite> mini_logo_sprite_; // Sprite con el logo de JailGames mini
|
||||
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user