Compare commits
11 Commits
b4e76a4c7d
...
v1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a3182fc74 | |||
| 5098ed1638 | |||
| f63ff07397 | |||
| 58f9841f71 | |||
| fd1fc0b582 | |||
| 770b06f2da | |||
| 33ad51e1c2 | |||
| 0a16c1cd0e | |||
| e8406c87b0 | |||
| ca5adf9433 | |||
| e753f6fbdb |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.DS_store
|
.DS_store
|
||||||
.vscode
|
.vscode
|
||||||
super_pang_clone
|
super_pang_clone*
|
||||||
bin
|
bin/*
|
||||||
|
info.plist*
|
||||||
24
Makefile
24
Makefile
@@ -1,15 +1,11 @@
|
|||||||
executable = super_pang_clone
|
executable = super_pang_clone
|
||||||
source = source/*.cpp
|
source = source/*.cpp
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
g++ $(source) -std=c++11 -Wall -O2 -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o $(executable).exe
|
||||||
if not exist bin\ (mkdir bin)
|
strip -s -R .comment -R .gnu.version $(executable).exe --strip-unneeded
|
||||||
g++ $(source) -std=c++11 -Wall -O2 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o $(executable).exe
|
macos:
|
||||||
strip -s -R .comment -R .gnu.version $(executable).exe --strip-unneeded
|
g++ $(source) -std=c++11 -Wall -O2 -lSDL2 -ffunction-sections -fdata-sections -o $(executable)_macos
|
||||||
macos:
|
linux:
|
||||||
mkdir -p bin
|
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(executable)_linux
|
||||||
g++ $(source) -std=c++11 -Wall -O2 -lSDL2 -lSDL2_image -lSDL2_mixer -ffunction-sections -fdata-sections -o $(executable)_macos
|
|
||||||
linux:
|
|
||||||
mkdir -p bin
|
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -lSDL2_image -lSDL2_mixer -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(executable)_linux
|
|
||||||
strip -s -R .comment -R .gnu.version $(executable)_linux --strip-unneeded
|
strip -s -R .comment -R .gnu.version $(executable)_linux --strip-unneeded
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
The assets in this repository are created at Sparklin Labs by Pixel-boy: https://twitter.com/2pblog1
|
The assets in this repository are created at Sparklin Labs by Pixel-boy: https://twitter.com/2pblog1
|
||||||
Their creation is funded by your support on Patreon (http://patreon.com/SparklinLabs) and through donations (http://sparklinlabs.itch.io/superpowers) Thanks!
|
Their creation is funded by your support on Patreon (http://patreon.com/SparklinLabs) and through donations (http://sparklinlabs.itch.io/superpowers) Thanks!
|
||||||
|
|
||||||
Originally downloaded from https://github.com/sparklinlabs/superpowers-asset-packs
|
Originally downloaded from https://github.com/sparklinlabs/superpowers-asset-packs
|
||||||
|
|
||||||
Attribution/Licensing:
|
Attribution/Licensing:
|
||||||
Creative Commons Zero: http://creativecommons.org/publicdomain/zero/1.0/
|
Creative Commons Zero: http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
Attribution is not required but appreciated. Placing a link to http://superpowers-html5.com/ somewhere would be awesome :)
|
Attribution is not required but appreciated. Placing a link to http://superpowers-html5.com/ somewhere would be awesome :)
|
||||||
|
|
||||||
Also available at http://opengameart.org/content/superpowers-assets-bitmap-fonts
|
Also available at http://opengameart.org/content/superpowers-assets-bitmap-fonts
|
||||||
@@ -1,127 +1,127 @@
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
NOKIA CELLPHONE FC SMALL
|
NOKIA CELLPHONE FC SMALL
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Info
|
Info
|
||||||
====
|
====
|
||||||
|
|
||||||
This is a font that emulates the bitmap font used by Nokia-based cell phones.
|
This is a font that emulates the bitmap font used by Nokia-based cell phones.
|
||||||
As the name implies ("Nokia Cellphone Small"), this is the "Small" font - used
|
As the name implies ("Nokia Cellphone Small"), this is the "Small" font - used
|
||||||
on some menus, not the data fields (which it used a "big" font).
|
on some menus, not the data fields (which it used a "big" font).
|
||||||
|
|
||||||
This was done because 1) I needed to use it on some projects and 2) I saw lots
|
This was done because 1) I needed to use it on some projects and 2) I saw lots
|
||||||
of people asking for a font like this. So I had some experience in creating
|
of people asking for a font like this. So I had some experience in creating
|
||||||
bitmap-emulating truetype fonts (that is, a truetype, vector-based font that
|
bitmap-emulating truetype fonts (that is, a truetype, vector-based font that
|
||||||
works as if it was a bitmap-based font) and then I decided to do this thingie.
|
works as if it was a bitmap-based font) and then I decided to do this thingie.
|
||||||
I send a message to my Nokia 6120 cell phone with every characters that the
|
I send a message to my Nokia 6120 cell phone with every characters that the
|
||||||
cell phone had and then scanned the cellphone screens to rebuild it using
|
cell phone had and then scanned the cellphone screens to rebuild it using
|
||||||
fontlab 3 and 4.
|
fontlab 3 and 4.
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
How to use (read it please)
|
How to use (read it please)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
This is a "bitmap" font, a truetype font that emulates real bitmap fonts (with
|
This is a "bitmap" font, a truetype font that emulates real bitmap fonts (with
|
||||||
no antialias, that is). It should be used at the same point size (8) or
|
no antialias, that is). It should be used at the same point size (8) or
|
||||||
multiples thereof (16, 24, 32) to produce the best result. When used properly,
|
multiples thereof (16, 24, 32) to produce the best result. When used properly,
|
||||||
it renders as the font found on the Nokia cellphones software.
|
it renders as the font found on the Nokia cellphones software.
|
||||||
|
|
||||||
Here's some specific hints:
|
Here's some specific hints:
|
||||||
|
|
||||||
Photoshop 5: use it as a normal font, with no antialias. The underline is way
|
Photoshop 5: use it as a normal font, with no antialias. The underline is way
|
||||||
too low, but I can't fix it.
|
too low, but I can't fix it.
|
||||||
|
|
||||||
Photoshop 7: use it as a normal font, with no antialias. If you're
|
Photoshop 7: use it as a normal font, with no antialias. If you're
|
||||||
experiencing variating vertical positions for the underline, use a fixed
|
experiencing variating vertical positions for the underline, use a fixed
|
||||||
leading/line spacing (10, for example) instead of the "auto" mode.
|
leading/line spacing (10, for example) instead of the "auto" mode.
|
||||||
|
|
||||||
Flash: use it normally. It will not produce antialias as long as you position
|
Flash: use it normally. It will not produce antialias as long as you position
|
||||||
your textfield on "rounded" pixels, related to the main flash stage. To do
|
your textfield on "rounded" pixels, related to the main flash stage. To do
|
||||||
this, draw/type your textfield on stage, go to the "Info" panel, and be sure
|
this, draw/type your textfield on stage, go to the "Info" panel, and be sure
|
||||||
the topmost axis is selected (little black box) and its X and Y position are
|
the topmost axis is selected (little black box) and its X and Y position are
|
||||||
set to a position with no decimal points (e.g., 10 and 8 instead of 10.1 and
|
set to a position with no decimal points (e.g., 10 and 8 instead of 10.1 and
|
||||||
8.5). You can embed the fonts too, *NO* antialias will occur as long as you use
|
8.5). You can embed the fonts too, *NO* antialias will occur as long as you use
|
||||||
it on the right positions.
|
it on the right positions.
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Modifications
|
Modifications
|
||||||
=============
|
=============
|
||||||
|
|
||||||
* VERSION 2.2 - A minor correction on wordspacing which got increased on the
|
* VERSION 2.2 - A minor correction on wordspacing which got increased on the
|
||||||
last version. Now it's correct again (from 5 to 4 pixels).
|
last version. Now it's correct again (from 5 to 4 pixels).
|
||||||
|
|
||||||
* VERSION 2.1 - Small additions, due to a BIG help by Panu Tuominen from
|
* VERSION 2.1 - Small additions, due to a BIG help by Panu Tuominen from
|
||||||
PanuWorld (www.panuworld.net). Added characters:
|
PanuWorld (www.panuworld.net). Added characters:
|
||||||
|
|
||||||
<20> <20> - Y/y with acute
|
<20> <20> - Y/y with acute
|
||||||
<20> <20> - A/a with ring
|
<20> <20> - A/a with ring
|
||||||
<20> <20> - Y/y with diaeresis (Y being *done from certain clues* - not sure it's right, but it probably is)
|
<20> <20> - Y/y with diaeresis (Y being *done from certain clues* - not sure it's right, but it probably is)
|
||||||
` - grave accent (unicode 0060)
|
` - grave accent (unicode 0060)
|
||||||
|
|
||||||
* VERSION 2.0 - Took it to a new metric system (more fit for "bitmap fonts"),
|
* VERSION 2.0 - Took it to a new metric system (more fit for "bitmap fonts"),
|
||||||
fixed lots of small polygon discrepancies, and fixed some Flash filling holes
|
fixed lots of small polygon discrepancies, and fixed some Flash filling holes
|
||||||
bugs. I've changed the leading too; since there's no standard leading on the
|
bugs. I've changed the leading too; since there's no standard leading on the
|
||||||
cellphone menus I've chosen one of my own.
|
cellphone menus I've chosen one of my own.
|
||||||
|
|
||||||
Also, since I got a new Nokia (3310) cellphone, there's ton of new characters
|
Also, since I got a new Nokia (3310) cellphone, there's ton of new characters
|
||||||
available that I have added to the font. There are now 164 glyphs on the Nokia
|
available that I have added to the font. There are now 164 glyphs on the Nokia
|
||||||
cellphone truetype font. Here's what have been added:
|
cellphone truetype font. Here's what have been added:
|
||||||
|
|
||||||
<20> <20> - A/a with diaeresis
|
<20> <20> - A/a with diaeresis
|
||||||
<20> <20> - E/e with grave
|
<20> <20> - E/e with grave
|
||||||
<20> <20> - E/e with diaeresis
|
<20> <20> - E/e with diaeresis
|
||||||
<20> <20> - I/i with diaeresis
|
<20> <20> - I/i with diaeresis
|
||||||
<20> <20> - I/i with circumflex
|
<20> <20> - I/i with circumflex
|
||||||
<20> <20> - O/o with grave
|
<20> <20> - O/o with grave
|
||||||
<20> <20> - O/o with diaeresis
|
<20> <20> - O/o with diaeresis
|
||||||
<20> <20> - U/u with grave
|
<20> <20> - U/u with grave
|
||||||
<20> <20> - U/u with circumflex
|
<20> <20> - U/u with circumflex
|
||||||
<20> <20> - N/n with tilde
|
<20> <20> - N/n with tilde
|
||||||
<20> <20> - O/o with slash/stroke
|
<20> <20> - O/o with slash/stroke
|
||||||
* * - G/g with breve (turkish codepage)
|
* * - G/g with breve (turkish codepage)
|
||||||
<20> - currency sign
|
<20> - currency sign
|
||||||
<20> - latin capital letter AE
|
<20> - latin capital letter AE
|
||||||
<20> - latin small letter AE
|
<20> - latin small letter AE
|
||||||
<20> - greek beta (I think)
|
<20> - greek beta (I think)
|
||||||
<20> - Euro
|
<20> - Euro
|
||||||
|
|
||||||
* VERSION 1.4 - Fixed the WORDSPACE and LEADING size. Thanks to Gustavo Rodrigues
|
* VERSION 1.4 - Fixed the WORDSPACE and LEADING size. Thanks to Gustavo Rodrigues
|
||||||
(from www.escritaurbana.com.br) for pointing me my mistakes. I also fixed some
|
(from www.escritaurbana.com.br) for pointing me my mistakes. I also fixed some
|
||||||
mistakes on the documentation (this file).
|
mistakes on the documentation (this file).
|
||||||
|
|
||||||
* VERSION 1.2 - Optimized for Macromedia Flash usage (no hollows) and with
|
* VERSION 1.2 - Optimized for Macromedia Flash usage (no hollows) and with
|
||||||
a MAC TTF version provided by Chris Moritz (members.home.net/fieldofaction3).
|
a MAC TTF version provided by Chris Moritz (members.home.net/fieldofaction3).
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Copyright and stuff
|
Copyright and stuff
|
||||||
===================
|
===================
|
||||||
|
|
||||||
This is a free font/file, distribute as you wish to who you wish. Do NOT sell
|
This is a free font/file, distribute as you wish to who you wish. Do NOT sell
|
||||||
this font within a CD or any other media; it's not yours and you can't make
|
this font within a CD or any other media; it's not yours and you can't make
|
||||||
money of it. You'd rather ask me first via email, I may probably let you do it
|
money of it. You'd rather ask me first via email, I may probably let you do it
|
||||||
as long as it's for a good cause.
|
as long as it's for a good cause.
|
||||||
|
|
||||||
I don't know if the original Nokia font has some copyright which prevents
|
I don't know if the original Nokia font has some copyright which prevents
|
||||||
people from making new fonts based on it. I hope not. Anyways, buy a Nokia,
|
people from making new fonts based on it. I hope not. Anyways, buy a Nokia,
|
||||||
and I think everything's gonna be alright.
|
and I think everything's gonna be alright.
|
||||||
|
|
||||||
Special thanks on this version go out to Carlos B<>la (www.goldenshower.gs) and
|
Special thanks on this version go out to Carlos B<>la (www.goldenshower.gs) and
|
||||||
Diogo Kalil (www.sincolor.com.br) for helping me out with the Mac version of
|
Diogo Kalil (www.sincolor.com.br) for helping me out with the Mac version of
|
||||||
the font. It has been extensively tested to ensure it's as smooth (hint,
|
the font. It has been extensively tested to ensure it's as smooth (hint,
|
||||||
kerning, spacing and aliasing-wise) as the pc one is.
|
kerning, spacing and aliasing-wise) as the pc one is.
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Author
|
Author
|
||||||
======
|
======
|
||||||
|
|
||||||
This font was done by Zeh Fernando on Fontlab 4 (www.fontlab.com) on a PC.
|
This font was done by Zeh Fernando on Fontlab 4 (www.fontlab.com) on a PC.
|
||||||
|
|
||||||
Zeh Fernando
|
Zeh Fernando
|
||||||
zeh@fatorcaos.com.br
|
zeh@fatorcaos.com.br
|
||||||
www.fatorcaos.com.br
|
www.fatorcaos.com.br
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
#include "background.h"
|
#include "background.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Background::Background()
|
Background::Background()
|
||||||
{
|
{
|
||||||
init(0, 0, 0, 0, NULL);
|
init(0, 0, 0, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void Background::init(int x, int y, int w, int h, LTexture *texture)
|
void Background::init(int x, int y, int w, int h, LTexture *texture)
|
||||||
{
|
{
|
||||||
// Establece el alto y el ancho del sprite del fondo
|
// Establece el alto y el ancho del sprite del fondo
|
||||||
mSprite.setWidth(w);
|
mSprite.setWidth(w);
|
||||||
mSprite.setHeight(h);
|
mSprite.setHeight(h);
|
||||||
|
|
||||||
// Establece la posición X,Y del sprite del fondo
|
// Establece la posición X,Y del sprite del fondo
|
||||||
mSprite.setPosX(x);
|
mSprite.setPosX(x);
|
||||||
mSprite.setPosY(y);
|
mSprite.setPosY(y);
|
||||||
|
|
||||||
// Establece la textura donde están los gráficos para el sprite del fondo
|
// Establece la textura donde están los gráficos para el sprite del fondo
|
||||||
mSprite.setTexture(*texture);
|
mSprite.setTexture(*texture);
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
mSprite.setSpriteClip(0, 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setSpriteClip(0, 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el fondo en la pantalla
|
// Pinta el fondo en la pantalla
|
||||||
void Background::render()
|
void Background::render()
|
||||||
{
|
{
|
||||||
mSprite.render();
|
mSprite.render();
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
#ifndef BACKGROUND_H
|
#ifndef BACKGROUND_H
|
||||||
#define BACKGROUND_H
|
#define BACKGROUND_H
|
||||||
|
|
||||||
// Clase para el fondo de pantalla del juego
|
// Clase para el fondo de pantalla del juego
|
||||||
class Background
|
class Background
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Background();
|
Background();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(int x, int y, int w, int h, LTexture *texture);
|
void init(int x, int y, int w, int h, LTexture *texture);
|
||||||
|
|
||||||
// Pinta el fondo en la pantalla
|
// Pinta el fondo en la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Variables
|
// Variables
|
||||||
Sprite mSprite;
|
Sprite mSprite;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,483 +1,483 @@
|
|||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon::Balloon(SDL_Renderer *gRenderer)
|
Balloon::Balloon(SDL_Renderer *gRenderer)
|
||||||
{
|
{
|
||||||
this->gRenderer = gRenderer;
|
this->gRenderer = gRenderer;
|
||||||
|
|
||||||
gBalloonTexture = new LTexture(gRenderer);
|
gBalloonTexture = new LTexture(gRenderer);
|
||||||
|
|
||||||
// Carga los gráficos de los globos
|
// Carga los gráficos de los globos
|
||||||
if (!gBalloonTexture->loadFromFile("media/gfx/balloon.png"))
|
if (!gBalloonTexture->loadFromFile("media/gfx/balloon.png"))
|
||||||
{
|
{
|
||||||
printf("Failed to load balloon texture!\n");
|
printf("Failed to load balloon texture!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
init(0, 0, NO_KIND, BALLON_VELX_POSITIVE, 0);
|
init(0, 0, NO_KIND, BALLON_VELX_POSITIVE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Balloon::~Balloon()
|
Balloon::~Balloon()
|
||||||
{
|
{
|
||||||
gBalloonTexture->free();
|
gBalloonTexture->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void Balloon::init(int x, int y, Uint8 kind, float velx, Uint16 creationtimer)
|
void Balloon::init(int x, int y, Uint8 kind, float velx, Uint16 creationtimer)
|
||||||
{
|
{
|
||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case BALLOON_1:
|
case BALLOON_1:
|
||||||
// Posición inicial
|
// Posición inicial
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 8;
|
mWidth = 8;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
mMaxVelY = 3;
|
mMaxVelY = 3;
|
||||||
mGravity = 0.09;
|
mGravity = 0.09;
|
||||||
mDefaultVelY = 3;
|
mDefaultVelY = 3;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 50;
|
mScore = 50;
|
||||||
|
|
||||||
// Rectangulo con la imagen del sprite
|
// Rectangulo con la imagen del sprite
|
||||||
mSprite.setSpriteClip(37 + 21 + 13, 0, mWidth, mHeight);
|
mSprite.setSpriteClip(37 + 21 + 13, 0, mWidth, mHeight);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BALLOON_2:
|
case BALLOON_2:
|
||||||
// Posición inicial
|
// Posición inicial
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 13;
|
mWidth = 13;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
mMaxVelY = 3;
|
mMaxVelY = 3;
|
||||||
mGravity = 0.10;
|
mGravity = 0.10;
|
||||||
mDefaultVelY = 4;
|
mDefaultVelY = 4;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 100;
|
mScore = 100;
|
||||||
|
|
||||||
// Rectangulo con la imagen del sprite
|
// Rectangulo con la imagen del sprite
|
||||||
mSprite.setSpriteClip(37 + 21, 0, mWidth, mHeight);
|
mSprite.setSpriteClip(37 + 21, 0, mWidth, mHeight);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BALLOON_3:
|
case BALLOON_3:
|
||||||
// Posición inicial
|
// Posición inicial
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 21;
|
mWidth = 21;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
mMaxVelY = 3;
|
mMaxVelY = 3;
|
||||||
mGravity = 0.10;
|
mGravity = 0.10;
|
||||||
mDefaultVelY = 4.5;
|
mDefaultVelY = 4.5;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 200;
|
mScore = 200;
|
||||||
|
|
||||||
// Rectangulo con la imagen del sprite
|
// Rectangulo con la imagen del sprite
|
||||||
mSprite.setSpriteClip(37, 0, mWidth, mHeight);
|
mSprite.setSpriteClip(37, 0, mWidth, mHeight);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BALLOON_4:
|
case BALLOON_4:
|
||||||
// Posición inicial
|
// Posición inicial
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 37;
|
mWidth = 37;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
mMaxVelY = 3;
|
mMaxVelY = 3;
|
||||||
mGravity = 0.10;
|
mGravity = 0.10;
|
||||||
mDefaultVelY = 5;
|
mDefaultVelY = 5;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 400;
|
mScore = 400;
|
||||||
|
|
||||||
// Rectangulo con la imagen del sprite
|
// Rectangulo con la imagen del sprite
|
||||||
mSprite.setSpriteClip(0, 0, mWidth, mHeight);
|
mSprite.setSpriteClip(0, 0, mWidth, mHeight);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Posición inicial
|
// Posición inicial
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 0;
|
mWidth = 0;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
mMaxVelY = 0;
|
mMaxVelY = 0;
|
||||||
mGravity = 0;
|
mGravity = 0;
|
||||||
mDefaultVelY = 0;
|
mDefaultVelY = 0;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 0;
|
mScore = 0;
|
||||||
|
|
||||||
// Rectangulo con la imagen del sprite
|
// Rectangulo con la imagen del sprite
|
||||||
mSprite.setSpriteClip(0, 0, mWidth, mHeight);
|
mSprite.setSpriteClip(0, 0, mWidth, mHeight);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Textura con los gráficos del sprite
|
// Textura con los gráficos del sprite
|
||||||
mSprite.setTexture(*gBalloonTexture);
|
mSprite.setTexture(*gBalloonTexture);
|
||||||
|
|
||||||
// Alto y ancho del sprite
|
// Alto y ancho del sprite
|
||||||
mSprite.setWidth(mWidth);
|
mSprite.setWidth(mWidth);
|
||||||
mSprite.setHeight(mHeight);
|
mSprite.setHeight(mHeight);
|
||||||
|
|
||||||
// Posición X,Y del sprite
|
// Posición X,Y del sprite
|
||||||
mSprite.setPosX(mPosX);
|
mSprite.setPosX(mPosX);
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Tamaño del circulo de colisión
|
// Tamaño del circulo de colisión
|
||||||
mCollider.r = mWidth / 2;
|
mCollider.r = mWidth / 2;
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
// Alinea el circulo de colisión con el objeto
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
mStopped = true;
|
mStopped = true;
|
||||||
mStoppedTimer = 0;
|
mStoppedTimer = 0;
|
||||||
mBlinking = false;
|
mBlinking = false;
|
||||||
mVisible = true;
|
mVisible = true;
|
||||||
mInvulnerable = false;
|
mInvulnerable = false;
|
||||||
mBeingCreated = true;
|
mBeingCreated = true;
|
||||||
mCreationTimer = creationtimer;
|
mCreationTimer = creationtimer;
|
||||||
|
|
||||||
// Tipo
|
// Tipo
|
||||||
mKind = kind;
|
mKind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void Balloon::allignTo(int x)
|
void Balloon::allignTo(int x)
|
||||||
{
|
{
|
||||||
mPosX = x - (mWidth / 2);
|
mPosX = x - (mWidth / 2);
|
||||||
|
|
||||||
if (mPosX < PLAY_AREA_LEFT)
|
if (mPosX < PLAY_AREA_LEFT)
|
||||||
{
|
{
|
||||||
mPosX = PLAY_AREA_LEFT + 1;
|
mPosX = PLAY_AREA_LEFT + 1;
|
||||||
}
|
}
|
||||||
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
||||||
{
|
{
|
||||||
mPosX = PLAY_AREA_RIGHT - mWidth - 1;
|
mPosX = PLAY_AREA_RIGHT - mWidth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Posición X,Y del sprite
|
// Posición X,Y del sprite
|
||||||
mSprite.setPosX(getPosX());
|
mSprite.setPosX(getPosX());
|
||||||
mSprite.setPosY(getPosY());
|
mSprite.setPosY(getPosY());
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
// Alinea el circulo de colisión con el objeto
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el globo en la pantalla
|
// Pinta el globo en la pantalla
|
||||||
void Balloon::render()
|
void Balloon::render()
|
||||||
{
|
{
|
||||||
if (mVisible)
|
if (mVisible)
|
||||||
{
|
{
|
||||||
mSprite.render();
|
mSprite.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición y estados del globo
|
// Actualiza la posición y estados del globo
|
||||||
void Balloon::move()
|
void Balloon::move()
|
||||||
{
|
{
|
||||||
// Comprobamos si se puede mover
|
// Comprobamos si se puede mover
|
||||||
if (isStopped() == false)
|
if (isStopped() == false)
|
||||||
{
|
{
|
||||||
// Lo movemos a izquierda o derecha
|
// Lo movemos a izquierda o derecha
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
|
|
||||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
||||||
{
|
{
|
||||||
// Corregir posición
|
// Corregir posición
|
||||||
mPosX -= mVelX;
|
mPosX -= mVelX;
|
||||||
|
|
||||||
// Invertir sentido
|
// Invertir sentido
|
||||||
mVelX = -mVelX;
|
mVelX = -mVelX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el globo hacia arriba o hacia abajo
|
// Mueve el globo hacia arriba o hacia abajo
|
||||||
mPosY += int(mVelY);
|
mPosY += int(mVelY);
|
||||||
|
|
||||||
// Si se sale por arriba
|
// Si se sale por arriba
|
||||||
if (mPosY < PLAY_AREA_TOP)
|
if (mPosY < PLAY_AREA_TOP)
|
||||||
{
|
{
|
||||||
// Corregimos
|
// Corregimos
|
||||||
mPosY -= int(mVelY);
|
mPosY -= int(mVelY);
|
||||||
|
|
||||||
// Invertimos sentido
|
// Invertimos sentido
|
||||||
mVelY = -mVelY;
|
mVelY = -mVelY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si el globo se sale por la parte inferior
|
// Si el globo se sale por la parte inferior
|
||||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
||||||
{
|
{
|
||||||
// Corregimos
|
// Corregimos
|
||||||
mPosY -= int(mVelY);
|
mPosY -= int(mVelY);
|
||||||
|
|
||||||
// Invertimos colocando una velocidad por defecto
|
// Invertimos colocando una velocidad por defecto
|
||||||
mVelY = -mDefaultVelY;
|
mVelY = -mDefaultVelY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aplica gravedad al objeto, sin pasarse de un limite establecido
|
// Aplica gravedad al objeto, sin pasarse de un limite establecido
|
||||||
if (int(mVelY) > mMaxVelY)
|
if (int(mVelY) > mMaxVelY)
|
||||||
{
|
{
|
||||||
mVelY = mMaxVelY;
|
mVelY = mMaxVelY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mVelY += mGravity;
|
mVelY += mGravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSprite.setPosX(getPosX());
|
mSprite.setPosX(getPosX());
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Actualiza la posición del circulo de colisión
|
// Actualiza la posición del circulo de colisión
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
}
|
}
|
||||||
// Si no se puede mover:
|
// Si no se puede mover:
|
||||||
// Comprobar si se está creando
|
// Comprobar si se está creando
|
||||||
else if (isBeingCreated() == true)
|
else if (isBeingCreated() == true)
|
||||||
{
|
{
|
||||||
// Actualiza el valor de las variables
|
// Actualiza el valor de las variables
|
||||||
setStop(true);
|
setStop(true);
|
||||||
setInvulnerable(true);
|
setInvulnerable(true);
|
||||||
|
|
||||||
// Todavia tiene tiempo en el contador
|
// Todavia tiene tiempo en el contador
|
||||||
if (mCreationTimer > 0)
|
if (mCreationTimer > 0)
|
||||||
{
|
{
|
||||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||||
if (mCreationTimer % 10 == 0)
|
if (mCreationTimer % 10 == 0)
|
||||||
{
|
{
|
||||||
++mPosY;
|
++mPosY;
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSprite.setPosX(getPosX());
|
mSprite.setPosX(getPosX());
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Actualiza la posición del circulo de colisión
|
// Actualiza la posición del circulo de colisión
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hace visible el globo de forma intermitente
|
// Hace visible el globo de forma intermitente
|
||||||
if (mCreationTimer > 100)
|
if (mCreationTimer > 100)
|
||||||
{
|
{
|
||||||
setVisible(mCreationTimer / 10 % 2 == 0);
|
setVisible(mCreationTimer / 10 % 2 == 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setVisible(mCreationTimer / 5 % 2 == 0);
|
setVisible(mCreationTimer / 5 % 2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
--mCreationTimer;
|
--mCreationTimer;
|
||||||
}
|
}
|
||||||
// El contador ha llegado a cero
|
// El contador ha llegado a cero
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setBeingCreated(false);
|
setBeingCreated(false);
|
||||||
setStop(false);
|
setStop(false);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setInvulnerable(false);
|
setInvulnerable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comprobar si está detenido
|
// Comprobar si está detenido
|
||||||
else if (isStopped() == true)
|
else if (isStopped() == true)
|
||||||
{
|
{
|
||||||
// Si todavía está detenido, reduce el contador
|
// Si todavía está detenido, reduce el contador
|
||||||
if (mStoppedTimer > 0)
|
if (mStoppedTimer > 0)
|
||||||
{
|
{
|
||||||
--mStoppedTimer;
|
--mStoppedTimer;
|
||||||
} // Si el contador ha llegado a cero, ya no está detenido
|
} // Si el contador ha llegado a cero, ya no está detenido
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setStop(false);
|
setStop(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone a cero todos los valores del globo
|
// Pone a cero todos los valores del globo
|
||||||
void Balloon::erase()
|
void Balloon::erase()
|
||||||
{
|
{
|
||||||
init(0, 0, NO_KIND, 0, 0);
|
init(0, 0, NO_KIND, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el globo tiene algun tipo asignado
|
// Comprueba si el globo tiene algun tipo asignado
|
||||||
bool Balloon::isActive()
|
bool Balloon::isActive()
|
||||||
{
|
{
|
||||||
if (mKind == NO_KIND)
|
if (mKind == NO_KIND)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getPosX()
|
int Balloon::getPosX()
|
||||||
{
|
{
|
||||||
return int(mPosX);
|
return int(mPosX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getPosY()
|
int Balloon::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return mPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Balloon::getVelY()
|
float Balloon::getVelY()
|
||||||
{
|
{
|
||||||
return mVelY;
|
return mVelY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getWidth()
|
int Balloon::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getHeight()
|
int Balloon::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setVelY(float velY)
|
void Balloon::setVelY(float velY)
|
||||||
{
|
{
|
||||||
mVelY = velY;
|
mVelY = velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getKind()
|
int Balloon::getKind()
|
||||||
{
|
{
|
||||||
return mKind;
|
return mKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setStop(bool state)
|
void Balloon::setStop(bool state)
|
||||||
{
|
{
|
||||||
mStopped = state;
|
mStopped = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isStopped()
|
bool Balloon::isStopped()
|
||||||
{
|
{
|
||||||
return mStopped;
|
return mStopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setBlink(bool state)
|
void Balloon::setBlink(bool state)
|
||||||
{
|
{
|
||||||
mBlinking = state;
|
mBlinking = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isBlinking()
|
bool Balloon::isBlinking()
|
||||||
{
|
{
|
||||||
return mBlinking;
|
return mBlinking;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setVisible(bool state)
|
void Balloon::setVisible(bool state)
|
||||||
{
|
{
|
||||||
mVisible = state;
|
mVisible = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isVisible()
|
bool Balloon::isVisible()
|
||||||
{
|
{
|
||||||
return mVisible;
|
return mVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setInvulnerable(bool state)
|
void Balloon::setInvulnerable(bool state)
|
||||||
{
|
{
|
||||||
mInvulnerable = state;
|
mInvulnerable = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isInvulnerable()
|
bool Balloon::isInvulnerable()
|
||||||
{
|
{
|
||||||
return mInvulnerable;
|
return mInvulnerable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setBeingCreated(bool state)
|
void Balloon::setBeingCreated(bool state)
|
||||||
{
|
{
|
||||||
mBeingCreated = state;
|
mBeingCreated = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isBeingCreated()
|
bool Balloon::isBeingCreated()
|
||||||
{
|
{
|
||||||
return mBeingCreated;
|
return mBeingCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setStoppedTimer(Uint16 time)
|
void Balloon::setStoppedTimer(Uint16 time)
|
||||||
{
|
{
|
||||||
mStoppedTimer = time;
|
mStoppedTimer = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 Balloon::getStoppedTimer()
|
Uint16 Balloon::getStoppedTimer()
|
||||||
{
|
{
|
||||||
return mStoppedTimer;
|
return mStoppedTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 Balloon::getScore()
|
Uint16 Balloon::getScore()
|
||||||
{
|
{
|
||||||
return mScore;
|
return mScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
Circle &Balloon::getCollider()
|
Circle &Balloon::getCollider()
|
||||||
{
|
{
|
||||||
return mCollider;
|
return mCollider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto globo
|
// Alinea el circulo de colisión con la posición del objeto globo
|
||||||
void Balloon::shiftColliders()
|
void Balloon::shiftColliders()
|
||||||
{
|
{
|
||||||
// Align collider to center of balloon
|
// Align collider to center of balloon
|
||||||
mCollider.x = mPosX + mCollider.r;
|
mCollider.x = mPosX + mCollider.r;
|
||||||
mCollider.y = mPosY + mCollider.r;
|
mCollider.y = mPosY + mCollider.r;
|
||||||
}
|
}
|
||||||
316
source/balloon.h
316
source/balloon.h
@@ -1,159 +1,159 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#ifndef BALLOON_H
|
#ifndef BALLOON_H
|
||||||
#define BALLOON_H
|
#define BALLOON_H
|
||||||
|
|
||||||
// Clase globo
|
// Clase globo
|
||||||
class Balloon
|
class Balloon
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon(SDL_Renderer *gRenderer);
|
Balloon(SDL_Renderer *gRenderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Balloon();
|
~Balloon();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(int x, int y, Uint8 kind, float velx, Uint16 creationtimer);
|
void init(int x, int y, Uint8 kind, float velx, Uint16 creationtimer);
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
// Pinta el globo en la pantalla
|
// Pinta el globo en la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Actualiza la posición y estados del globo
|
// Actualiza la posición y estados del globo
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
// Pone a cero todos los valores del globo
|
// Pone a cero todos los valores del globo
|
||||||
void erase();
|
void erase();
|
||||||
|
|
||||||
// Comprueba si el globo tiene algun tipo asignado
|
// Comprueba si el globo tiene algun tipo asignado
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getPosY();
|
int getPosY();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getVelY();
|
float getVelY();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getWidth();
|
int getWidth();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVelY(float velY);
|
void setVelY(float velY);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getKind();
|
int getKind();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStop(bool state);
|
void setStop(bool state);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isStopped();
|
bool isStopped();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setBlink(bool state);
|
void setBlink(bool state);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBlinking();
|
bool isBlinking();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVisible(bool state);
|
void setVisible(bool state);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isVisible();
|
bool isVisible();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setInvulnerable(bool state);
|
void setInvulnerable(bool state);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isInvulnerable();
|
bool isInvulnerable();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setBeingCreated(bool state);
|
void setBeingCreated(bool state);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBeingCreated();
|
bool isBeingCreated();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStoppedTimer(Uint16 time);
|
void setStoppedTimer(Uint16 time);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getStoppedTimer();
|
Uint16 getStoppedTimer();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getScore();
|
Uint16 getScore();
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
Circle &getCollider();
|
Circle &getCollider();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// El renderizador de la ventana
|
// El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer;
|
SDL_Renderer *gRenderer;
|
||||||
|
|
||||||
LTexture *gBalloonTexture;
|
LTexture *gBalloonTexture;
|
||||||
|
|
||||||
// Posición X,Y del objeto globo
|
// Posición X,Y del objeto globo
|
||||||
float mPosX;
|
float mPosX;
|
||||||
int mPosY;
|
int mPosY;
|
||||||
|
|
||||||
// Alto y ancho del objeto globo
|
// Alto y ancho del objeto globo
|
||||||
Uint8 mWidth;
|
Uint8 mWidth;
|
||||||
Uint8 mHeight;
|
Uint8 mHeight;
|
||||||
|
|
||||||
// Variables para controlar la velocidad del globo
|
// Variables para controlar la velocidad del globo
|
||||||
float mVelX;
|
float mVelX;
|
||||||
float mVelY;
|
float mVelY;
|
||||||
float mGravity;
|
float mGravity;
|
||||||
float mDefaultVelY;
|
float mDefaultVelY;
|
||||||
int mMaxVelY;
|
int mMaxVelY;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
Uint16 mScore;
|
Uint16 mScore;
|
||||||
|
|
||||||
// Indica si el globo está parado
|
// Indica si el globo está parado
|
||||||
bool mStopped;
|
bool mStopped;
|
||||||
|
|
||||||
// Temporizador para controlar el estado "parado"
|
// Temporizador para controlar el estado "parado"
|
||||||
Uint16 mStoppedTimer;
|
Uint16 mStoppedTimer;
|
||||||
|
|
||||||
// Indica si el globo está intermitente
|
// Indica si el globo está intermitente
|
||||||
bool mBlinking;
|
bool mBlinking;
|
||||||
|
|
||||||
// Indica si el globo es visible
|
// Indica si el globo es visible
|
||||||
bool mVisible;
|
bool mVisible;
|
||||||
|
|
||||||
// Indica si el globo es invulnerable
|
// Indica si el globo es invulnerable
|
||||||
bool mInvulnerable;
|
bool mInvulnerable;
|
||||||
|
|
||||||
// Indica si el globo se está creando
|
// Indica si el globo se está creando
|
||||||
bool mBeingCreated;
|
bool mBeingCreated;
|
||||||
|
|
||||||
// Temporizador para controlar el estado "creandose"
|
// Temporizador para controlar el estado "creandose"
|
||||||
Uint16 mCreationTimer;
|
Uint16 mCreationTimer;
|
||||||
|
|
||||||
// Tipo de globo
|
// Tipo de globo
|
||||||
Uint8 mKind;
|
Uint8 mKind;
|
||||||
|
|
||||||
// Sprite del objeto globo
|
// Sprite del objeto globo
|
||||||
Sprite mSprite;
|
Sprite mSprite;
|
||||||
|
|
||||||
// Circulo de colisión del objeto
|
// Circulo de colisión del objeto
|
||||||
Circle mCollider;
|
Circle mCollider;
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto globo
|
// Alinea el circulo de colisión con la posición del objeto globo
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,206 +1,211 @@
|
|||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(SDL_Renderer *gRenderer)
|
Bullet::Bullet(SDL_Renderer *gRenderer)
|
||||||
{
|
{
|
||||||
this->gRenderer = gRenderer;
|
this->gRenderer = gRenderer;
|
||||||
|
|
||||||
gBulletTexture = new LTexture(gRenderer);
|
gBulletTexture = new LTexture(gRenderer);
|
||||||
|
|
||||||
// Carga los gráficos de las balas
|
// Carga los gráficos de las balas
|
||||||
if (!gBulletTexture->loadFromFile("media/gfx/bullet.png"))
|
if (!gBulletTexture->loadFromFile("media/gfx/bullet.png"))
|
||||||
{
|
{
|
||||||
printf("Failed to load bullet texture!\n");
|
printf("Failed to load bullet texture!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
init(0, 0, NO_KIND);
|
init(0, 0, NO_KIND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Bullet::~Bullet()
|
Bullet::~Bullet()
|
||||||
{
|
{
|
||||||
gBulletTexture->free();
|
gBulletTexture->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void Bullet::init(int x, int y, int kind)
|
void Bullet::init(int x, int y, int kind)
|
||||||
{
|
{
|
||||||
// Posición inicial del objeto
|
// Posición inicial del objeto
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 8;
|
mWidth = 8;
|
||||||
mHeight = mWidth;
|
mHeight = mWidth;
|
||||||
|
|
||||||
// Velocidad inicial en el eje Y
|
// Velocidad inicial en el eje Y
|
||||||
mVelY = -3;
|
mVelY = -3;
|
||||||
|
|
||||||
// Tipo de bala
|
// Tipo de bala
|
||||||
mKind = kind;
|
mKind = kind;
|
||||||
|
|
||||||
// Textura con los gráficos del objeto
|
// Textura con los gráficos del objeto
|
||||||
mSprite.setTexture(*gBulletTexture);
|
mSprite.setTexture(*gBulletTexture);
|
||||||
|
|
||||||
// Alto y ancho del sprite
|
// Alto y ancho del sprite
|
||||||
mSprite.setWidth(mWidth);
|
mSprite.setWidth(mWidth);
|
||||||
mSprite.setHeight(mHeight);
|
mSprite.setHeight(mHeight);
|
||||||
|
|
||||||
// Posición inicial del sprite
|
// Posición inicial del sprite
|
||||||
mSprite.setPosX(mPosX);
|
mSprite.setPosX(mPosX);
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Valores especificos según el tipo
|
// Valores especificos según el tipo
|
||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case BULLET_UP:
|
case BULLET_UP:
|
||||||
// Establece la velocidad inicial
|
// Establece la velocidad inicial
|
||||||
mVelX = 0;
|
mVelX = 0;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite.setSpriteClip(0 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setSpriteClip(0 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_LEFT:
|
case BULLET_LEFT:
|
||||||
// Establece la velocidad inicial
|
// Establece la velocidad inicial
|
||||||
mVelX = -2;
|
mVelX = -2;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite.setSpriteClip(1 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setSpriteClip(1 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_RIGHT:
|
case BULLET_RIGHT:
|
||||||
// Establece la velocidad inicial
|
// Establece la velocidad inicial
|
||||||
mVelX = 2;
|
mVelX = 2;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite.setSpriteClip(2 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setSpriteClip(2 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
// Establece la velocidad inicial
|
||||||
}
|
mVelX = 0;
|
||||||
|
|
||||||
// Establece el tamaño del circulo de colisión
|
// Rectangulo con los gráficos del objeto
|
||||||
mCollider.r = mWidth / 2;
|
mSprite.setSpriteClip(0 * mWidth, 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
|
break;
|
||||||
// Alinea el circulo de colisión con el objeto
|
}
|
||||||
shiftColliders();
|
|
||||||
}
|
// Establece el tamaño del circulo de colisión
|
||||||
|
mCollider.r = mWidth / 2;
|
||||||
// Pinta el objeto en pantalla
|
|
||||||
void Bullet::render()
|
// Alinea el circulo de colisión con el objeto
|
||||||
{
|
shiftColliders();
|
||||||
mSprite.render();
|
}
|
||||||
}
|
|
||||||
|
// Pinta el objeto en pantalla
|
||||||
// Actualiza la posición y estado del objeto en horizontal
|
void Bullet::render()
|
||||||
void Bullet::move()
|
{
|
||||||
{
|
mSprite.render();
|
||||||
// Mueve el objeto a su nueva posición
|
}
|
||||||
mPosX += mVelX;
|
|
||||||
|
// Actualiza la posición y estado del objeto en horizontal
|
||||||
// Si el objeto se sale del area de juego por los laterales
|
void Bullet::move()
|
||||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
{
|
||||||
{
|
// Mueve el objeto a su nueva posición
|
||||||
// Se deshabilita
|
mPosX += mVelX;
|
||||||
mKind = NO_KIND;
|
|
||||||
}
|
// Si el objeto se sale del area de juego por los laterales
|
||||||
|
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
||||||
// Mueve el objeto a su nueva posición en vertical
|
{
|
||||||
mPosY += int(mVelY);
|
// Se deshabilita
|
||||||
|
mKind = NO_KIND;
|
||||||
// Si el objeto se sale del area de juego por la parte superior o inferior
|
}
|
||||||
if ((mPosY < PLAY_AREA_TOP) || (mPosY + mHeight > PLAY_AREA_BOTTOM))
|
|
||||||
{
|
// Mueve el objeto a su nueva posición en vertical
|
||||||
// Se deshabilita
|
mPosY += int(mVelY);
|
||||||
mKind = NO_KIND;
|
|
||||||
}
|
// Si el objeto se sale del area de juego por la parte superior o inferior
|
||||||
|
if ((mPosY < PLAY_AREA_TOP) || (mPosY + mHeight > PLAY_AREA_BOTTOM))
|
||||||
// Actualiza la posición del sprite
|
{
|
||||||
mSprite.setPosX(mPosX);
|
// Se deshabilita
|
||||||
mSprite.setPosY(mPosY);
|
mKind = NO_KIND;
|
||||||
|
}
|
||||||
// Alinea el circulo de colisión con el objeto
|
|
||||||
shiftColliders();
|
// Actualiza la posición del sprite
|
||||||
}
|
mSprite.setPosX(mPosX);
|
||||||
|
mSprite.setPosY(mPosY);
|
||||||
#ifdef TEST
|
|
||||||
void Bullet::testMove()
|
// Alinea el circulo de colisión con el objeto
|
||||||
{
|
shiftColliders();
|
||||||
// Update sprite position
|
}
|
||||||
mSprite.setPosX(mPosX);
|
|
||||||
mSprite.setPosY(mPosY);
|
#ifdef TEST
|
||||||
|
void Bullet::testMove()
|
||||||
// Update circle colliders
|
{
|
||||||
shiftColliders();
|
// Update sprite position
|
||||||
}
|
mSprite.setPosX(mPosX);
|
||||||
#endif
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Deshabilita el objeto
|
// Update circle colliders
|
||||||
void Bullet::erase()
|
shiftColliders();
|
||||||
{
|
}
|
||||||
mKind = NO_KIND;
|
#endif
|
||||||
}
|
|
||||||
|
// Deshabilita el objeto
|
||||||
// Comprueba si el objeto está activo
|
void Bullet::erase()
|
||||||
bool Bullet::isActive()
|
{
|
||||||
{
|
mKind = NO_KIND;
|
||||||
if (mKind == NO_KIND)
|
}
|
||||||
{
|
|
||||||
return false;
|
// Comprueba si el objeto está activo
|
||||||
}
|
bool Bullet::isActive()
|
||||||
else
|
{
|
||||||
{
|
if (mKind == NO_KIND)
|
||||||
return true;
|
{
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Obtiene el valor de la variable
|
{
|
||||||
int Bullet::getPosX()
|
return true;
|
||||||
{
|
}
|
||||||
return mPosX;
|
}
|
||||||
}
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
// Obtiene el valor de la variable
|
int Bullet::getPosX()
|
||||||
int Bullet::getPosY()
|
{
|
||||||
{
|
return mPosX;
|
||||||
return mPosY;
|
}
|
||||||
}
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
// Establece el valor de la variable
|
int Bullet::getPosY()
|
||||||
void Bullet::setPosX(int x)
|
{
|
||||||
{
|
return mPosY;
|
||||||
mPosX = x;
|
}
|
||||||
}
|
|
||||||
|
// Establece el valor de la variable
|
||||||
// Establece el valor de la variable
|
void Bullet::setPosX(int x)
|
||||||
void Bullet::setPosY(int y)
|
{
|
||||||
{
|
mPosX = x;
|
||||||
mPosY = y;
|
}
|
||||||
}
|
|
||||||
|
// Establece el valor de la variable
|
||||||
// Obtiene el valor de la variable
|
void Bullet::setPosY(int y)
|
||||||
float Bullet::getVelY()
|
{
|
||||||
{
|
mPosY = y;
|
||||||
return mVelY;
|
}
|
||||||
}
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
// Obtiene el valor de la variable
|
float Bullet::getVelY()
|
||||||
int Bullet::getKind()
|
{
|
||||||
{
|
return mVelY;
|
||||||
return mKind;
|
}
|
||||||
}
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
// Obtiene el circulo de colisión
|
int Bullet::getKind()
|
||||||
Circle &Bullet::getCollider()
|
{
|
||||||
{
|
return mKind;
|
||||||
return mCollider;
|
}
|
||||||
}
|
|
||||||
|
// Obtiene el circulo de colisión
|
||||||
// Alinea el circulo de colisión con el objeto
|
Circle &Bullet::getCollider()
|
||||||
void Bullet::shiftColliders()
|
{
|
||||||
{
|
return mCollider;
|
||||||
mCollider.x = mPosX + mCollider.r;
|
}
|
||||||
mCollider.y = mPosY + mCollider.r;
|
|
||||||
}
|
// Alinea el circulo de colisión con el objeto
|
||||||
|
void Bullet::shiftColliders()
|
||||||
|
{
|
||||||
|
mCollider.x = mPosX + mCollider.r;
|
||||||
|
mCollider.y = mPosY + mCollider.r;
|
||||||
|
}
|
||||||
|
|||||||
176
source/bullet.h
176
source/bullet.h
@@ -1,89 +1,89 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#ifndef BULLET_H
|
#ifndef BULLET_H
|
||||||
#define BULLET_H
|
#define BULLET_H
|
||||||
|
|
||||||
// Clase bala
|
// Clase bala
|
||||||
class Bullet
|
class Bullet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet(SDL_Renderer *gRenderer);
|
Bullet(SDL_Renderer *gRenderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Bullet();
|
~Bullet();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init(int x, int y, int kind);
|
void init(int x, int y, int kind);
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Actualiza la posición y estado del objeto
|
// Actualiza la posición y estado del objeto
|
||||||
void move();
|
void move();
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
void testMove();
|
void testMove();
|
||||||
#endif
|
#endif
|
||||||
// Deshabilita el objeto
|
// Deshabilita el objeto
|
||||||
void erase();
|
void erase();
|
||||||
|
|
||||||
// Comprueba si el objeto está activo
|
// Comprueba si el objeto está activo
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosY();
|
int getPosY();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(int x);
|
void setPosX(int x);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosY(int y);
|
void setPosY(int y);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float getVelY();
|
float getVelY();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getKind();
|
int getKind();
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
Circle &getCollider();
|
Circle &getCollider();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// El renderizador de la ventana
|
// El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer;
|
SDL_Renderer *gRenderer;
|
||||||
|
|
||||||
LTexture *gBulletTexture;
|
LTexture *gBulletTexture;
|
||||||
|
|
||||||
// Posición X/Y del objeto
|
// Posición X/Y del objeto
|
||||||
int mPosX;
|
int mPosX;
|
||||||
int mPosY;
|
int mPosY;
|
||||||
|
|
||||||
// Alto y ancho el objeto
|
// Alto y ancho el objeto
|
||||||
Uint8 mWidth;
|
Uint8 mWidth;
|
||||||
Uint8 mHeight;
|
Uint8 mHeight;
|
||||||
|
|
||||||
// Velocidad del objeto
|
// Velocidad del objeto
|
||||||
int mVelX;
|
int mVelX;
|
||||||
int mVelY;
|
int mVelY;
|
||||||
|
|
||||||
// Tipo de objeto
|
// Tipo de objeto
|
||||||
int mKind;
|
int mKind;
|
||||||
|
|
||||||
// Sprite con los graficos y métodos de pintado
|
// Sprite con los graficos y métodos de pintado
|
||||||
Sprite mSprite;
|
Sprite mSprite;
|
||||||
|
|
||||||
// Balloon's collision circle
|
// Balloon's collision circle
|
||||||
Circle mCollider;
|
Circle mCollider;
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
// Alinea el circulo de colisión con el objeto
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
210
source/const.h
210
source/const.h
@@ -1,106 +1,106 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef CONST_H
|
#ifndef CONST_H
|
||||||
#define CONST_H
|
#define CONST_H
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
const int BLOCK = 8;
|
const int BLOCK = 8;
|
||||||
|
|
||||||
// Tamaño de la pantalla real
|
// Tamaño de la pantalla real
|
||||||
const int SCREEN_WIDTH = 256;
|
const int SCREEN_WIDTH = 256;
|
||||||
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4;
|
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4;
|
||||||
|
|
||||||
// Tamaño de la pantalla que se muestra
|
// Tamaño de la pantalla que se muestra
|
||||||
const int VIEW_WIDTH = SCREEN_WIDTH * 3;
|
const int VIEW_WIDTH = SCREEN_WIDTH * 3;
|
||||||
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
|
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);
|
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);
|
||||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||||
const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
|
const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
|
||||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||||
|
|
||||||
// Color transparente para los sprites
|
// Color transparente para los sprites
|
||||||
const int COLOR_KEY_R = 0xff;
|
const int COLOR_KEY_R = 0xff;
|
||||||
const int COLOR_KEY_G = 0x00;
|
const int COLOR_KEY_G = 0x00;
|
||||||
const int COLOR_KEY_B = 0xff;
|
const int COLOR_KEY_B = 0xff;
|
||||||
|
|
||||||
// Opciones de menu
|
// Opciones de menu
|
||||||
const int MENU_NO_OPTION = -1;
|
const int MENU_NO_OPTION = -1;
|
||||||
const int MENU_OPTION_START = 0;
|
const int MENU_OPTION_START = 0;
|
||||||
const int MENU_OPTION_QUIT = 1;
|
const int MENU_OPTION_QUIT = 1;
|
||||||
const int MENU_OPTION_TOTAL = 2;
|
const int MENU_OPTION_TOTAL = 2;
|
||||||
|
|
||||||
// Selector de menu
|
// Selector de menu
|
||||||
const int MENU_SELECTOR_BLACK = (BLOCK * 0);
|
const int MENU_SELECTOR_BLACK = (BLOCK * 0);
|
||||||
const int MENU_SELECTOR_WHITE = (BLOCK * 1);
|
const int MENU_SELECTOR_WHITE = (BLOCK * 1);
|
||||||
|
|
||||||
// Tipos de fondos para el menu
|
// Tipos de fondos para el menu
|
||||||
const int MENU_BACKGROUND_TRANSPARENT = 0;
|
const int MENU_BACKGROUND_TRANSPARENT = 0;
|
||||||
const int MENU_BACKGROUND_SOLID = 1;
|
const int MENU_BACKGROUND_SOLID = 1;
|
||||||
|
|
||||||
// Estados del jugador
|
// Estados del jugador
|
||||||
const int PLAYER_STATE_STOPPED = 0;
|
const int PLAYER_STATE_STOPPED = 0;
|
||||||
const int PLAYER_STATE_WALKING_LEFT = 1;
|
const int PLAYER_STATE_WALKING_LEFT = 1;
|
||||||
const int PLAYER_STATE_WALKING_RIGHT = 2;
|
const int PLAYER_STATE_WALKING_RIGHT = 2;
|
||||||
const int PLAYER_STATE_TOTAL = 3;
|
const int PLAYER_STATE_TOTAL = 3;
|
||||||
|
|
||||||
// Estados del juego
|
// Estados del juego
|
||||||
const int GAME_STATE_TITLE = 0;
|
const int GAME_STATE_TITLE = 0;
|
||||||
const int GAME_STATE_PLAYING = 1;
|
const int GAME_STATE_PLAYING = 1;
|
||||||
const int GAME_STATE_PAUSED = 2;
|
const int GAME_STATE_PAUSED = 2;
|
||||||
const int GAME_STATE_QUIT = 3;
|
const int GAME_STATE_QUIT = 3;
|
||||||
const int GAME_STATE_TOTAL = 4;
|
const int GAME_STATE_TOTAL = 4;
|
||||||
|
|
||||||
// Anclajes para el marcador de puntos
|
// Anclajes para el marcador de puntos
|
||||||
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
|
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
|
||||||
const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 4;
|
const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 4;
|
||||||
const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - (3 * BLOCK);
|
const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - (3 * BLOCK);
|
||||||
const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 4;
|
const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 4;
|
||||||
const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
|
const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
|
||||||
const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 4;
|
const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 4;
|
||||||
const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - (3 * BLOCK);
|
const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - (3 * BLOCK);
|
||||||
const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 4;
|
const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 4;
|
||||||
|
|
||||||
// Ningun tipo
|
// Ningun tipo
|
||||||
const int NO_KIND = 0;
|
const int NO_KIND = 0;
|
||||||
|
|
||||||
// Tipos de globo
|
// Tipos de globo
|
||||||
const int BALLOON_1 = 1;
|
const int BALLOON_1 = 1;
|
||||||
const int BALLOON_2 = 2;
|
const int BALLOON_2 = 2;
|
||||||
const int BALLOON_3 = 3;
|
const int BALLOON_3 = 3;
|
||||||
const int BALLOON_4 = 4;
|
const int BALLOON_4 = 4;
|
||||||
|
|
||||||
// Velocidad del globo
|
// Velocidad del globo
|
||||||
const float BALLON_VELX_POSITIVE = 0.7;
|
const float BALLON_VELX_POSITIVE = 0.7;
|
||||||
const float BALLON_VELX_NEGATIVE = -0.7;
|
const float BALLON_VELX_NEGATIVE = -0.7;
|
||||||
|
|
||||||
// Tipos de bala
|
// Tipos de bala
|
||||||
const int BULLET_UP = 1;
|
const int BULLET_UP = 1;
|
||||||
const int BULLET_LEFT = 2;
|
const int BULLET_LEFT = 2;
|
||||||
const int BULLET_RIGHT = 3;
|
const int BULLET_RIGHT = 3;
|
||||||
|
|
||||||
// Estados de entrada
|
// Estados de entrada
|
||||||
const int NO_INPUT = 0;
|
const int NO_INPUT = 0;
|
||||||
const int INPUT_UP = 1;
|
const int INPUT_UP = 1;
|
||||||
const int INPUT_DOWN = 2;
|
const int INPUT_DOWN = 2;
|
||||||
const int INPUT_LEFT = 3;
|
const int INPUT_LEFT = 3;
|
||||||
const int INPUT_RIGHT = 4;
|
const int INPUT_RIGHT = 4;
|
||||||
const int INPUT_FIRE = 5;
|
const int INPUT_FIRE = 5;
|
||||||
|
|
||||||
// Zona muerta del mando analógico
|
// Zona muerta del mando analógico
|
||||||
const int JOYSTICK_DEAD_ZONE = 8000;
|
const int JOYSTICK_DEAD_ZONE = 8000;
|
||||||
|
|
||||||
// Mapeo de bottones (8bitdo)
|
// Mapeo de bottones (8bitdo)
|
||||||
const int BUTTON_A = 0;
|
const int BUTTON_A = 0;
|
||||||
const int BUTTON_B = 1;
|
const int BUTTON_B = 1;
|
||||||
const int BUTTON_X = 3;
|
const int BUTTON_X = 3;
|
||||||
const int BUTTON_Y = 4;
|
const int BUTTON_Y = 4;
|
||||||
const int BUTTON_SELECT = 10;
|
const int BUTTON_SELECT = 10;
|
||||||
const int BUTTON_START = 11;
|
const int BUTTON_START = 11;
|
||||||
const int BUTTON_L = 6;
|
const int BUTTON_L = 6;
|
||||||
const int BUTTON_R = 7;
|
const int BUTTON_R = 7;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,219 +1,221 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "background.h"
|
#include "background.h"
|
||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "ltexture.h"
|
#include "ltexture.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
#ifndef GAMEDIRECTOR_H
|
|
||||||
#define GAMEDIRECTOR_H
|
#ifndef GAMEDIRECTOR_H
|
||||||
|
#define GAMEDIRECTOR_H
|
||||||
// GameDirector
|
|
||||||
class GameDirector
|
// GameDirector
|
||||||
{
|
class GameDirector
|
||||||
public:
|
{
|
||||||
// Constructor
|
public:
|
||||||
GameDirector(SDL_Renderer *gRenderer);
|
// Constructor
|
||||||
|
GameDirector(SDL_Renderer *gRenderer);
|
||||||
// Destructor
|
|
||||||
~GameDirector();
|
// Destructor
|
||||||
|
~GameDirector();
|
||||||
// Iniciador
|
|
||||||
void init();
|
// Iniciador
|
||||||
|
void init();
|
||||||
// Hace una pausa de milisegundos
|
|
||||||
void sleep(Uint16 time);
|
// Establece el valor de la variable
|
||||||
|
void setScore(Uint32 score);
|
||||||
// Establece el valor de la variable
|
|
||||||
void setScore(Uint32 score);
|
// Establece el valor de la variable
|
||||||
|
void setHiScore(Uint32 score);
|
||||||
// Establece el valor de la variable
|
|
||||||
void setHiScore(Uint32 score);
|
// Actualiza el valor de HiScore en caso necesario
|
||||||
|
void updateHiScore();
|
||||||
// Actualiza el valor de HiScore en caso necesario
|
|
||||||
void updateHiScore();
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
|
std::string updateScoreText(Uint32 num);
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string updateScoreText(Uint32 num);
|
// Pinta el marcador en pantalla usando un objeto texto
|
||||||
|
void renderScoreBoard(Text &text);
|
||||||
// Pinta el marcador en pantalla usando un objeto texto
|
|
||||||
void renderScoreBoard(Text &text);
|
// Mueve todos los globos activos
|
||||||
|
void moveBalloons();
|
||||||
// Mueve todos los globos activos
|
|
||||||
void moveBalloons();
|
// Pinta en pantalla todos los globos activos
|
||||||
|
void renderBalloons();
|
||||||
// Pinta en pantalla todos los globos activos
|
|
||||||
void renderBalloons();
|
// Devuelve el primer indice no activo del vector de globos
|
||||||
|
Uint8 getBallonFreeIndex();
|
||||||
// Devuelve el primer indice no activo del vector de globos
|
|
||||||
Uint8 getBallonFreeIndex();
|
// Crea un globo nuevo en el vector de globos
|
||||||
|
Uint8 createNewBalloon(int x, int y, Uint8 kind, float velx, Uint16 stoppedtimer);
|
||||||
// Crea un globo nuevo en el vector de globos
|
|
||||||
Uint8 createNewBalloon(int x, int y, Uint8 kind, float velx, Uint16 stoppedtimer);
|
// Establece a cero todos los valores del vector de objetos globo
|
||||||
|
void resetBalloons();
|
||||||
// Establece a cero todos los valores del vector de objetos globo
|
|
||||||
void resetBalloons();
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
|
void popBalloon(Uint8 index);
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
|
||||||
void popBalloon(Uint8 index);
|
// Detiene todos los globos
|
||||||
|
void stopAllBalloons();
|
||||||
// Detiene todos los globos
|
|
||||||
void stopAllBalloons();
|
// Pone en marcha todos los globos
|
||||||
|
void startAllBalloons();
|
||||||
// Pone en marcha todos los globos
|
|
||||||
void startAllBalloons();
|
// Obtiene el numero de globos activos
|
||||||
|
Uint8 countBalloons();
|
||||||
// Obtiene el numero de globos activos
|
|
||||||
Uint8 countBalloons();
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
|
bool checkPlayerBallonCollision();
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
|
||||||
bool checkPlayerBallonCollision();
|
// Comprueba y procesa la colisión entre las balas y los globos
|
||||||
|
void processBulletBallonCollision();
|
||||||
// Comprueba y procesa la colisión entre las balas y los globos
|
|
||||||
void processBulletBallonCollision();
|
// Mueve las balas activas
|
||||||
|
void moveBullets();
|
||||||
// Mueve las balas activas
|
|
||||||
void moveBullets();
|
// Pinta las balas activas
|
||||||
|
void renderBullets();
|
||||||
// Pinta las balas activas
|
|
||||||
void renderBullets();
|
// Devuelve el primer indice no activo del vector de balas
|
||||||
|
Uint8 getBulletFreeIndex();
|
||||||
// Devuelve el primer indice no activo del vector de balas
|
|
||||||
Uint8 getBulletFreeIndex();
|
// Establece a cero todos los valores del vector de objetos bala
|
||||||
|
void resetBullets();
|
||||||
// Establece a cero todos los valores del vector de objetos bala
|
|
||||||
void resetBullets();
|
// Crea un objeto bala
|
||||||
|
void createBullet(int x, int y, Uint8 kind);
|
||||||
// Crea un objeto bala
|
|
||||||
void createBullet(int x, int y, Uint8 kind);
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
|
void calculateMenaceLevel();
|
||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
|
||||||
void calculateMenaceLevel();
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getMenaceLevel();
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getMenaceLevel();
|
// Gestiona el nivel de amenaza
|
||||||
|
void checkMenaceLevel();
|
||||||
// Gestiona el nivel de amenaza
|
|
||||||
void checkMenaceLevel();
|
// Gestiona la entrada de teclado y mando durante el juego
|
||||||
|
void checkGameInput();
|
||||||
// Gestiona la entrada de teclado y mando durante el juego
|
|
||||||
void checkGameInput();
|
// Gestiona la entrada de teclado y mando durante el menu
|
||||||
|
void checkMenuInput(Menu *menu);
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
|
||||||
void checkMenuInput(Menu *menu);
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getGameStatus();
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getGameStatus();
|
// Establece el valor de la variable
|
||||||
|
void setGameStatus(Uint8 status);
|
||||||
// Establece el valor de la variable
|
|
||||||
void setGameStatus(Uint8 status);
|
// Pinta una transición en pantalla
|
||||||
|
void renderTransition(Uint8 index);
|
||||||
// Pinta una transición en pantalla
|
|
||||||
void renderTransition(Uint8 index);
|
// Pinta el texto GetReady en pantalla
|
||||||
|
void renderGetReady();
|
||||||
// Pinta el texto GetReady en pantalla
|
|
||||||
void renderGetReady();
|
// Bucle para el titulo del juego
|
||||||
|
void runTitle();
|
||||||
// Bucle para el titulo del juego
|
|
||||||
void runTitle();
|
// Bucle para el juego
|
||||||
|
void runGame();
|
||||||
// Bucle para el juego
|
|
||||||
void runGame();
|
// Bucle para el menu de pausa del juego
|
||||||
|
void runPausedGame();
|
||||||
// Bucle para el menu de pausa del juego
|
|
||||||
void runPausedGame();
|
private:
|
||||||
|
// El renderizador de la ventana
|
||||||
private:
|
SDL_Renderer *gRenderer = NULL;
|
||||||
// El renderizador de la ventana
|
|
||||||
SDL_Renderer *gRenderer = NULL;
|
// Objetos con la música del juego
|
||||||
|
//Mix_Music *gTitleMusic = NULL;
|
||||||
// Objetos con la música del juego
|
//Mix_Music *gPlayingMusic = NULL;
|
||||||
Mix_Music *gTitleMusic = NULL;
|
JA_Music gTitleMusic;
|
||||||
Mix_Music *gPlayingMusic = NULL;
|
JA_Music gPlayingMusic;
|
||||||
|
|
||||||
// Objetos con los efectos de sonido del juego
|
// Objetos con los efectos de sonido del juego
|
||||||
Mix_Chunk *gPopBalloonFX = NULL;
|
//Mix_Chunk *gPopBalloonFX = NULL;
|
||||||
Mix_Chunk *gBulletFX = NULL;
|
//Mix_Chunk *gBulletFX = NULL;
|
||||||
|
JA_Sound gPopBalloonFX;
|
||||||
// Manejador para el mando 1
|
JA_Sound gBulletFX;
|
||||||
SDL_Joystick *gGameController = NULL;
|
|
||||||
|
// Manejador para el mando 1
|
||||||
// Texturas
|
SDL_Joystick *gGameController = NULL;
|
||||||
LTexture *gGameBackgroundTexture;
|
|
||||||
LTexture *gTitleBackgroundTexture;
|
// Texturas
|
||||||
LTexture *gWhiteFontTexture;
|
LTexture *gGameBackgroundTexture;
|
||||||
LTexture *gBlackFontTexture;
|
LTexture *gTitleBackgroundTexture;
|
||||||
LTexture *gMiscTexture;
|
LTexture *gWhiteFontTexture;
|
||||||
|
LTexture *gBlackFontTexture;
|
||||||
// Manejador de eventos
|
LTexture *gMiscTexture;
|
||||||
SDL_Event eventHandler;
|
|
||||||
|
// Manejador de eventos
|
||||||
// El jugador
|
SDL_Event eventHandler;
|
||||||
Player *player;
|
|
||||||
|
// El jugador
|
||||||
// Vector con los objetos globo
|
Player *player;
|
||||||
Balloon *balloon[50];
|
|
||||||
#ifdef TEST
|
// Vector con los objetos globo
|
||||||
Balloon balloonTest;
|
Balloon *balloon[50];
|
||||||
Bullet bulletTest;
|
#ifdef TEST
|
||||||
#endif
|
Balloon balloonTest;
|
||||||
|
Bullet bulletTest;
|
||||||
// Vector con los objetos bala
|
#endif
|
||||||
Bullet *bullet[50];
|
|
||||||
|
// Vector con los objetos bala
|
||||||
// Fondo del juego
|
Bullet *bullet[50];
|
||||||
Background gameBackground;
|
|
||||||
|
// Fondo del juego
|
||||||
// Fondo de la pantalla de titulo
|
Background gameBackground;
|
||||||
Background titleBackground;
|
|
||||||
|
// Fondo de la pantalla de titulo
|
||||||
// Texto blanco
|
Background titleBackground;
|
||||||
Text whiteText;
|
|
||||||
|
// Texto blanco
|
||||||
// Texto negro
|
Text whiteText;
|
||||||
Text blackText;
|
|
||||||
|
// Texto negro
|
||||||
// Menu de la pantalla de título
|
Text blackText;
|
||||||
Menu *menuTitle;
|
|
||||||
|
// Menu de la pantalla de título
|
||||||
// Menú de la pantalla de pausa
|
Menu *menuTitle;
|
||||||
Menu *menuPause;
|
|
||||||
|
// Menú de la pantalla de pausa
|
||||||
// Indicador para el bucle principal
|
Menu *menuPause;
|
||||||
Uint8 mGameStatus;
|
|
||||||
|
// Indicador para el bucle principal
|
||||||
// Puntuación actual y puntuación máxima
|
Uint8 mGameStatus;
|
||||||
Uint32 mScore;
|
|
||||||
Uint32 mHiScore;
|
// Puntuación actual y puntuación máxima
|
||||||
|
Uint32 mScore;
|
||||||
// Cadena de texto con la puntuación actual y la puntuación máxima de 6 cifras
|
Uint32 mHiScore;
|
||||||
std::string mScoreText;
|
|
||||||
std::string mHiScoreText;
|
// Cadena de texto con la puntuación actual y la puntuación máxima de 6 cifras
|
||||||
|
std::string mScoreText;
|
||||||
// Número máximo de globos y balas que puede almacenar el vector
|
std::string mHiScoreText;
|
||||||
Uint8 mMaxBalloons;
|
|
||||||
Uint8 mMaxBullets;
|
// Número máximo de globos y balas que puede almacenar el vector
|
||||||
|
Uint8 mMaxBalloons;
|
||||||
// Contador de ticks para ajustar la velocidad del juego
|
Uint8 mMaxBullets;
|
||||||
Uint32 mOldTicks;
|
|
||||||
|
// Contador de ticks para ajustar la velocidad del juego
|
||||||
// Velocidad a la que se repite el bucle de juego
|
Uint32 mOldTicks;
|
||||||
Uint8 mGameSpeed;
|
|
||||||
|
// Velocidad a la que se repite el bucle de juego
|
||||||
// Nivel de amenaza actual
|
Uint8 mGameSpeed;
|
||||||
Uint8 mMenaceLevel;
|
|
||||||
|
// Nivel de amenaza actual
|
||||||
// Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral,
|
Uint8 mMenaceLevel;
|
||||||
// se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
|
||||||
Uint8 mMenaceLevelThreshold;
|
// Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral,
|
||||||
|
// se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
||||||
// Indica si ha de aparecer el texto de GetReady en pantalla
|
Uint8 mMenaceLevelThreshold;
|
||||||
bool mGetReady;
|
|
||||||
};
|
// Indica si ha de aparecer el texto de GetReady en pantalla
|
||||||
|
bool mGetReady;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
#ifndef GLOBALS_H
|
||||||
|
#define GLOBALS_H
|
||||||
#ifndef GLOBALS_H
|
|
||||||
#define GLOBALS_H
|
// Estructura para definir un circulo
|
||||||
|
struct Circle
|
||||||
// Estructura para definir un circulo
|
{
|
||||||
struct Circle
|
Uint16 x;
|
||||||
{
|
Uint16 y;
|
||||||
Uint16 x;
|
Uint8 r;
|
||||||
Uint16 y;
|
};
|
||||||
Uint8 r;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
238
source/jail_audio.cpp
Normal file
238
source/jail_audio.cpp
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
#include "jail_audio.h"
|
||||||
|
#include "stb_vorbis.c"
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||||
|
|
||||||
|
struct JA_Sound_t {
|
||||||
|
Uint32 length {0};
|
||||||
|
Uint8* buffer {NULL};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_Channel_t {
|
||||||
|
JA_Sound sound;
|
||||||
|
int pos {0};
|
||||||
|
int times {0};
|
||||||
|
JA_Channel_state state { JA_CHANNEL_FREE };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_Music_t {
|
||||||
|
int samples {0};
|
||||||
|
int pos {0};
|
||||||
|
int times {0};
|
||||||
|
short* output {NULL};
|
||||||
|
JA_Music_state state {JA_MUSIC_INVALID};
|
||||||
|
};
|
||||||
|
|
||||||
|
JA_Music current_music{NULL};
|
||||||
|
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||||
|
|
||||||
|
int JA_freq {48000};
|
||||||
|
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||||
|
Uint8 JA_channels {2};
|
||||||
|
int JA_volume = 128;
|
||||||
|
|
||||||
|
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||||
|
SDL_memset(stream, 0, len);
|
||||||
|
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||||
|
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
||||||
|
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
||||||
|
current_music->pos += size/2;
|
||||||
|
if (size < len) {
|
||||||
|
if (current_music->times != 0) {
|
||||||
|
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
||||||
|
current_music->pos = (len-size)/2;
|
||||||
|
if (current_music->times > 0) current_music->times--;
|
||||||
|
} else {
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mixar els channels mi amol
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||||
|
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||||
|
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
||||||
|
channels[i].pos += size;
|
||||||
|
if (size < len) {
|
||||||
|
if (channels[i].times != 0) {
|
||||||
|
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
||||||
|
channels[i].pos = len-size;
|
||||||
|
if (channels[i].times > 0) channels[i].times--;
|
||||||
|
} else {
|
||||||
|
JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||||
|
JA_freq = freq;
|
||||||
|
JA_format = format;
|
||||||
|
JA_channels = channels;
|
||||||
|
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
||||||
|
SDL_AudioDeviceID sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||||
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music JA_LoadMusic(const char* filename) {
|
||||||
|
int chan, samplerate;
|
||||||
|
JA_Music music = new JA_Music_t();
|
||||||
|
|
||||||
|
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||||
|
FILE *f = fopen(filename, "rb");
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long fsize = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
|
||||||
|
fread(buffer, fsize, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
||||||
|
free(buffer);
|
||||||
|
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||||
|
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||||
|
cvt.len = music->samples * chan * 2;
|
||||||
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
free(music->output);
|
||||||
|
music->output = (short*)cvt.buf;
|
||||||
|
|
||||||
|
music->pos = 0;
|
||||||
|
music->state = JA_MUSIC_STOPPED;
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PlayMusic(JA_Music music, const int loop) {
|
||||||
|
if (current_music != NULL) {
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
current_music = music;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
|
current_music->times = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PauseMusic() {
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
current_music->state = JA_MUSIC_PAUSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_ResumeMusic() {
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_StopMusic() {
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music_state JA_GetMusicState() {
|
||||||
|
if (current_music == NULL) return JA_MUSIC_INVALID;
|
||||||
|
return current_music->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_DeleteMusic(JA_Music music) {
|
||||||
|
if (current_music == music) current_music = NULL;
|
||||||
|
SDL_free(music->output);
|
||||||
|
delete music;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||||
|
JA_Sound sound = new JA_Sound_t();
|
||||||
|
sound->buffer = buffer;
|
||||||
|
sound->length = length;
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound JA_LoadSound(const char* filename) {
|
||||||
|
JA_Sound sound = new JA_Sound_t();
|
||||||
|
SDL_AudioSpec wavSpec;
|
||||||
|
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||||
|
cvt.len = sound->length;
|
||||||
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
SDL_FreeWAV(sound->buffer);
|
||||||
|
sound->buffer = cvt.buf;
|
||||||
|
sound->length = cvt.len_cvt;
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_PlaySound(JA_Sound sound, const int loop) {
|
||||||
|
int channel = 0;
|
||||||
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
|
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
||||||
|
|
||||||
|
channels[channel].sound = sound;
|
||||||
|
channels[channel].times = loop;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_DeleteSound(JA_Sound sound) {
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
SDL_free(sound->buffer);
|
||||||
|
delete sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PauseChannel(const int channel) {
|
||||||
|
if (channel == -1) {
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
|
||||||
|
}
|
||||||
|
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||||
|
if (channels[channel].state == JA_CHANNEL_PLAYING) channels[channel].state = JA_CHANNEL_PAUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_ResumeChannel(const int channel) {
|
||||||
|
if (channel == -1) {
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
|
||||||
|
}
|
||||||
|
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||||
|
if (channels[channel].state == JA_CHANNEL_PAUSED) channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_StopChannel(const int channel) {
|
||||||
|
if (channel == -1) {
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
channels[i].state = JA_CHANNEL_FREE;
|
||||||
|
channels[i].pos = 0;
|
||||||
|
channels[i].sound = NULL;
|
||||||
|
}
|
||||||
|
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||||
|
channels[channel].state = JA_CHANNEL_FREE;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].sound = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Channel_state JA_GetChannelState(const int channel) {
|
||||||
|
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
||||||
|
return channels[channel].state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume) {
|
||||||
|
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||||
|
return JA_volume;
|
||||||
|
}
|
||||||
29
source/jail_audio.h
Normal file
29
source/jail_audio.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||||
|
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
||||||
|
|
||||||
|
typedef struct JA_Sound_t *JA_Sound;
|
||||||
|
typedef struct JA_Music_t *JA_Music;
|
||||||
|
|
||||||
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
|
||||||
|
|
||||||
|
JA_Music JA_LoadMusic(const char* filename);
|
||||||
|
void JA_PlayMusic(JA_Music music, const int loop = -1);
|
||||||
|
void JA_PauseMusic();
|
||||||
|
void JA_ResumeMusic();
|
||||||
|
void JA_StopMusic();
|
||||||
|
JA_Music_state JA_GetMusicState();
|
||||||
|
void JA_DeleteMusic(JA_Music music);
|
||||||
|
|
||||||
|
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length);
|
||||||
|
JA_Sound JA_LoadSound(const char* filename);
|
||||||
|
int JA_PlaySound(JA_Sound sound, const int loop = 0);
|
||||||
|
void JA_PauseChannel(const int channel);
|
||||||
|
void JA_ResumeChannel(const int channel);
|
||||||
|
void JA_StopChannel(const int channel);
|
||||||
|
JA_Channel_state JA_GetChannelState(const int channel);
|
||||||
|
void JA_DeleteSound(JA_Sound sound);
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume);
|
||||||
@@ -1,137 +1,206 @@
|
|||||||
#include "ltexture.h"
|
#include "ltexture.h"
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
LTexture::LTexture(SDL_Renderer *gRenderer)
|
#include "stb_image.h"
|
||||||
{
|
|
||||||
this->gRenderer = gRenderer;
|
LTexture::LTexture(SDL_Renderer *gRenderer)
|
||||||
|
{
|
||||||
// Initialize
|
this->gRenderer = gRenderer;
|
||||||
mTexture = NULL;
|
|
||||||
mWidth = 0;
|
// Initialize
|
||||||
mHeight = 0;
|
mTexture = NULL;
|
||||||
}
|
mWidth = 0;
|
||||||
|
mHeight = 0;
|
||||||
LTexture::~LTexture()
|
}
|
||||||
{
|
|
||||||
// Deallocate
|
LTexture::~LTexture()
|
||||||
free();
|
{
|
||||||
}
|
// Deallocate
|
||||||
|
free();
|
||||||
bool LTexture::loadFromFile(std::string path)
|
}
|
||||||
{
|
|
||||||
// Get rid of preexisting texture
|
bool LTexture::loadFromFile(std::string path)
|
||||||
free();
|
{
|
||||||
|
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||||
// The final texture
|
int req_format = STBI_rgb_alpha;
|
||||||
SDL_Texture *newTexture = NULL;
|
int width, height, orig_format;
|
||||||
|
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||||
// Load image at specified path
|
if (data == nullptr)
|
||||||
SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
{
|
||||||
if (loadedSurface == NULL)
|
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||||
{
|
exit(1);
|
||||||
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
printf("Image loaded: %s\n", filename.c_str());
|
||||||
// Color key image
|
}
|
||||||
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
|
||||||
|
int depth, pitch;
|
||||||
// Create texture from surface pixels
|
Uint32 pixel_format;
|
||||||
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
|
if (req_format == STBI_rgb)
|
||||||
if (newTexture == NULL)
|
{
|
||||||
{
|
depth = 24;
|
||||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||||
}
|
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
// Get image dimensions
|
{ // STBI_rgb_alpha (RGBA)
|
||||||
mWidth = loadedSurface->w;
|
depth = 32;
|
||||||
mHeight = loadedSurface->h;
|
pitch = 4 * width;
|
||||||
}
|
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||||
|
}
|
||||||
// Get rid of old loaded surface
|
|
||||||
SDL_FreeSurface(loadedSurface);
|
// Limpia
|
||||||
}
|
free();
|
||||||
|
|
||||||
// Return success
|
// La textura final
|
||||||
mTexture = newTexture;
|
SDL_Texture *newTexture = nullptr;
|
||||||
return mTexture != NULL;
|
|
||||||
}
|
// Carga la imagen desde una ruta específica
|
||||||
|
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||||
bool LTexture::createBlank(int width, int height, SDL_TextureAccess access)
|
if (loadedSurface == nullptr)
|
||||||
{
|
{
|
||||||
// Create uninitialized texture
|
printf("Unable to load image %s!\n", path.c_str());
|
||||||
mTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
}
|
||||||
if (mTexture == NULL)
|
else
|
||||||
{
|
{
|
||||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
// Crea la textura desde los pixels de la surface
|
||||||
}
|
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
|
||||||
else
|
if (newTexture == nullptr)
|
||||||
{
|
{
|
||||||
mWidth = width;
|
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
mHeight = height;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
return mTexture != NULL;
|
// Obtiene las dimensiones de la imagen
|
||||||
}
|
this->mWidth = loadedSurface->w;
|
||||||
|
this->mHeight = loadedSurface->h;
|
||||||
void LTexture::free()
|
}
|
||||||
{
|
|
||||||
// Free texture if it exists
|
// Elimina la textura cargada
|
||||||
if (mTexture != NULL)
|
SDL_FreeSurface(loadedSurface);
|
||||||
{
|
}
|
||||||
SDL_DestroyTexture(mTexture);
|
|
||||||
mTexture = NULL;
|
// Return success
|
||||||
mWidth = 0;
|
mTexture = newTexture;
|
||||||
mHeight = 0;
|
return mTexture != nullptr;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
/*
|
||||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
// Get rid of preexisting texture
|
||||||
{
|
free();
|
||||||
// Modulate texture rgb
|
|
||||||
SDL_SetTextureColorMod(mTexture, red, green, blue);
|
// The final texture
|
||||||
}
|
SDL_Texture *newTexture = NULL;
|
||||||
|
|
||||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
// Load image at specified path
|
||||||
{
|
SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
||||||
// Set blending function
|
if (loadedSurface == NULL)
|
||||||
SDL_SetTextureBlendMode(mTexture, blending);
|
{
|
||||||
}
|
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
|
||||||
|
}
|
||||||
void LTexture::setAlpha(Uint8 alpha)
|
else
|
||||||
{
|
{
|
||||||
// Modulate texture alpha
|
// Color key image
|
||||||
SDL_SetTextureAlphaMod(mTexture, alpha);
|
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
||||||
}
|
|
||||||
|
// Create texture from surface pixels
|
||||||
void LTexture::render(int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
|
||||||
{
|
if (newTexture == NULL)
|
||||||
// Set rendering space and render to screen
|
{
|
||||||
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
|
}
|
||||||
// Set clip rendering dimensions
|
else
|
||||||
if (clip != NULL)
|
{
|
||||||
{
|
// Get image dimensions
|
||||||
renderQuad.w = clip->w;
|
mWidth = loadedSurface->w;
|
||||||
renderQuad.h = clip->h;
|
mHeight = loadedSurface->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render to screen
|
// Get rid of old loaded surface
|
||||||
SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip);
|
SDL_FreeSurface(loadedSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LTexture::setAsRenderTarget()
|
// Return success
|
||||||
{
|
mTexture = newTexture;
|
||||||
// Make self render target
|
return mTexture != NULL;
|
||||||
SDL_SetRenderTarget(gRenderer, mTexture);
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int LTexture::getWidth()
|
bool LTexture::createBlank(int width, int height, SDL_TextureAccess access)
|
||||||
{
|
{
|
||||||
return mWidth;
|
// Create uninitialized texture
|
||||||
}
|
mTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||||
|
if (mTexture == NULL)
|
||||||
int LTexture::getHeight()
|
{
|
||||||
{
|
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||||
return mHeight;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mWidth = width;
|
||||||
|
mHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mTexture != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::free()
|
||||||
|
{
|
||||||
|
// Free texture if it exists
|
||||||
|
if (mTexture != NULL)
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(mTexture);
|
||||||
|
mTexture = NULL;
|
||||||
|
mWidth = 0;
|
||||||
|
mHeight = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||||
|
{
|
||||||
|
// Modulate texture rgb
|
||||||
|
SDL_SetTextureColorMod(mTexture, red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||||
|
{
|
||||||
|
// Set blending function
|
||||||
|
SDL_SetTextureBlendMode(mTexture, blending);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::setAlpha(Uint8 alpha)
|
||||||
|
{
|
||||||
|
// Modulate texture alpha
|
||||||
|
SDL_SetTextureAlphaMod(mTexture, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::render(int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||||
|
{
|
||||||
|
// Set rendering space and render to screen
|
||||||
|
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
||||||
|
|
||||||
|
// Set clip rendering dimensions
|
||||||
|
if (clip != NULL)
|
||||||
|
{
|
||||||
|
renderQuad.w = clip->w;
|
||||||
|
renderQuad.h = clip->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render to screen
|
||||||
|
SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LTexture::setAsRenderTarget()
|
||||||
|
{
|
||||||
|
// Make self render target
|
||||||
|
SDL_SetRenderTarget(gRenderer, mTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LTexture::getWidth()
|
||||||
|
{
|
||||||
|
return mWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LTexture::getHeight()
|
||||||
|
{
|
||||||
|
return mHeight;
|
||||||
}
|
}
|
||||||
@@ -1,71 +1,71 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef LTEXTURE_H
|
#ifndef LTEXTURE_H
|
||||||
#define LTEXTURE_H
|
#define LTEXTURE_H
|
||||||
|
|
||||||
// Texture wrapper class
|
// Texture wrapper class
|
||||||
class LTexture
|
class LTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Initializes variables
|
// Initializes variables
|
||||||
LTexture(SDL_Renderer *gRenderer);
|
LTexture(SDL_Renderer *gRenderer);
|
||||||
|
|
||||||
// Deallocates memory
|
// Deallocates memory
|
||||||
~LTexture();
|
~LTexture();
|
||||||
|
|
||||||
// Loads image at specified path
|
// Loads image at specified path
|
||||||
bool loadFromFile(std::string path);
|
bool loadFromFile(std::string path);
|
||||||
|
|
||||||
// Creates blank texture
|
// Creates blank texture
|
||||||
bool createBlank(int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
bool createBlank(int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||||
|
|
||||||
// Deallocates texture
|
// Deallocates texture
|
||||||
void free();
|
void free();
|
||||||
|
|
||||||
// Set color modulation
|
// Set color modulation
|
||||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||||
|
|
||||||
// Set blending
|
// Set blending
|
||||||
void setBlendMode(SDL_BlendMode blending);
|
void setBlendMode(SDL_BlendMode blending);
|
||||||
|
|
||||||
// Set alpha modulation
|
// Set alpha modulation
|
||||||
void setAlpha(Uint8 alpha);
|
void setAlpha(Uint8 alpha);
|
||||||
|
|
||||||
// Renders texture at given point
|
// Renders texture at given point
|
||||||
void render(int x, int y, SDL_Rect *clip = NULL, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
void render(int x, int y, SDL_Rect *clip = NULL, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
||||||
|
|
||||||
// Set self as render target
|
// Set self as render target
|
||||||
void setAsRenderTarget();
|
void setAsRenderTarget();
|
||||||
|
|
||||||
// Gets image dimensions
|
// Gets image dimensions
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Pixel manipulators
|
// Pixel manipulators
|
||||||
bool lockTexture();
|
bool lockTexture();
|
||||||
bool unlockTexture();
|
bool unlockTexture();
|
||||||
void *getPixels();
|
void *getPixels();
|
||||||
void copyPixels(void *pixels);
|
void copyPixels(void *pixels);
|
||||||
int getPitch();
|
int getPitch();
|
||||||
Uint32 getPixel32(unsigned int x, unsigned int y);
|
Uint32 getPixel32(unsigned int x, unsigned int y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// El renderizador de la ventana
|
// El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer = NULL;
|
SDL_Renderer *gRenderer = NULL;
|
||||||
|
|
||||||
// The actual hardware texture
|
// The actual hardware texture
|
||||||
SDL_Texture *mTexture;
|
SDL_Texture *mTexture;
|
||||||
void *mPixels;
|
void *mPixels;
|
||||||
int mPitch;
|
int mPitch;
|
||||||
|
|
||||||
// Image dimensions
|
// Image dimensions
|
||||||
int mWidth;
|
int mWidth;
|
||||||
int mHeight;
|
int mHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
369
source/main.cpp
369
source/main.cpp
@@ -1,196 +1,175 @@
|
|||||||
/*
|
/*
|
||||||
This source code copyrighted by JailDesigner (2020)
|
This source code copyrighted by JailDesigner (2020)
|
||||||
started on Castalla 15-07-2020.
|
started on Castalla 15-07-2020.
|
||||||
Using some sample source code from Lazy Foo' Productions
|
Using some sample source code from Lazy Foo' Productions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*Descripción del enfoque utilizado para crear el juego.
|
/*Descripción del enfoque utilizado para crear el juego.
|
||||||
|
|
||||||
El programa contine una serie de clases/objetos básicos: la clase sprite
|
El programa contine una serie de clases/objetos básicos: la clase sprite
|
||||||
permite dibujar partes de un fichero png en pantalla. La clase spriteanimated
|
permite dibujar partes de un fichero png en pantalla. La clase spriteanimated
|
||||||
contiene funcionalidad adicional para crear animaciones. La clase text permite
|
contiene funcionalidad adicional para crear animaciones. La clase text permite
|
||||||
dibujar letras de un png en pantalla a partir de una cadena de texto. La clase
|
dibujar letras de un png en pantalla a partir de una cadena de texto. La clase
|
||||||
menu permite crear una estructura con diferentes elementos, escribirlos en
|
menu permite crear una estructura con diferentes elementos, escribirlos en
|
||||||
pantalla y seleccionar uno de ellos.
|
pantalla y seleccionar uno de ellos.
|
||||||
|
|
||||||
A continuación tenemos las clases enfocadas a la lógica del juego, la clase player
|
A continuación tenemos las clases enfocadas a la lógica del juego, la clase player
|
||||||
contiene la información del jugador, la clase balloon la de los enemigos y la
|
contiene la información del jugador, la clase balloon la de los enemigos y la
|
||||||
clase bullet para las balas que dispara el jugador. La clase background es
|
clase bullet para las balas que dispara el jugador. La clase background es
|
||||||
muy simple y sirve para pintar el fondo de la pantalla. Por ultimo, la clase
|
muy simple y sirve para pintar el fondo de la pantalla. Por ultimo, la clase
|
||||||
gamedirector es la que realiza toda la lógica y se encarga de hacer interactuar
|
gamedirector es la que realiza toda la lógica y se encarga de hacer interactuar
|
||||||
al resto de objetos entre si.
|
al resto de objetos entre si.
|
||||||
|
|
||||||
El objeto gamedirector tiene tres estados: titulo, juego y pausa. Segun su estado
|
El objeto gamedirector tiene tres estados: titulo, juego y pausa. Segun su estado
|
||||||
el bucle que recorre es distinto. En el bucle juego, el objeto gamedirector
|
el bucle que recorre es distinto. En el bucle juego, el objeto gamedirector
|
||||||
tiene un objeto jugador, un vector con los objetos globo y un vector con los
|
tiene un objeto jugador, un vector con los objetos globo y un vector con los
|
||||||
objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
||||||
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
||||||
el vector de globos y de balas y si tienen algun tipo asignado las gestiona.
|
el vector de globos y de balas y si tienen algun tipo asignado las gestiona.
|
||||||
Comprueba las colisiones entre los globos y el jugador y entre las balas y los
|
Comprueba las colisiones entre los globos y el jugador y entre las balas y los
|
||||||
globos. Tiene ademas un nivel de amenaza que calcula en funcion del numero de globos
|
globos. Tiene ademas un nivel de amenaza que calcula en funcion del numero de globos
|
||||||
en pantalla y que se va incrementando conforme aumenta la puntuación del jugador.
|
en pantalla y que se va incrementando conforme aumenta la puntuación del jugador.
|
||||||
|
|
||||||
Los objetos globo tienen varios contadores para alternar de un estado a otro.
|
Los objetos globo tienen varios contadores para alternar de un estado a otro.
|
||||||
|
|
||||||
En los vectores que contienen objetos, se considera activos los objetos que tienen
|
En los vectores que contienen objetos, se considera activos los objetos que tienen
|
||||||
un tipo asociado diferente a NO_KIND
|
un tipo asociado diferente a NO_KIND
|
||||||
*/
|
*/
|
||||||
#define TEST_
|
|
||||||
|
#include "background.h"
|
||||||
#include "background.h"
|
#include "balloon.h"
|
||||||
#include "balloon.h"
|
#include "bullet.h"
|
||||||
#include "bullet.h"
|
#include "const.h"
|
||||||
#include "const.h"
|
#include "gamedirector.h"
|
||||||
#include "gamedirector.h"
|
#include "globals.h"
|
||||||
#include "globals.h"
|
#include "ltexture.h"
|
||||||
#include "ltexture.h"
|
#include "menu.h"
|
||||||
#include "menu.h"
|
#include "player.h"
|
||||||
#include "player.h"
|
#include "sprite.h"
|
||||||
#include "sprite.h"
|
#include "spriteanimated.h"
|
||||||
#include "spriteanimated.h"
|
#include "text.h"
|
||||||
#include "text.h"
|
#include <iostream>
|
||||||
#include <iostream>
|
#include <stdio.h>
|
||||||
#include <stdio.h>
|
#include <string>
|
||||||
#include <string>
|
|
||||||
|
// La ventana donde dibujamos
|
||||||
// La ventana donde dibujamos
|
SDL_Window *gWindow = NULL;
|
||||||
SDL_Window *gWindow = NULL;
|
|
||||||
|
// El renderizador de la ventana
|
||||||
// El renderizador de la ventana
|
SDL_Renderer *gRenderer = NULL;
|
||||||
SDL_Renderer *gRenderer = NULL;
|
|
||||||
|
// Arranca SDL y crea la ventana
|
||||||
// Arranca SDL y crea la ventana
|
bool init();
|
||||||
bool init();
|
|
||||||
|
// Carga todos los recursos
|
||||||
// Carga todos los recursos
|
bool loadMedia();
|
||||||
bool loadMedia();
|
|
||||||
|
// Libera todos los recursos y cierra SDL
|
||||||
// Libera todos los recursos y cierra SDL
|
void close();
|
||||||
void close();
|
|
||||||
|
// Arranca SDL y crea la ventana
|
||||||
// Arranca SDL y crea la ventana
|
bool init()
|
||||||
bool init()
|
{
|
||||||
{
|
// Indicador de inicialización
|
||||||
// Indicador de inicialización
|
bool success = true;
|
||||||
bool success = true;
|
|
||||||
|
// Inicializa SDL
|
||||||
// Inicializa SDL
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
|
{
|
||||||
{
|
printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
|
||||||
printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
|
success = false;
|
||||||
success = false;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
// Establece el filtro de la textura a nearest
|
||||||
// Establece el filtro de la textura a nearest
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"))
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"))
|
{
|
||||||
{
|
printf("Warning: Nearest texture filtering not enabled!");
|
||||||
printf("Warning: Nearest texture filtering not enabled!");
|
}
|
||||||
}
|
|
||||||
|
// Crea la ventana
|
||||||
// Inicializa SDL_mixer
|
gWindow = SDL_CreateWindow("Super Popping (Like Loc) in Jailers World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN);
|
||||||
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
|
if (gWindow == NULL)
|
||||||
{
|
{
|
||||||
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
|
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Crea la ventana
|
{
|
||||||
gWindow = SDL_CreateWindow("Super Popping (Like Loc) in Jailers World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN);
|
// Crea un renderizador para la ventana con vsync
|
||||||
if (gWindow == NULL)
|
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
{
|
if (gRenderer == NULL)
|
||||||
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
|
{
|
||||||
success = false;
|
printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
|
||||||
}
|
success = false;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
// Crea un renderizador para la ventana con vsync
|
{
|
||||||
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
// Inicializa el color de renderizado
|
||||||
if (gRenderer == NULL)
|
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
{
|
|
||||||
printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
|
// Establece el tamaño del buffer de renderizado
|
||||||
success = false;
|
SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
// Inicializa el color de renderizado
|
|
||||||
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
|
// Inicializa JailAudio
|
||||||
|
JA_Init(44100, AUDIO_S16, 2);
|
||||||
// Establece el tamaño del buffer de renderizado
|
|
||||||
SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
return success;
|
||||||
|
}
|
||||||
// Inicializa el cargador de PNG
|
|
||||||
int imgFlags = IMG_INIT_PNG;
|
// Libera todos los recursos y cierra SDL
|
||||||
if (!(IMG_Init(imgFlags) & imgFlags))
|
void close()
|
||||||
{
|
{
|
||||||
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
|
// Destruye la ventana
|
||||||
success = false;
|
SDL_DestroyRenderer(gRenderer);
|
||||||
}
|
SDL_DestroyWindow(gWindow);
|
||||||
}
|
gWindow = NULL;
|
||||||
}
|
gRenderer = NULL;
|
||||||
}
|
|
||||||
|
// Sal del subsistema SDL
|
||||||
return success;
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera todos los recursos y cierra SDL
|
int main(int argc, char *args[])
|
||||||
void close()
|
{
|
||||||
{
|
// Arranca SDL y crea la ventana
|
||||||
// Destruye la ventana
|
if (!init())
|
||||||
SDL_DestroyRenderer(gRenderer);
|
{
|
||||||
SDL_DestroyWindow(gWindow);
|
printf("Failed to initialize!\n");
|
||||||
gWindow = NULL;
|
return -1;
|
||||||
gRenderer = NULL;
|
}
|
||||||
|
else
|
||||||
// Sal del subsistema SDL
|
{
|
||||||
IMG_Quit();
|
{
|
||||||
SDL_Quit();
|
// Crea el objeto gameDirector
|
||||||
}
|
GameDirector gameDirector(gRenderer);
|
||||||
|
|
||||||
int main(int argc, char *args[])
|
// Mientras no se quiera salir del juego
|
||||||
{
|
while (!(gameDirector.getGameStatus() == GAME_STATE_QUIT))
|
||||||
// Arranca SDL y crea la ventana
|
{
|
||||||
if (!init())
|
switch (gameDirector.getGameStatus())
|
||||||
{
|
{
|
||||||
printf("Failed to initialize!\n");
|
case GAME_STATE_TITLE:
|
||||||
return -1;
|
gameDirector.runTitle();
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
case GAME_STATE_PLAYING:
|
||||||
{
|
gameDirector.runGame();
|
||||||
// Crea el objeto gameDirector
|
break;
|
||||||
GameDirector gameDirector(gRenderer);
|
|
||||||
|
case GAME_STATE_PAUSED:
|
||||||
// Inicializa el objeto gameDirector
|
gameDirector.runPausedGame();
|
||||||
gameDirector.init();
|
break;
|
||||||
|
}
|
||||||
#ifdef TEST
|
}
|
||||||
gameDirector.resetBalloons();
|
}
|
||||||
#endif
|
|
||||||
|
// Libera todos los recursos y cierra SDL
|
||||||
// Mientras no se quiera salir del juego
|
close();
|
||||||
while (!(gameDirector.getGameStatus() == GAME_STATE_QUIT))
|
|
||||||
{
|
return 0;
|
||||||
switch (gameDirector.getGameStatus())
|
}
|
||||||
{
|
|
||||||
case GAME_STATE_TITLE:
|
|
||||||
gameDirector.runTitle();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GAME_STATE_PLAYING:
|
|
||||||
gameDirector.runGame();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GAME_STATE_PAUSED:
|
|
||||||
gameDirector.runPausedGame();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Libera todos los recursos y cierra SDL
|
|
||||||
close();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
418
source/menu.cpp
418
source/menu.cpp
@@ -1,210 +1,210 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu::Menu(SDL_Renderer *gRenderer)
|
Menu::Menu(SDL_Renderer *gRenderer)
|
||||||
{
|
{
|
||||||
this->gRenderer = gRenderer;
|
this->gRenderer = gRenderer;
|
||||||
|
|
||||||
gMenuTexture = new LTexture(gRenderer);
|
gMenuTexture = new LTexture(gRenderer);
|
||||||
// Carga los gráficos para el menu
|
// Carga los gráficos para el menu
|
||||||
if (!gMenuTexture->loadFromFile("media/gfx/menu.png"))
|
if (!gMenuTexture->loadFromFile("media/gfx/menu.png"))
|
||||||
{
|
{
|
||||||
printf("Failed to load menu texture!\n");
|
printf("Failed to load menu texture!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
init(0, 0, 0, MENU_BACKGROUND_SOLID);
|
//init(0, 0, 0, MENU_BACKGROUND_SOLID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Menu::~Menu()
|
Menu::~Menu()
|
||||||
{
|
{
|
||||||
gMenuTexture->free();
|
gMenuTexture->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void Menu::init(int x, int y, int offset_sprite_selector, int backgroundType)
|
void Menu::init(int x, int y, int offset_sprite_selector, int backgroundType)
|
||||||
{
|
{
|
||||||
// Inicia variables
|
// Inicia variables
|
||||||
mSelectorIndex = 0;
|
mSelectorIndex = 0;
|
||||||
mTotalItems = 0;
|
mTotalItems = 0;
|
||||||
mItemSelected = MENU_NO_OPTION;
|
mItemSelected = MENU_NO_OPTION;
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
mRect.x = 0;
|
mRect.x = 0;
|
||||||
mRect.y = 0;
|
mRect.y = 0;
|
||||||
mRect.w = 0;
|
mRect.w = 0;
|
||||||
mRect.h = 0;
|
mRect.h = 0;
|
||||||
mRectR = 0;
|
mRectR = 0;
|
||||||
mRectG = 0;
|
mRectG = 0;
|
||||||
mRectB = 0;
|
mRectB = 0;
|
||||||
mBackgroundType = backgroundType;
|
mBackgroundType = backgroundType;
|
||||||
|
|
||||||
// Sprite con los graficos del selector
|
// Sprite con los graficos del selector
|
||||||
mSelectorSprite.setWidth(8);
|
mSelectorSprite.setWidth(8);
|
||||||
mSelectorSprite.setHeight(8);
|
mSelectorSprite.setHeight(8);
|
||||||
mSelectorSprite.setPosX(0);
|
mSelectorSprite.setPosX(0);
|
||||||
mSelectorSprite.setPosY(0);
|
mSelectorSprite.setPosY(0);
|
||||||
mSelectorSprite.setTexture(*gMenuTexture);
|
mSelectorSprite.setTexture(*gMenuTexture);
|
||||||
mSelectorSprite.setSpriteClip(offset_sprite_selector, 0, mSelectorSprite.getWidth(), mSelectorSprite.getHeight());
|
mSelectorSprite.setSpriteClip(offset_sprite_selector, 0, mSelectorSprite.getWidth(), mSelectorSprite.getHeight());
|
||||||
|
|
||||||
// Elementos del menu
|
// Elementos del menu
|
||||||
for (Uint8 i = 0; i < 10; i++)
|
for (Uint8 i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
mMenuItem[i].label = "";
|
mMenuItem[i].x = mPosX;
|
||||||
mMenuItem[i].x = mPosX;
|
mMenuItem[i].y = mPosY + (i * (BLOCK + 2));
|
||||||
mMenuItem[i].y = mPosY + (i * (BLOCK + 2));
|
mMenuItem[i].label = "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el grafico del selector al elemento seleccionado
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
moveSelectorSprite(mSelectorIndex);
|
moveSelectorSprite(mSelectorIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 Menu::getItemSelected()
|
Uint8 Menu::getItemSelected()
|
||||||
{
|
{
|
||||||
return mItemSelected;
|
return mItemSelected;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mueve el grafico del selector al elemento seleccionado
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
void Menu::moveSelectorSprite(int pos)
|
void Menu::moveSelectorSprite(int pos)
|
||||||
{
|
{
|
||||||
mSelectorSprite.setPosX(mMenuItem[pos].x - (BLOCK * 1));
|
mSelectorSprite.setPosX(mMenuItem[pos].x - (BLOCK * 1));
|
||||||
mSelectorSprite.setPosY(mMenuItem[pos].y);
|
mSelectorSprite.setPosY(mMenuItem[pos].y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
// Deja el menu apuntando al primer elemento
|
||||||
void Menu::resetMenu()
|
void Menu::resetMenu()
|
||||||
{
|
{
|
||||||
mItemSelected = MENU_NO_OPTION;
|
mItemSelected = MENU_NO_OPTION;
|
||||||
mSelectorIndex = 0;
|
mSelectorIndex = 0;
|
||||||
moveSelectorSprite(mSelectorIndex);
|
moveSelectorSprite(mSelectorIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Deja el menu apuntando al siguiente elemento
|
// Deja el menu apuntando al siguiente elemento
|
||||||
void Menu::increaseSelectorIndex()
|
void Menu::increaseSelectorIndex()
|
||||||
{
|
{
|
||||||
if (mSelectorIndex < (mTotalItems - 1))
|
if (mSelectorIndex < (mTotalItems - 1))
|
||||||
{
|
{
|
||||||
++mSelectorIndex;
|
++mSelectorIndex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Deja el menu apuntando al elemento anterior
|
// Deja el menu apuntando al elemento anterior
|
||||||
void Menu::decreaseSelectorIndex()
|
void Menu::decreaseSelectorIndex()
|
||||||
{
|
{
|
||||||
if (mSelectorIndex > 0)
|
if (mSelectorIndex > 0)
|
||||||
{
|
{
|
||||||
--mSelectorIndex;
|
--mSelectorIndex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
||||||
void Menu::checkInput(Uint8 input)
|
void Menu::checkInput(Uint8 input)
|
||||||
{
|
{
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case INPUT_UP:
|
case INPUT_UP:
|
||||||
decreaseSelectorIndex();
|
decreaseSelectorIndex();
|
||||||
moveSelectorSprite(mSelectorIndex);
|
moveSelectorSprite(mSelectorIndex);
|
||||||
break;
|
break;
|
||||||
case INPUT_DOWN:
|
case INPUT_DOWN:
|
||||||
increaseSelectorIndex();
|
increaseSelectorIndex();
|
||||||
moveSelectorSprite(mSelectorIndex);
|
moveSelectorSprite(mSelectorIndex);
|
||||||
break;
|
break;
|
||||||
case INPUT_FIRE:
|
case INPUT_FIRE:
|
||||||
mItemSelected = mSelectorIndex;
|
mItemSelected = mSelectorIndex;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el menu en pantalla
|
// Pinta el menu en pantalla
|
||||||
void Menu::render(Text &text)
|
void Menu::render(Text &text)
|
||||||
{
|
{
|
||||||
// Render color filled quad
|
// Render color filled quad
|
||||||
if (mBackgroundType == MENU_BACKGROUND_SOLID)
|
if (mBackgroundType == MENU_BACKGROUND_SOLID)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(gRenderer, mRectR, mRectG, mRectB, mRectA);
|
SDL_SetRenderDrawColor(gRenderer, mRectR, mRectG, mRectB, mRectA);
|
||||||
SDL_RenderFillRect(gRenderer, &mRect);
|
SDL_RenderFillRect(gRenderer, &mRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render text
|
// Render text
|
||||||
int i = 0;
|
int i = 0;
|
||||||
mSelectorSprite.render();
|
mSelectorSprite.render();
|
||||||
for (i = 0; i < mTotalItems; i++)
|
for (i = 0; i < mTotalItems; i++)
|
||||||
{
|
{
|
||||||
text.write(mMenuItem[i].x, mMenuItem[i].y, mMenuItem[i].label);
|
text.write(mMenuItem[i].x, mMenuItem[i].y, mMenuItem[i].label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu
|
// Establece el rectangulo de fondo del menu
|
||||||
void Menu::setRectSize()
|
void Menu::setRectSize()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int maxLength = 0;
|
int maxLength = 0;
|
||||||
|
|
||||||
// La altura se corresponde al numero de items mas un hueco arriba y otro abajo
|
// La altura se corresponde al numero de items mas un hueco arriba y otro abajo
|
||||||
mRect.h = (mTotalItems + 2) * BLOCK;
|
mRect.h = (mTotalItems + 2) * BLOCK;
|
||||||
|
|
||||||
// La anchura es la de la cadena mas larga mas tres bloques, uno por la derecha
|
// La anchura es la de la cadena mas larga mas tres bloques, uno por la derecha
|
||||||
// y dos por la izquierda, uno de ellos para el selector
|
// y dos por la izquierda, uno de ellos para el selector
|
||||||
for (i = 0; i < mTotalItems; i++)
|
for (i = 0; i < mTotalItems; i++)
|
||||||
{
|
{
|
||||||
if ((int)mMenuItem[i].label.length() > maxLength)
|
if ((int)mMenuItem[i].label.length() > maxLength)
|
||||||
{
|
{
|
||||||
maxLength = mMenuItem[i].label.length();
|
maxLength = mMenuItem[i].label.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mRect.w = (maxLength + 3) * BLOCK;
|
mRect.w = (maxLength + 3) * BLOCK;
|
||||||
|
|
||||||
mRect.x = mPosX - (BLOCK * 2);
|
mRect.x = mPosX - (BLOCK * 2);
|
||||||
mRect.y = mPosY - BLOCK;
|
mRect.y = mPosY - BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Menu::setTotalItems(int num)
|
void Menu::setTotalItems(int num)
|
||||||
{
|
{
|
||||||
mTotalItems = num;
|
mTotalItems = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color del rectangulo de fondo
|
// Establece el color del rectangulo de fondo
|
||||||
void Menu::setBackgroundColor(int r, int g, int b, int alpha)
|
void Menu::setBackgroundColor(int r, int g, int b, int alpha)
|
||||||
{
|
{
|
||||||
mRectR = r;
|
mRectR = r;
|
||||||
mRectG = g;
|
mRectG = g;
|
||||||
mRectB = b;
|
mRectB = b;
|
||||||
mRectA = alpha;
|
mRectA = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el menu en pantalla
|
// Centra el menu en pantalla
|
||||||
void Menu::centerMenuOnScreen()
|
void Menu::centerMenuOnScreen()
|
||||||
{
|
{
|
||||||
// Actualiza el rectangulo de fondo para recalcular las dimensiones
|
// Actualiza el rectangulo de fondo para recalcular las dimensiones
|
||||||
setRectSize();
|
setRectSize();
|
||||||
|
|
||||||
// Establece la nueva posición centrada en funcion del ancho
|
// Establece la nueva posición centrada en funcion del ancho
|
||||||
// de la pantalla y del ancho del rectangulo
|
// de la pantalla y del ancho del rectangulo
|
||||||
mPosX = (SCREEN_WIDTH / 2) - (mRect.w / 2) + (BLOCK * 2);
|
mPosX = (SCREEN_WIDTH / 2) - (mRect.w / 2) + (BLOCK * 2);
|
||||||
|
|
||||||
// Reposiciona los elementos del menu
|
// Reposiciona los elementos del menu
|
||||||
for (Uint8 i = 0; i < 10; i++)
|
for (Uint8 i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
mMenuItem[i].x = mPosX;
|
mMenuItem[i].x = mPosX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalcula el rectangulo de fondo
|
// Recalcula el rectangulo de fondo
|
||||||
setRectSize();
|
setRectSize();
|
||||||
|
|
||||||
// Recoloca el selector
|
// Recoloca el selector
|
||||||
moveSelectorSprite(mSelectorIndex);
|
moveSelectorSprite(mSelectorIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade un item al menu
|
// Añade un item al menu
|
||||||
void Menu::addItem(std::string text)
|
void Menu::addItem(std::string text)
|
||||||
{
|
{
|
||||||
if (mTotalItems < 10)
|
if (mTotalItems < 10)
|
||||||
{
|
{
|
||||||
mMenuItem[mTotalItems].label = text;
|
mMenuItem[mTotalItems].label = text;
|
||||||
setTotalItems(mTotalItems + 1);
|
setTotalItems(mTotalItems + 1);
|
||||||
setRectSize();
|
setRectSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
200
source/menu.h
200
source/menu.h
@@ -1,101 +1,101 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
#ifndef MENU_H
|
#ifndef MENU_H
|
||||||
#define MENU_H
|
#define MENU_H
|
||||||
|
|
||||||
// Clase menu
|
// Clase menu
|
||||||
class Menu
|
class Menu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu(SDL_Renderer *gRenderer);
|
Menu(SDL_Renderer *gRenderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Menu();
|
~Menu();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(int x, int y, int offset_sprite_selector, int backgroundType);
|
void init(int x, int y, int offset_sprite_selector, int backgroundType);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 getItemSelected();
|
Uint8 getItemSelected();
|
||||||
|
|
||||||
// Mueve el grafico del selector al elemento seleccionado
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
void moveSelectorSprite(int pos);
|
void moveSelectorSprite(int pos);
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
// Deja el menu apuntando al primer elemento
|
||||||
void resetMenu();
|
void resetMenu();
|
||||||
|
|
||||||
// Deja el menu apuntando al siguiente elemento
|
// Deja el menu apuntando al siguiente elemento
|
||||||
void increaseSelectorIndex();
|
void increaseSelectorIndex();
|
||||||
|
|
||||||
// Deja el menu apuntando al elemento anterior
|
// Deja el menu apuntando al elemento anterior
|
||||||
void decreaseSelectorIndex();
|
void decreaseSelectorIndex();
|
||||||
|
|
||||||
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
||||||
void checkInput(Uint8 input);
|
void checkInput(Uint8 input);
|
||||||
|
|
||||||
// Pinta el menu en pantalla
|
// Pinta el menu en pantalla
|
||||||
void render(Text &text);
|
void render(Text &text);
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu
|
// Establece el rectangulo de fondo del menu
|
||||||
void setRectSize();
|
void setRectSize();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setTotalItems(int num);
|
void setTotalItems(int num);
|
||||||
|
|
||||||
// Establece el color del rectangulo de fondo
|
// Establece el color del rectangulo de fondo
|
||||||
void setBackgroundColor(int r, int g, int b, int alpha);
|
void setBackgroundColor(int r, int g, int b, int alpha);
|
||||||
|
|
||||||
// Centra el menu en pantalla
|
// Centra el menu en pantalla
|
||||||
void centerMenuOnScreen();
|
void centerMenuOnScreen();
|
||||||
|
|
||||||
// Añade un item al menu
|
// Añade un item al menu
|
||||||
void addItem(std::string text);
|
void addItem(std::string text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// El renderizador de la ventana
|
// El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer;
|
SDL_Renderer *gRenderer;
|
||||||
|
|
||||||
LTexture *gMenuTexture;
|
LTexture *gMenuTexture;
|
||||||
|
|
||||||
// Posicion X/Y del texto del primer elemento del menu
|
// Posicion X/Y del texto del primer elemento del menu
|
||||||
int mPosX;
|
int mPosX;
|
||||||
int mPosY;
|
int mPosY;
|
||||||
|
|
||||||
// Elemento del menu que tiene el foco
|
// Elemento del menu que tiene el foco
|
||||||
Uint8 mSelectorIndex;
|
Uint8 mSelectorIndex;
|
||||||
|
|
||||||
// Numero de items del menu
|
// Numero de items del menu
|
||||||
Uint8 mTotalItems;
|
Uint8 mTotalItems;
|
||||||
|
|
||||||
// Item del menu que ha sido seleccionado
|
// Item del menu que ha sido seleccionado
|
||||||
Uint8 mItemSelected;
|
Uint8 mItemSelected;
|
||||||
|
|
||||||
// Tipo de fondo para el menu
|
// Tipo de fondo para el menu
|
||||||
Uint8 mBackgroundType;
|
Uint8 mBackgroundType;
|
||||||
|
|
||||||
// Sprite con los graficos del selector
|
// Sprite con los graficos del selector
|
||||||
Sprite mSelectorSprite;
|
Sprite mSelectorSprite;
|
||||||
|
|
||||||
// Rectangulo y colores para el fondo del menu
|
// Rectangulo y colores para el fondo del menu
|
||||||
SDL_Rect mRect;
|
SDL_Rect mRect;
|
||||||
Uint8 mRectR; // Rojo
|
Uint8 mRectR; // Rojo
|
||||||
Uint8 mRectG; // Verde
|
Uint8 mRectG; // Verde
|
||||||
Uint8 mRectB; // Azul
|
Uint8 mRectB; // Azul
|
||||||
Uint8 mRectA; // Alfa o transparencia
|
Uint8 mRectA; // Alfa o transparencia
|
||||||
|
|
||||||
// Estructura para cada elemento del menu
|
// Estructura para cada elemento del menu
|
||||||
struct MenuItem
|
struct MenuItem
|
||||||
{
|
{
|
||||||
std::string label;
|
std::string label;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} mMenuItem[10];
|
} mMenuItem[10];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,268 +1,268 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(SDL_Renderer *gRenderer)
|
Player::Player(SDL_Renderer *gRenderer)
|
||||||
{
|
{
|
||||||
this->gRenderer = gRenderer;
|
this->gRenderer = gRenderer;
|
||||||
|
|
||||||
gPlayerTexture = new LTexture(gRenderer);
|
gPlayerTexture = new LTexture(gRenderer);
|
||||||
|
|
||||||
// Carga los gráficos del jugador
|
// Carga los gráficos del jugador
|
||||||
if (!gPlayerTexture->loadFromFile("media/gfx/player.png"))
|
if (!gPlayerTexture->loadFromFile("media/gfx/player.png"))
|
||||||
{
|
{
|
||||||
printf("Failed to load player texture!\n");
|
printf("Failed to load player texture!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
gPlayerTexture->free();
|
gPlayerTexture->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void Player::init()
|
void Player::init()
|
||||||
{
|
{
|
||||||
// Establece la altura y el ancho del jugador
|
// Establece la altura y el ancho del jugador
|
||||||
mWidth = 3 * BLOCK;
|
mWidth = 3 * BLOCK;
|
||||||
mHeight = 3 * BLOCK;
|
mHeight = 3 * BLOCK;
|
||||||
|
|
||||||
// Establece la posición inicial del jugador
|
// Establece la posición inicial del jugador
|
||||||
mPosX = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2) - (mWidth / 2);
|
mPosX = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2) - (mWidth / 2);
|
||||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
||||||
|
|
||||||
// Establece el tamaño del circulo de colisión
|
// Establece el tamaño del circulo de colisión
|
||||||
mCollider.r = 7;
|
mCollider.r = 7;
|
||||||
|
|
||||||
// Actualiza la posición del circulo de colisión
|
// Actualiza la posición del circulo de colisión
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
|
|
||||||
// Establece la velocidad inicial
|
// Establece la velocidad inicial
|
||||||
mVelX = 0;
|
mVelX = 0;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
|
|
||||||
// Establece la velocidad base
|
// Establece la velocidad base
|
||||||
mBaseSpeed = 1.5;
|
mBaseSpeed = 1.5;
|
||||||
|
|
||||||
// Establece el numero inicial de vidas
|
// Establece el numero inicial de vidas
|
||||||
mStartingLives = 3;
|
mStartingLives = 3;
|
||||||
mLives = mStartingLives;
|
mLives = mStartingLives;
|
||||||
|
|
||||||
// Establece la puntuación inicial
|
// Establece la puntuación inicial
|
||||||
mScore = 0;
|
mScore = 0;
|
||||||
|
|
||||||
// Inicia el contador
|
// Inicia el contador
|
||||||
mCooldown = 10;
|
mCooldown = 10;
|
||||||
|
|
||||||
// Inicia el sprite
|
// Inicia el sprite
|
||||||
mSprite.init();
|
mSprite.init();
|
||||||
|
|
||||||
// Set width and height of the player sprite
|
// Set width and height of the player sprite
|
||||||
mSprite.setWidth(mWidth);
|
mSprite.setWidth(mWidth);
|
||||||
mSprite.setHeight(mHeight);
|
mSprite.setHeight(mHeight);
|
||||||
|
|
||||||
// Set sprite position
|
// Set sprite position
|
||||||
mSprite.setPosX(mPosX);
|
mSprite.setPosX(mPosX);
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
|
|
||||||
// Set sprite sheet
|
// Set sprite sheet
|
||||||
mSprite.setTexture(*gPlayerTexture);
|
mSprite.setTexture(*gPlayerTexture);
|
||||||
|
|
||||||
// Set status
|
// Set status
|
||||||
mStatus = PLAYER_STATE_STOPPED;
|
mStatus = PLAYER_STATE_STOPPED;
|
||||||
|
|
||||||
// Initialize animation variables
|
// Initialize animation variables
|
||||||
mSprite.setCurrentFrame(0);
|
mSprite.setCurrentFrame(0);
|
||||||
mSprite.setAnimationCounter(0);
|
mSprite.setAnimationCounter(0);
|
||||||
|
|
||||||
mSprite.setAnimationNumFrames(PLAYER_STATE_STOPPED, 1);
|
mSprite.setAnimationNumFrames(PLAYER_STATE_STOPPED, 1);
|
||||||
mSprite.setAnimationNumFrames(PLAYER_STATE_WALKING_LEFT, 4);
|
mSprite.setAnimationNumFrames(PLAYER_STATE_WALKING_LEFT, 4);
|
||||||
mSprite.setAnimationNumFrames(PLAYER_STATE_WALKING_RIGHT, 4);
|
mSprite.setAnimationNumFrames(PLAYER_STATE_WALKING_RIGHT, 4);
|
||||||
|
|
||||||
mSprite.setAnimationSpeed(PLAYER_STATE_STOPPED, 10);
|
mSprite.setAnimationSpeed(PLAYER_STATE_STOPPED, 10);
|
||||||
mSprite.setAnimationSpeed(PLAYER_STATE_WALKING_LEFT, 5);
|
mSprite.setAnimationSpeed(PLAYER_STATE_WALKING_LEFT, 5);
|
||||||
mSprite.setAnimationSpeed(PLAYER_STATE_WALKING_RIGHT, 5);
|
mSprite.setAnimationSpeed(PLAYER_STATE_WALKING_RIGHT, 5);
|
||||||
|
|
||||||
// Set animation clips
|
// Set animation clips
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 0, mSprite.getWidth() * 0, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 0, mSprite.getWidth() * 0, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 1, mSprite.getWidth() * 1, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 1, mSprite.getWidth() * 1, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 2, mSprite.getWidth() * 2, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 2, mSprite.getWidth() * 2, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 3, mSprite.getWidth() * 3, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_LEFT, 3, mSprite.getWidth() * 3, mSprite.getWidth() * 0, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 0, mSprite.getWidth() * 0, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 0, mSprite.getWidth() * 0, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 1, mSprite.getWidth() * 1, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 1, mSprite.getWidth() * 1, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 2, mSprite.getWidth() * 2, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 2, mSprite.getWidth() * 2, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 3, mSprite.getWidth() * 3, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_WALKING_RIGHT, 3, mSprite.getWidth() * 3, mSprite.getHeight() * 1, mSprite.getWidth(), mSprite.getHeight());
|
||||||
mSprite.setAnimationFrames(PLAYER_STATE_STOPPED, 0, mSprite.getWidth() * 0, mSprite.getHeight() * 2, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setAnimationFrames(PLAYER_STATE_STOPPED, 0, mSprite.getWidth() * 0, mSprite.getHeight() * 2, mSprite.getWidth(), mSprite.getHeight());
|
||||||
|
|
||||||
// Set window for sprite sheet
|
// Set window for sprite sheet
|
||||||
mSprite.setSpriteClip(mSprite.getAnimationClip(PLAYER_STATE_STOPPED, 0));
|
mSprite.setSpriteClip(mSprite.getAnimationClip(PLAYER_STATE_STOPPED, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado y actua en consecuencia
|
// Comprueba el teclado y actua en consecuencia
|
||||||
void Player::checkInput(Uint8 input)
|
void Player::checkInput(Uint8 input)
|
||||||
{
|
{
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case INPUT_LEFT:
|
case INPUT_LEFT:
|
||||||
mVelX = -mBaseSpeed;
|
mVelX = -mBaseSpeed;
|
||||||
setStatus(PLAYER_STATE_WALKING_LEFT);
|
setStatus(PLAYER_STATE_WALKING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_RIGHT:
|
case INPUT_RIGHT:
|
||||||
mVelX = mBaseSpeed;
|
mVelX = mBaseSpeed;
|
||||||
setStatus(PLAYER_STATE_WALKING_RIGHT);
|
setStatus(PLAYER_STATE_WALKING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mVelX = 0;
|
mVelX = 0;
|
||||||
setStatus(PLAYER_STATE_STOPPED);
|
setStatus(PLAYER_STATE_STOPPED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el jugador a la posición y animación que le corresponde
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
void Player::move()
|
void Player::move()
|
||||||
{
|
{
|
||||||
// Move the player left or right
|
// Move the player left or right
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
|
|
||||||
// If the player went too far to the left or right
|
// If the player went too far to the left or right
|
||||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
||||||
{
|
{
|
||||||
// Move back
|
// Move back
|
||||||
mPosX -= mVelX;
|
mPosX -= mVelX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the player up or down
|
// Move the player up or down
|
||||||
mPosY += mVelY;
|
mPosY += mVelY;
|
||||||
|
|
||||||
// If the player went too far up or down
|
// If the player went too far up or down
|
||||||
if ((mPosY < PLAY_AREA_TOP) || (mPosY + mHeight > PLAY_AREA_BOTTOM))
|
if ((mPosY < PLAY_AREA_TOP) || (mPosY + mHeight > PLAY_AREA_BOTTOM))
|
||||||
{
|
{
|
||||||
// Move back
|
// Move back
|
||||||
mPosY -= mVelY;
|
mPosY -= mVelY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update sprite position
|
// Update sprite position
|
||||||
mSprite.setPosX(getPosX());
|
mSprite.setPosX(getPosX());
|
||||||
mSprite.setPosY(mPosY);
|
mSprite.setPosY(mPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void Player::render()
|
void Player::render()
|
||||||
{
|
{
|
||||||
mSprite.render();
|
mSprite.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el estado del jugador
|
// Establece el estado del jugador
|
||||||
void Player::setStatus(int status)
|
void Player::setStatus(int status)
|
||||||
{
|
{
|
||||||
// Si cambiamos de estado, reiniciamos la animación
|
// Si cambiamos de estado, reiniciamos la animación
|
||||||
if (mStatus != status)
|
if (mStatus != status)
|
||||||
{
|
{
|
||||||
mStatus = status;
|
mStatus = status;
|
||||||
mSprite.setCurrentFrame(0);
|
mSprite.setCurrentFrame(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animación correspondiente al estado
|
// Establece la animación correspondiente al estado
|
||||||
void Player::setAnimation()
|
void Player::setAnimation()
|
||||||
{
|
{
|
||||||
mSprite.animate(mStatus);
|
mSprite.animate(mStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int Player::getPosX()
|
int Player::getPosX()
|
||||||
{
|
{
|
||||||
return int(mPosX);
|
return int(mPosX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int Player::getPosY()
|
int Player::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return mPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int Player::getWidth()
|
int Player::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int Player::getHeight()
|
int Player::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si el jugador puede disparar
|
// Indica si el jugador puede disparar
|
||||||
bool Player::canFire()
|
bool Player::canFire()
|
||||||
{
|
{
|
||||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||||
if (mCooldown > 0)
|
if (mCooldown > 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Player::setFireCooldown(int time)
|
void Player::setFireCooldown(int time)
|
||||||
{
|
{
|
||||||
mCooldown = time;
|
mCooldown = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void Player::updateCooldown()
|
void Player::updateCooldown()
|
||||||
{
|
{
|
||||||
if (mCooldown > 0)
|
if (mCooldown > 0)
|
||||||
{
|
{
|
||||||
--mCooldown;
|
--mCooldown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||||
void Player::update()
|
void Player::update()
|
||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
setAnimation();
|
setAnimation();
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
updateCooldown();
|
updateCooldown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la puntuación del jugador
|
// Obtiene la puntuación del jugador
|
||||||
int Player::getScore()
|
int Player::getScore()
|
||||||
{
|
{
|
||||||
return mScore;
|
return mScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la puntuación del jugador
|
// Establece la puntuación del jugador
|
||||||
void Player::setScore(int score)
|
void Player::setScore(int score)
|
||||||
{
|
{
|
||||||
mScore = score;
|
mScore = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade a la puntuación del jugador
|
// Añade a la puntuación del jugador
|
||||||
void Player::addScore(int score)
|
void Player::addScore(int score)
|
||||||
{
|
{
|
||||||
mScore += score;
|
mScore += score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
Circle &Player::getCollider()
|
Circle &Player::getCollider()
|
||||||
{
|
{
|
||||||
return mCollider;
|
return mCollider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
void Player::shiftColliders()
|
void Player::shiftColliders()
|
||||||
{
|
{
|
||||||
// Align collider to center of player
|
// Align collider to center of player
|
||||||
mCollider.x = mPosX + (mWidth / 2);
|
mCollider.x = mPosX + (mWidth / 2);
|
||||||
mCollider.y = mPosY + (mHeight / 2);
|
mCollider.y = mPosY + (mHeight / 2);
|
||||||
}
|
}
|
||||||
238
source/player.h
238
source/player.h
@@ -1,120 +1,120 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "spriteanimated.h"
|
#include "spriteanimated.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
// The player
|
// The player
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Player(SDL_Renderer *gRenderer);
|
Player(SDL_Renderer *gRenderer);
|
||||||
|
|
||||||
// DEstructor
|
// DEstructor
|
||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
||||||
void checkInput(Uint8 input);
|
void checkInput(Uint8 input);
|
||||||
|
|
||||||
// Mueve el jugador a la posición y animación que le corresponde
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Establece el estado del jugador
|
// Establece el estado del jugador
|
||||||
void setStatus(int status);
|
void setStatus(int status);
|
||||||
|
|
||||||
// Establece la animación correspondiente al estado
|
// Establece la animación correspondiente al estado
|
||||||
void setAnimation();
|
void setAnimation();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosY();
|
int getPosY();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getWidth();
|
int getWidth();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Indica si el jugador puede disparar
|
// Indica si el jugador puede disparar
|
||||||
bool canFire();
|
bool canFire();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setFireCooldown(int time);
|
void setFireCooldown(int time);
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void updateCooldown();
|
void updateCooldown();
|
||||||
|
|
||||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Obtiene la puntuación del jugador
|
// Obtiene la puntuación del jugador
|
||||||
int getScore();
|
int getScore();
|
||||||
|
|
||||||
// Establece la puntuación del jugador
|
// Establece la puntuación del jugador
|
||||||
void setScore(int score);
|
void setScore(int score);
|
||||||
|
|
||||||
// Añade a la puntuación del jugador
|
// Añade a la puntuación del jugador
|
||||||
void addScore(int score);
|
void addScore(int score);
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
Circle &getCollider();
|
Circle &getCollider();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// El renderizador de la ventana
|
// El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer;
|
SDL_Renderer *gRenderer;
|
||||||
|
|
||||||
LTexture *gPlayerTexture;
|
LTexture *gPlayerTexture;
|
||||||
|
|
||||||
// Posición X, Y del jugador
|
// Posición X, Y del jugador
|
||||||
float mPosX;
|
float mPosX;
|
||||||
int mPosY;
|
int mPosY;
|
||||||
|
|
||||||
// Altura y anchura del jugador
|
// Altura y anchura del jugador
|
||||||
Uint8 mWidth;
|
Uint8 mWidth;
|
||||||
Uint8 mHeight;
|
Uint8 mHeight;
|
||||||
|
|
||||||
// Velocidad X, Y del jugador
|
// Velocidad X, Y del jugador
|
||||||
float mVelX;
|
float mVelX;
|
||||||
int mVelY;
|
int mVelY;
|
||||||
|
|
||||||
// Velocidad base del jugador
|
// Velocidad base del jugador
|
||||||
float mBaseSpeed;
|
float mBaseSpeed;
|
||||||
|
|
||||||
// Contador durante el cual no puede disparar
|
// Contador durante el cual no puede disparar
|
||||||
int mCooldown;
|
int mCooldown;
|
||||||
|
|
||||||
// Vidas actuales del jugador
|
// Vidas actuales del jugador
|
||||||
Uint8 mLives;
|
Uint8 mLives;
|
||||||
|
|
||||||
// Vidas iniciales del jugador
|
// Vidas iniciales del jugador
|
||||||
Uint8 mStartingLives;
|
Uint8 mStartingLives;
|
||||||
|
|
||||||
// Puntos del jugador
|
// Puntos del jugador
|
||||||
int mScore;
|
int mScore;
|
||||||
|
|
||||||
// Estado del jugador
|
// Estado del jugador
|
||||||
Uint8 mStatus;
|
Uint8 mStatus;
|
||||||
|
|
||||||
// Sprite para dibujar al jugador en pantalla
|
// Sprite para dibujar al jugador en pantalla
|
||||||
SpriteAnimated mSprite;
|
SpriteAnimated mSprite;
|
||||||
|
|
||||||
// Circulo de colisión del jugador
|
// Circulo de colisión del jugador
|
||||||
Circle mCollider;
|
Circle mCollider;
|
||||||
|
|
||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,88 +1,88 @@
|
|||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
void Sprite::render()
|
void Sprite::render()
|
||||||
{
|
{
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
mTexture->render(mPosX, mPosY, &mSpriteClip);
|
mTexture->render(mPosX, mPosY, &mSpriteClip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getPosX()
|
int Sprite::getPosX()
|
||||||
{
|
{
|
||||||
return mPosX;
|
return mPosX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getPosY()
|
int Sprite::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return mPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getWidth()
|
int Sprite::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getHeight()
|
int Sprite::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setPosX(int x)
|
void Sprite::setPosX(int x)
|
||||||
{
|
{
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setPosY(int y)
|
void Sprite::setPosY(int y)
|
||||||
{
|
{
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setWidth(int w)
|
void Sprite::setWidth(int w)
|
||||||
{
|
{
|
||||||
mWidth = w;
|
mWidth = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setHeight(int h)
|
void Sprite::setHeight(int h)
|
||||||
{
|
{
|
||||||
mHeight = h;
|
mHeight = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
SDL_Rect Sprite::getSpriteClip()
|
SDL_Rect Sprite::getSpriteClip()
|
||||||
{
|
{
|
||||||
return mSpriteClip;
|
return mSpriteClip;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||||
{
|
{
|
||||||
mSpriteClip = rect;
|
mSpriteClip = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
mSpriteClip.x = x;
|
mSpriteClip.x = x;
|
||||||
mSpriteClip.y = y;
|
mSpriteClip.y = y;
|
||||||
mSpriteClip.w = w;
|
mSpriteClip.w = w;
|
||||||
mSpriteClip.h = h;
|
mSpriteClip.h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
LTexture *Sprite::getTexture()
|
LTexture *Sprite::getTexture()
|
||||||
{
|
{
|
||||||
return mTexture;
|
return mTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setTexture(LTexture &texture)
|
void Sprite::setTexture(LTexture &texture)
|
||||||
{
|
{
|
||||||
mTexture = &texture;
|
mTexture = &texture;
|
||||||
}
|
}
|
||||||
138
source/sprite.h
138
source/sprite.h
@@ -1,70 +1,70 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ltexture.h"
|
#include "ltexture.h"
|
||||||
|
|
||||||
#ifndef SPRITE_H
|
#ifndef SPRITE_H
|
||||||
#define SPRITE_H
|
#define SPRITE_H
|
||||||
|
|
||||||
// Clase sprite
|
// Clase sprite
|
||||||
class Sprite
|
class Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getPosY();
|
int getPosY();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getWidth();
|
int getWidth();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(int x);
|
void setPosX(int x);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosY(int y);
|
void setPosY(int y);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setWidth(int w);
|
void setWidth(int w);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setHeight(int h);
|
void setHeight(int h);
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
SDL_Rect getSpriteClip();
|
SDL_Rect getSpriteClip();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setSpriteClip(SDL_Rect rect);
|
void setSpriteClip(SDL_Rect rect);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setSpriteClip(int x, int y, int w, int h);
|
void setSpriteClip(int x, int y, int w, int h);
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
LTexture *getTexture();
|
LTexture *getTexture();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setTexture(LTexture &texture);
|
void setTexture(LTexture &texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Posición X,Y donde dibujar el sprite
|
// Posición X,Y donde dibujar el sprite
|
||||||
int mPosX;
|
int mPosX;
|
||||||
int mPosY;
|
int mPosY;
|
||||||
|
|
||||||
// Alto y ancho del sprite
|
// Alto y ancho del sprite
|
||||||
Uint16 mWidth;
|
Uint16 mWidth;
|
||||||
Uint16 mHeight;
|
Uint16 mHeight;
|
||||||
|
|
||||||
// Textura donde estan todos los dibujos del sprite
|
// Textura donde estan todos los dibujos del sprite
|
||||||
LTexture *mTexture;
|
LTexture *mTexture;
|
||||||
|
|
||||||
// Rectangulo de la textura que se dibujará en pantalla
|
// Rectangulo de la textura que se dibujará en pantalla
|
||||||
SDL_Rect mSpriteClip;
|
SDL_Rect mSpriteClip;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,87 +1,87 @@
|
|||||||
#include "spriteanimated.h"
|
#include "spriteanimated.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SpriteAnimated::SpriteAnimated()
|
SpriteAnimated::SpriteAnimated()
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void SpriteAnimated::init()
|
void SpriteAnimated::init()
|
||||||
{
|
{
|
||||||
for (Uint8 i = 0; i < 20; i++)
|
for (Uint8 i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
mAnimation[i].numFrames = 0;
|
mAnimation[i].numFrames = 0;
|
||||||
mAnimation[i].speed = 0;
|
mAnimation[i].speed = 0;
|
||||||
for (Uint8 j = 0; i < 20; i++)
|
for (Uint8 j = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
mAnimation[i].frames[j].x = 0;
|
mAnimation[i].frames[j].x = 0;
|
||||||
mAnimation[i].frames[j].y = 0;
|
mAnimation[i].frames[j].y = 0;
|
||||||
mAnimation[i].frames[j].w = 0;
|
mAnimation[i].frames[j].w = 0;
|
||||||
mAnimation[i].frames[j].h = 0;
|
mAnimation[i].frames[j].h = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCurrentFrame = 0;
|
mCurrentFrame = 0;
|
||||||
mAnimationCounter = 0;
|
mAnimationCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
// Calcula el frame correspondiente a la animación
|
||||||
void SpriteAnimated::animate(int index)
|
void SpriteAnimated::animate(int index)
|
||||||
{
|
{
|
||||||
// Calculamos el frame actual a partir del contador
|
// Calculamos el frame actual a partir del contador
|
||||||
mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
|
mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
|
||||||
|
|
||||||
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación
|
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación
|
||||||
if (mCurrentFrame >= mAnimation[index].numFrames)
|
if (mCurrentFrame >= mAnimation[index].numFrames)
|
||||||
{
|
{
|
||||||
mAnimationCounter = 0;
|
mAnimationCounter = 0;
|
||||||
}
|
}
|
||||||
// En caso contrario
|
// En caso contrario
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Escogemos el frame correspondiente de la animación
|
// Escogemos el frame correspondiente de la animación
|
||||||
setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
|
setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
|
||||||
|
|
||||||
// Incrementamos el contador de la animacion
|
// Incrementamos el contador de la animacion
|
||||||
++mAnimationCounter;
|
++mAnimationCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el frame actual de la animación
|
// Establece el frame actual de la animación
|
||||||
void SpriteAnimated::setCurrentFrame(Uint8 num)
|
void SpriteAnimated::setCurrentFrame(Uint8 num)
|
||||||
{
|
{
|
||||||
mCurrentFrame = num;
|
mCurrentFrame = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el numero de frames de la animacion
|
// Establece el numero de frames de la animacion
|
||||||
void SpriteAnimated::setAnimationCounter(Uint16 num)
|
void SpriteAnimated::setAnimationCounter(Uint16 num)
|
||||||
{
|
{
|
||||||
mAnimationCounter = num;
|
mAnimationCounter = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el rectangulo para un frame de una animación
|
// Establece el rectangulo para un frame de una animación
|
||||||
void SpriteAnimated::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
void SpriteAnimated::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
mAnimation[index_animation].frames[index_frame].x = x;
|
mAnimation[index_animation].frames[index_frame].x = x;
|
||||||
mAnimation[index_animation].frames[index_frame].y = y;
|
mAnimation[index_animation].frames[index_frame].y = y;
|
||||||
mAnimation[index_animation].frames[index_frame].w = w;
|
mAnimation[index_animation].frames[index_frame].w = w;
|
||||||
mAnimation[index_animation].frames[index_frame].h = h;
|
mAnimation[index_animation].frames[index_frame].h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void SpriteAnimated::setAnimationSpeed(Uint8 index, Uint8 speed)
|
void SpriteAnimated::setAnimationSpeed(Uint8 index, Uint8 speed)
|
||||||
{
|
{
|
||||||
mAnimation[index].speed = speed;
|
mAnimation[index].speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el numero de frames de una animación
|
// Establece el numero de frames de una animación
|
||||||
void SpriteAnimated::setAnimationNumFrames(Uint8 index, Uint8 num)
|
void SpriteAnimated::setAnimationNumFrames(Uint8 index, Uint8 num)
|
||||||
{
|
{
|
||||||
mAnimation[index].numFrames = num;
|
mAnimation[index].numFrames = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect SpriteAnimated::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
|
SDL_Rect SpriteAnimated::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
|
||||||
{
|
{
|
||||||
return mAnimation[index_animation].frames[index_frame];
|
return mAnimation[index_animation].frames[index_frame];
|
||||||
}
|
}
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#ifndef SPRITEANIMATED_H
|
#ifndef SPRITEANIMATED_H
|
||||||
#define SPRITEANIMATED_H
|
#define SPRITEANIMATED_H
|
||||||
|
|
||||||
// Clase spriteAnimated
|
// Clase spriteAnimated
|
||||||
class SpriteAnimated : public Sprite
|
class SpriteAnimated : public Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
SpriteAnimated();
|
SpriteAnimated();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
// Calcula el frame correspondiente a la animación
|
||||||
void animate(int index);
|
void animate(int index);
|
||||||
|
|
||||||
// Establece el frame actual de la animación
|
// Establece el frame actual de la animación
|
||||||
void setCurrentFrame(Uint8 num);
|
void setCurrentFrame(Uint8 num);
|
||||||
|
|
||||||
// Establece el numero de frames de la animacion
|
// Establece el numero de frames de la animacion
|
||||||
void setAnimationCounter(Uint16 num);
|
void setAnimationCounter(Uint16 num);
|
||||||
|
|
||||||
// Establece el rectangulo para un frame de una animación
|
// Establece el rectangulo para un frame de una animación
|
||||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void setAnimationSpeed(Uint8 index, Uint8 speed);
|
void setAnimationSpeed(Uint8 index, Uint8 speed);
|
||||||
|
|
||||||
// Establece el numero de frames de una animación
|
// Establece el numero de frames de una animación
|
||||||
void setAnimationNumFrames(Uint8 index, Uint8 num);
|
void setAnimationNumFrames(Uint8 index, Uint8 num);
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
|
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct sAnimation
|
struct sAnimation
|
||||||
{
|
{
|
||||||
SDL_Rect frames[20];
|
SDL_Rect frames[20];
|
||||||
Uint8 numFrames;
|
Uint8 numFrames;
|
||||||
Uint8 speed;
|
Uint8 speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vector con las diferentes animaciones y los diferentes frames de cada animación
|
// Vector con las diferentes animaciones y los diferentes frames de cada animación
|
||||||
sAnimation mAnimation[20];
|
sAnimation mAnimation[20];
|
||||||
|
|
||||||
// Frame actual
|
// Frame actual
|
||||||
Uint8 mCurrentFrame;
|
Uint8 mCurrentFrame;
|
||||||
|
|
||||||
// Contador para las animaciones
|
// Contador para las animaciones
|
||||||
Uint16 mAnimationCounter;
|
Uint16 mAnimationCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
7897
source/stb_image.h
Normal file
7897
source/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
5565
source/stb_vorbis.c
Normal file
5565
source/stb_vorbis.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,50 +1,50 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text()
|
Text::Text()
|
||||||
{
|
{
|
||||||
init(NULL);
|
init(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void Text::init(LTexture *texture)
|
void Text::init(LTexture *texture)
|
||||||
{
|
{
|
||||||
// Inicia los valores del sprite que dibuja las letras
|
// Inicia los valores del sprite que dibuja las letras
|
||||||
mSprite.setWidth(8);
|
mSprite.setWidth(8);
|
||||||
mSprite.setHeight(8);
|
mSprite.setHeight(8);
|
||||||
mSprite.setPosX(0);
|
mSprite.setPosX(0);
|
||||||
mSprite.setPosY(0);
|
mSprite.setPosY(0);
|
||||||
mSprite.setTexture(*texture);
|
mSprite.setTexture(*texture);
|
||||||
mSprite.setSpriteClip(8, 8, mSprite.getWidth(), mSprite.getHeight());
|
mSprite.setSpriteClip(8, 8, mSprite.getWidth(), mSprite.getHeight());
|
||||||
|
|
||||||
// Cadena con los caracteres ascii que se van a inicializar
|
// Cadena con los caracteres ascii que se van a inicializar
|
||||||
std::string text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/().:#";
|
std::string text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/().:#";
|
||||||
Uint8 i;
|
Uint8 i;
|
||||||
|
|
||||||
// Inicializa a cero el vector con las coordenadas
|
// Inicializa a cero el vector con las coordenadas
|
||||||
for (i = 0; i < 255; ++i)
|
for (i = 0; i < 255; ++i)
|
||||||
{
|
{
|
||||||
mOffset[i].x = 0;
|
mOffset[i].x = 0;
|
||||||
mOffset[i].y = 0;
|
mOffset[i].y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece las coordenadas para cada caracter ascii de la cadena
|
// Establece las coordenadas para cada caracter ascii de la cadena
|
||||||
for (i = 0; i < text.length(); ++i)
|
for (i = 0; i < text.length(); ++i)
|
||||||
{
|
{
|
||||||
mOffset[int(text[i])].x = (((int(text[i]) - 32) % 15) - 0) * BLOCK;
|
mOffset[int(text[i])].x = (((int(text[i]) - 32) % 15) - 0) * BLOCK;
|
||||||
mOffset[int(text[i])].y = ((int(text[i]) - 32) / 15) * BLOCK;
|
mOffset[int(text[i])].y = ((int(text[i]) - 32) / 15) * BLOCK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto en pantalla
|
// Escribe el texto en pantalla
|
||||||
void Text::write(int x, int y, std::string text)
|
void Text::write(int x, int y, std::string text)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
for (Uint8 i = 0; i < text.length(); ++i)
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
{
|
{
|
||||||
mSprite.setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, 8, 8);
|
mSprite.setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, 8, 8);
|
||||||
mSprite.setPosX(x + (i * BLOCK));
|
mSprite.setPosX(x + (i * BLOCK));
|
||||||
mSprite.setPosY(y);
|
mSprite.setPosY(y);
|
||||||
mSprite.render();
|
mSprite.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
|
||||||
#ifndef TEXT_H
|
#ifndef TEXT_H
|
||||||
#define TEXT_H
|
#define TEXT_H
|
||||||
|
|
||||||
// Text class
|
// Text class
|
||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Text();
|
Text();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(LTexture *texture);
|
void init(LTexture *texture);
|
||||||
|
|
||||||
// Escribe el texto en pantalla
|
// Escribe el texto en pantalla
|
||||||
void write(int x, int y, std::string text);
|
void write(int x, int y, std::string text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Objeto con los graficos para el texto
|
// Objeto con los graficos para el texto
|
||||||
Sprite mSprite;
|
Sprite mSprite;
|
||||||
|
|
||||||
// Coordenadas dentro del PNG para cada código ascii
|
// Coordenadas dentro del PNG para cada código ascii
|
||||||
struct Offset
|
struct Offset
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} mOffset[255];
|
} mOffset[255];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Binary file not shown.
Reference in New Issue
Block a user