Optimizaciones de código

This commit is contained in:
2022-09-24 19:16:39 +02:00
parent f3aeed9428
commit b44869341c
99 changed files with 441 additions and 509 deletions

View File

@@ -1,16 +1,13 @@
name=THE JAIL
bgColor=bright_blue
border=blue
tilemap=01.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=02.room
[tilemap]
01.tmx
[/tilemap]
[enemy]
tileset=jailer.png
animation=jailer.ani

View File

@@ -1,16 +1,13 @@
name=road to the jail
bgColor=black
border=cyan
tilemap=02.tmx
tileset=standard.png
roomUp=0
roomDown=04.room
roomLeft=01.room
roomRight=03.room
[tilemap]
02.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=void main
bgColor=black
border=magenta
tilemap=03.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=02.room
roomRight=0
[tilemap]
03.tmx
[/tilemap]
[enemy]
tileset=bin.png
animation=bin.ani

View File

@@ -1,16 +1,13 @@
name=no 04
bgColor=black
border=red
tilemap=04.tmx
tileset=standard.png
roomUp=02.room
roomDown=0
roomLeft=07.room
roomRight=05.room
[tilemap]
04.tmx
[/tilemap]
[enemy]
tileset=chip.png
animation=chip.ani

View File

@@ -1,16 +1,13 @@
name=no 05
bgColor=black
border=red
tilemap=05.tmx
tileset=standard.png
roomUp=0
roomDown=60.room
roomLeft=04.room
roomRight=06.room
[tilemap]
05.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 06
bgColor=black
border=red
tilemap=06.tmx
tileset=standard.png
roomUp=15.room
roomDown=0
roomLeft=05.room
roomRight=25.room
[tilemap]
06.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=sigmasua
bgColor=black
border=black
tilemap=07.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=08.room
roomRight=04.room
[tilemap]
07.tmx
[/tilemap]
[enemy]
tileset=sigmasua.png
animation=sigmasua.ani

View File

@@ -1,16 +1,13 @@
name=THE GARDEN
bgColor=black
border=cyan
tilemap=08.tmx
tileset=standard.png
roomUp=09.room
roomDown=0
roomLeft=16.room
roomRight=07.room
[tilemap]
08.tmx
[/tilemap]
[enemy]
tileset=abad.png
animation=abad.ani

View File

@@ -1,16 +1,13 @@
name=no 09
bgColor=black
border=red
tilemap=09.tmx
tileset=standard.png
roomUp=10.room
roomDown=08.room
roomLeft=0
roomRight=0
[tilemap]
09.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=the hall
bgColor=black
border=magenta
tilemap=10.tmx
tileset=standard.png
roomUp=0
roomDown=09.room
roomLeft=0
roomRight=11.room
[tilemap]
10.tmx
[/tilemap]
[item]
tileset=items.png
tile=22

View File

@@ -1,16 +1,13 @@
name=no 11
bgColor=black
border=red
tilemap=11.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=10.room
roomRight=12.room
[tilemap]
11.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=THE PASSAGE
bgColor=black
border=green
tilemap=12.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=11.room
roomRight=13.room
[tilemap]
12.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=matatunos
bgColor=black
border=blue
tilemap=13.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=12.room
roomRight=14.room
[tilemap]
13.tmx
[/tilemap]
[enemy]
tileset=matatunos.png
animation=matatunos.ani

View File

@@ -1,16 +1,13 @@
name=KILLING SPREE
bgColor=black
border=blue
tilemap=14.tmx
tileset=standard.png
roomUp=0
roomDown=15.room
roomLeft=13.room
roomRight=45.room
[tilemap]
14.tmx
[/tilemap]
[enemy]
tileset=matatunos.png
animation=matatunos.ani

View File

@@ -1,16 +1,13 @@
name=no 15
bgColor=black
border=red
tilemap=15.tmx
tileset=standard.png
roomUp=14.room
roomDown=06.room
roomLeft=0
roomRight=0
[tilemap]
15.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -3,16 +3,13 @@ bgColor=blue
border=blue
itemColor1=bright_cyan
itemColor2=yellow
tilemap=16.tmx
tileset=standard.png
roomUp=44.room
roomDown=0
roomLeft=17.room
roomRight=08.room
[tilemap]
16.tmx
[/tilemap]
[enemy]
tileset=chip.png
animation=chip.ani

View File

@@ -1,16 +1,13 @@
name=no 17
bgColor=black
border=red
tilemap=17.tmx
tileset=standard.png
roomUp=0
roomDown=18.room
roomLeft=49.room
roomRight=16.room
[tilemap]
17.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 18
bgColor=black
border=red
tilemap=18.tmx
tileset=standard.png
roomUp=17.room
roomDown=54.room
roomLeft=19.room
roomRight=0
[tilemap]
18.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 19
bgColor=black
border=red
tilemap=19.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=20.room
roomRight=18.room
[tilemap]
19.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 20
bgColor=black
border=red
tilemap=20.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=21.room
roomRight=19.room
[tilemap]
20.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 21
bgColor=black
border=red
tilemap=21.tmx
tileset=standard.png
roomUp=23.room
roomDown=0
roomLeft=22.room
roomRight=20.room
[tilemap]
01.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 22
bgColor=black
border=red
tilemap=22.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=21.room
[tilemap]
22.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 23
bgColor=black
border=red
tilemap=23.tmx
tileset=standard.png
roomUp=0
roomDown=21.room
roomLeft=24.room
roomRight=0
[tilemap]
23.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 24
bgColor=black
border=red
tilemap=24.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=23.room
[tilemap]
24.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 25
bgColor=black
border=red
tilemap=25.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=06.room
roomRight=26.room
[tilemap]
25.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 26
bgColor=black
border=red
tilemap=26.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=25.room
roomRight=27.room
[tilemap]
26.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 27
bgColor=black
border=red
tilemap=27.tmx
tileset=standard.png
roomUp=28.room
roomDown=29.room
roomLeft=0
roomRight=0
[tilemap]
27.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 28
bgColor=black
border=red
tilemap=28.tmx
tileset=standard.png
roomUp=32.room
roomDown=27.room
roomLeft=0
roomRight=31.room
[tilemap]
28.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 29
bgColor=black
border=red
tilemap=29.tmx
tileset=standard.png
roomUp=27.room
roomDown=0
roomLeft=30.room
roomRight=0
[tilemap]
29.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 30
bgColor=black
border=red
tilemap=30.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=29.room
[tilemap]
30.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 31
bgColor=black
border=red
tilemap=31.tmx
tileset=standard.png
roomUp=33.room
roomDown=0
roomLeft=28.room
roomRight=0
[tilemap]
31.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 32
bgColor=black
border=red
tilemap=32.tmx
tileset=standard.png
roomUp=34.room
roomDown=28.room
roomLeft=0
roomRight=33.room
[tilemap]
32.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 33
bgColor=black
border=red
tilemap=33.tmx
tileset=standard.png
roomUp=0
roomDown=31.room
roomLeft=32.room
roomRight=0
[tilemap]
33.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 34
bgColor=black
border=red
tilemap=34.tmx
tileset=standard.png
roomUp=0
roomDown=32.room
roomLeft=35.room
roomRight=0
[tilemap]
34.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 35
bgColor=black
border=red
tilemap=35.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=36.room
roomRight=34.room
[tilemap]
35.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 36
bgColor=black
border=red
tilemap=36.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=37.room
roomRight=35.room
[tilemap]
36.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 37
bgColor=black
border=red
tilemap=37.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=38.room
roomRight=36.room
[tilemap]
37.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 38
bgColor=black
border=red
tilemap=38.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=39.room
roomRight=37.room
[tilemap]
38.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 39
bgColor=black
border=red
tilemap=39.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=40.room
roomRight=38.room
[tilemap]
39.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 40
bgColor=black
border=red
tilemap=40.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=41.room
roomRight=39.room
[tilemap]
40.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 41
bgColor=black
border=red
tilemap=41.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=42.room
roomRight=40.room
[tilemap]
41.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 42
bgColor=black
border=red
tilemap=42.tmx
tileset=standard.png
roomUp=0
roomDown=43.room
roomLeft=53.room
roomRight=41.room
[tilemap]
42.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 43
bgColor=black
border=red
tilemap=43.tmx
tileset=standard.png
roomUp=42.room
roomDown=44.room
roomLeft=0
roomRight=0
[tilemap]
43.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 44
bgColor=black
border=red
tilemap=44.tmx
tileset=standard.png
roomUp=43.room
roomDown=16.room
roomLeft=0
roomRight=0
[tilemap]
44.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=FEEL THE HEAT
bgColor=red
border=black
tilemap=45.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=14.room
roomRight=46.room
[tilemap]
45.tmx
[/tilemap]
[enemy]
tileset=chip.png
animation=chip.ani

View File

@@ -1,16 +1,13 @@
name=no 46
bgColor=black
border=red
tilemap=46.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=45.room
roomRight=0
[tilemap]
46.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 47
bgColor=black
border=red
tilemap=47.tmx
tileset=standard.png
roomUp=51.room
roomDown=0
roomLeft=48.room
roomRight=0
[tilemap]
47.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 48
bgColor=black
border=red
tilemap=48.tmx
tileset=standard.png
roomUp=0
roomDown=49.room
roomLeft=0
roomRight=47.room
[tilemap]
48.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 49
bgColor=black
border=red
tilemap=49.tmx
tileset=standard.png
roomUp=48.room
roomDown=0
roomLeft=50.room
roomRight=17.room
[tilemap]
49.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 50
bgColor=black
border=red
tilemap=50.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=49.room
[tilemap]
50.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 51
bgColor=black
border=red
tilemap=51.tmx
tileset=standard.png
roomUp=53.room
roomDown=47.room
roomLeft=52.room
roomRight=0
[tilemap]
51.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 52
bgColor=black
border=red
tilemap=52.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=0
roomRight=51.room
[tilemap]
52.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 53
bgColor=black
border=red
tilemap=53.tmx
tileset=standard.png
roomUp=0
roomDown=51.room
roomLeft=0
roomRight=42.room
[tilemap]
53.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 54
bgColor=black
border=red
tilemap=54.tmx
tileset=standard.png
roomUp=18.room
roomDown=0
roomLeft=0
roomRight=55.room
[tilemap]
54.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 55
bgColor=black
border=red
tilemap=55.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=54.room
roomRight=56.room
[tilemap]
55.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 56
bgColor=black
border=red
tilemap=56.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=55.room
roomRight=57.room
[tilemap]
56.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=no 57
bgColor=black
border=red
tilemap=57.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=56.room
roomRight=58.room
[tilemap]
57.tmx
[/tilemap]
[enemy]
tileset=diskette.png
animation=diskette.ani

View File

@@ -1,16 +1,13 @@
name=chirping
bgColor=black
border=magenta
tilemap=58.tmx
tileset=standard.png
roomUp=0
roomDown=0
roomLeft=57.room
roomRight=59.room
[tilemap]
58.tmx
[/tilemap]
[enemy]
tileset=bird.png
animation=bird.ani

View File

@@ -1,16 +1,13 @@
name=static
bgColor=black
border=bright_magenta
tilemap=59.tmx
tileset=standard.png
roomUp=60.room
roomDown=0
roomLeft=58.room
roomRight=0
[tilemap]
59.tmx
[/tilemap]
[enemy]
tileset=wave.png
animation=wave.ani

View File

@@ -1,6 +1,7 @@
name=magnetic fields
bgColor=black
border=red
tilemap=60.tmx
tileset=standard.png
roomUp=05.room
roomDown=59.room
@@ -9,10 +10,6 @@ roomRight=0
itemColor1=red
itemColor2=green
[tilemap]
60.tmx
[/tilemap]
[enemy]
tileset=wave_v.png
animation=wave_v.ani

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=06.room
roomRight=02.room
[tilemap]
01.tmx
[/tilemap]
[enemy]
tileset=diskette.png

View File

@@ -7,9 +7,9 @@ roomDown=04.room
roomLeft=01.room
roomRight=03.room
[tilemap]
02.tmx
[/tilemap]
[enemy]
tileset=paco.png

View File

@@ -7,9 +7,9 @@ roomDown=05.room
roomLeft=02.room
roomRight=11.room
[tilemap]
03.tmx
[/tilemap]
[enemy]
tileset=chip.png

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=07.room
roomRight=05.room
[tilemap]
04.tmx
[/tilemap]
[enemy]
tileset=chip.png

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=04.room
roomRight=12.room
[tilemap]
05.tmx
[/tilemap]
[enemy]
tileset=sigmasua.png

View File

@@ -7,6 +7,5 @@ roomDown=0
roomLeft=13.room
roomRight=01.room
[tilemap]
06.tmx
[/tilemap]

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=08.room
roomRight=04.room
[tilemap]
07.tmx
[/tilemap]
[enemy]
tileset=bird.png

View File

@@ -7,6 +7,5 @@ roomDown=09.room
roomLeft=10.room
roomRight=07.room
[tilemap]
08.tmx
[/tilemap]

View File

@@ -7,6 +7,5 @@ roomDown=0
roomLeft=0
roomRight=0
[tilemap]
09.tmx
[/tilemap]

View File

@@ -7,6 +7,5 @@ roomDown=0
roomLeft=0
roomRight=08.room
[tilemap]
10.tmx
[/tilemap]

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=03.room
roomRight=0
[tilemap]
11.tmx
[/tilemap]
[enemy]
tileset=qvoid.png

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=05.room
roomRight=0
[tilemap]
01.tmx
[/tilemap]
[enemy]
tileset=diskette.png

View File

@@ -7,9 +7,9 @@ roomDown=0
roomLeft=0
roomRight=06.room
[tilemap]
13.tmx
[/tilemap]
[enemy]
tileset=batman.png

View File

@@ -32,7 +32,7 @@ int AnimatedSprite::getIndex(std::string name)
for (auto a : animation)
{
index++;
++index;
if (a.name == name)
{
return index;
@@ -57,7 +57,7 @@ void AnimatedSprite::animate()
// Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop y coloca el nuevo frame
if (animation[currentAnimation].currentFrame >= animation[currentAnimation].frames.size())
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
{
if (animation[currentAnimation].loop == -1)
{ // Si no hay loop, deja el último frame
@@ -77,7 +77,7 @@ void AnimatedSprite::animate()
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
// Incrementa el contador de la animacion
animation[currentAnimation].counter++;
++animation[currentAnimation].counter;
}
}
@@ -85,7 +85,7 @@ void AnimatedSprite::animate()
void AnimatedSprite::setCurrentFrame(int num)
{
// Descarta valores fuera de rango
if (num >= animation[currentAnimation].frames.size())
if (num >= (int)animation[currentAnimation].frames.size())
{
num = 0;
}
@@ -136,9 +136,9 @@ SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
// Carga la animación desde un fichero
bool AnimatedSprite::load(std::string filePath)
{
int frames_per_row = 0;
int frame_width = 0;
int frame_height = 0;
int framesPerRow = 0;
int frameWidth = 0;
int frameHeight = 0;
// Indicador de éxito en la carga
bool success = true;
@@ -170,7 +170,7 @@ bool AnimatedSprite::load(std::string filePath)
int pos = line.find("=");
// Procesa las dos subcadenas
if (pos != line.npos)
if (pos != (int)line.npos)
{
if (line.substr(0, pos) == "name")
{
@@ -189,12 +189,12 @@ bool AnimatedSprite::load(std::string filePath)
// Se introducen los valores separados por comas en un vector
std::stringstream ss(line.substr(pos + 1, line.length()));
std::string tmp;
SDL_Rect rect = {0, 0, frame_width, frame_height};
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
while (getline(ss, tmp, ','))
{
int num_tile = std::stoi(tmp);
rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height;
int numTile = std::stoi(tmp);
rect.x = (numTile % framesPerRow) * frameWidth;
rect.y = (numTile / framesPerRow) * frameHeight;
buffer.frames.push_back(rect);
}
}
@@ -217,27 +217,27 @@ bool AnimatedSprite::load(std::string filePath)
int pos = line.find("=");
// Procesa las dos subcadenas
if (pos != line.npos)
if (pos != (int)line.npos)
{
if (line.substr(0, pos) == "frames_per_row")
if (line.substr(0, pos) == "framesPerRow")
{
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frame_width")
else if (line.substr(0, pos) == "frameWidth")
{
frame_width = std::stoi(line.substr(pos + 1, line.length()));
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
// Normaliza valores
if (frames_per_row == 0)
if (framesPerRow == 0)
{
frames_per_row = texture->getWidth() / frame_width;
framesPerRow = texture->getWidth() / frameWidth;
}
}
else if (line.substr(0, pos) == "frame_height")
else if (line.substr(0, pos) == "frameHeight")
{
frame_height = std::stoi(line.substr(pos + 1, line.length()));
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
}
else
@@ -261,7 +261,7 @@ bool AnimatedSprite::load(std::string filePath)
}
// Pone un valor por defecto
setPos({0, 0, frame_width, frame_height});
setPos({0, 0, frameWidth, frameHeight});
return success;
}

View File

@@ -3,8 +3,8 @@
// Constructor
Asset::Asset(std::string path)
{
mExecutablePath = path;
longest_name = 0;
executablePath = path;
longestName = 0;
}
// Destructor
@@ -16,21 +16,25 @@ Asset::~Asset()
void Asset::add(std::string file, enum assetType type, bool required)
{
item_t temp;
temp.file = mExecutablePath + "/.." + file;
temp.file = executablePath + "/.." + file;
temp.type = type;
temp.required = required;
mFileList.push_back(temp);
fileList.push_back(temp);
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
longest_name = SDL_max(longest_name, filename.size());
longestName = SDL_max(longestName, filename.size());
}
// Devuelve el fichero de un elemento de la lista a partir de una cadena
std::string Asset::get(std::string text)
{
for (int i = 0; i < mFileList.size(); i++)
if (mFileList[i].file.find(text) != std::string::npos)
return mFileList[i].file;
for (auto f : fileList)
{
if (f.file.find(text) != std::string::npos)
{
return f.file;
}
}
printf("Warning: file %s not found\n", text.c_str());
return "";
@@ -44,31 +48,43 @@ bool Asset::check()
printf("\n** Checking files.\n");
// Comprueba la lista de ficheros clasificandolos por tipo
for (int type = 0; type < maxAssetType; type++)
for (int type = 0; type < maxAssetType; ++type)
{
// Comprueba si hay ficheros de ese tipo
bool any = false;
for (int i = 0; i < mFileList.size(); i++)
if ((mFileList[i].required) && (mFileList[i].type == type))
for (auto f : fileList)
{
if ((f.required) && (f.type == type))
{
any = true;
}
}
// Si hay ficheros de ese tipo, comprueba si existen
if (any)
{
printf("\n>> %s FILES\n", getTypeName(type).c_str());
for (int i = 0; i < mFileList.size(); i++)
if ((mFileList[i].required) && (mFileList[i].type == type))
success &= checkFile(mFileList[i].file);
for (auto f : fileList)
{
if ((f.required) && (f.type == type))
{
success &= checkFile(f.file);
}
}
}
}
// Resultado
if (success)
{
printf("\n** All files OK.\n\n");
}
else
{
printf("\n** A file is missing. Exiting.\n\n");
}
return success;
}
@@ -83,14 +99,14 @@ bool Asset::checkFile(std::string path)
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b");
if (file != NULL)
if (file != nullptr)
{
result = "OK";
success = true;
SDL_RWclose(file);
}
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
const std::string s = "Checking file %-" + std::to_string(longestName) + "s [" + result + "]\n";
printf(s.c_str(), filename.c_str());
return success;
@@ -104,30 +120,39 @@ std::string Asset::getTypeName(int type)
case bitmap:
return "BITMAP";
break;
case music:
return "MUSIC";
break;
case sound:
return "SOUND";
break;
case font:
return "FONT";
break;
case lang:
return "LANG";
break;
case data:
return "DATA";
break;
case room:
return "ROOM";
break;
case enemy:
return "ENEMY";
break;
case item:
return "ITEM";
break;
default:
return "ERROR";
break;

View File

@@ -33,10 +33,10 @@ private:
bool required; // Indica si es un fichero que debe de existir
};
int longest_name; // Contiene la longitud del nombre de fichero mas largo
int longestName; // Contiene la longitud del nombre de fichero mas largo
std::vector<item_t> mFileList;
std::string mExecutablePath;
std::vector<item_t> fileList;
std::string executablePath;
// Comprueba que existe un fichero
bool checkFile(std::string path);

View File

@@ -49,9 +49,12 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
texts.push_back("");
// Crea la textura para el texto que se escribe en pantalla
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (textTexture == NULL)
printf("Error: textTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (textTexture == nullptr)
{
printf("Error: textTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
// Escribe el texto en la textura
fillTexture();
@@ -101,18 +104,21 @@ void Credits::checkEventHandler()
// Escribe el texto en la textura
void Credits::fillTexture()
{
SDL_SetRenderTarget(renderer, textTexture);
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
SDL_SetRenderTarget(renderer, textTexture);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
// Escribe el texto en la textura
for (int i = 0; i < texts.size(); ++i)
// Escribe el texto en la textura
const int size = text->getCharacterSize();
int i = 0;
for (auto t:texts)
{
text->write(0, i * 8, texts[i]);
text->write(0, i * size, t);
++i;
}
SDL_SetRenderTarget(renderer, nullptr);
SDL_SetRenderTarget(renderer, nullptr);
}
// Actualiza las variables
@@ -128,7 +134,7 @@ void Credits::update()
checkEventHandler();
// Incrementa el contador
counter++;
++counter;
// Comprueba si ha terminado la sección
if (counter > 1000)
@@ -147,11 +153,10 @@ void Credits::render()
// Limpia la pantalla
screen->clean();
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
// Dibuja la textura con el mapa en pantalla
SDL_RenderCopy(renderer, textTexture, &rect, NULL);
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
// Dibuja la textura con el mapa en pantalla
SDL_RenderCopy(renderer, textTexture, &rect, nullptr);
// Vuelca el contenido del renderizador en pantalla
screen->blit();

View File

@@ -31,8 +31,8 @@ private:
Text *text; // Objeto para escribir texto en pantalla
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<std::string> texts; // Vector con las letras de la marquesina
SDL_Texture *textTexture; // Textura para dibujar el texto

View File

@@ -313,7 +313,7 @@ bool Director::initSDL()
// Crea la ventana
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == NULL)
if (window == nullptr)
{
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
success = false;
@@ -326,7 +326,7 @@ bool Director::initSDL()
else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL)
if (renderer == nullptr)
{
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
success = false;

View File

@@ -303,8 +303,6 @@ void Game::renderRoomName()
// Cambia de habitación
bool Game::changeRoom(std::string file)
{
bool success = false;
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
if (file != "0")
// Verifica que exista el fichero que se va a cargar
@@ -322,16 +320,16 @@ bool Game::changeRoom(std::string file)
board.color = (c.r + c.g + c.b == 0) ? stringToColor("white") : c; // Si el color es negrom cambialo a blanco
if (roomTracker->addRoom(file))
{ // Incrementa el contador de habitaciones visitadas
board.rooms++;
++board.rooms;
}
// Pasa la nueva habitación al jugador
player->setRoom(room);
success = true;
return true;
}
return success;
return false;
}
// Comprueba si el jugador esta en el borde de la pantalla
@@ -339,11 +337,11 @@ void Game::checkPlayerOnBorder()
{
if (player->getOnBorder())
{
const std::string room_name = room->getRoom(player->getBorder());
if (changeRoom(room_name))
const std::string roomName = room->getRoom(player->getBorder());
if (changeRoom(roomName))
{
player->switchBorders();
currentRoom = room_name;
currentRoom = roomName;
spawnPoint = player->getSpawnParams();
}
}
@@ -434,7 +432,7 @@ void Game::updateBlackScreen()
{
//if (screen->spectrumFadeEnded())
{
blackScreenCounter++;
++blackScreenCounter;
if (blackScreenCounter > 10)
{
blackScreen = false;

View File

@@ -38,8 +38,8 @@ private:
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
JA_Music music; // Musica que suena durante el juego
Debug *debug; // Objeto para gestionar la información de debug
int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Seccion actual dentro del juego
std::string currentRoom; // Fichero de la habitación actual
player_t spawnPoint; // Lugar de la habitación donde aparece el jugador

View File

@@ -1,23 +1,20 @@
#include "input.h"
#include <iostream>
// Contestar cuantos joystics ha detectado
// Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones
// Constructor
Input::Input(std::string file)
{
// Fichero gamecontrollerdb.txt
mDBpath = file;
dbPath = file;
// Inicializa las variables
for (int i = 0; i < 17; i++)
for (int i = 0; i < 17; ++i)
{
mKeyBindings[i].scancode = 0;
mKeyBindings[i].active = false;
keyBindings[i].scancode = 0;
keyBindings[i].active = false;
mGameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
mGameControllerBindings[i].active = false;
gameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
gameControllerBindings[i].active = false;
}
discoverGameController();
@@ -26,20 +23,20 @@ Input::Input(std::string file)
// Destructor
Input::~Input()
{
for (int i = 0; i < mNumGamepads; i++)
mConnectedControllers[i] = nullptr;
for (int i = 0; i < numGamepads; ++i)
connectedControllers[i] = nullptr;
}
// Asigna uno de los posibles inputs a una tecla del teclado
void Input::bindKey(Uint8 input, SDL_Scancode code)
{
mKeyBindings[input].scancode = code;
keyBindings[input].scancode = code;
}
// Asigna uno de los posibles inputs a un botón del mando
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
{
mGameControllerBindings[input].button = button;
gameControllerBindings[input].button = button;
}
// Comprueba si un input esta activo
@@ -53,22 +50,22 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
{
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
if (repeat)
{
if (mKeystates[mKeyBindings[input].scancode] != 0)
if (mKeystates[keyBindings[input].scancode] != 0)
successKeyboard = true;
else
successKeyboard = false;
}
else
{
if (!mKeyBindings[input].active)
if (!keyBindings[input].active)
{
if (mKeystates[mKeyBindings[input].scancode] != 0)
if (mKeystates[keyBindings[input].scancode] != 0)
{
mKeyBindings[input].active = true;
keyBindings[input].active = true;
successKeyboard = true;
}
else
@@ -78,9 +75,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
}
else
{
if (mKeystates[mKeyBindings[input].scancode] == 0)
if (mKeystates[keyBindings[input].scancode] == 0)
{
mKeyBindings[input].active = false;
keyBindings[input].active = false;
successKeyboard = false;
}
else
@@ -96,18 +93,18 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
{
if (repeat)
{
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
successGameController = true;
else
successGameController = false;
}
else
{
if (!mGameControllerBindings[input].active)
if (!gameControllerBindings[input].active)
{
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
{
mGameControllerBindings[input].active = true;
gameControllerBindings[input].active = true;
successGameController = true;
}
else
@@ -117,9 +114,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
}
else
{
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
{
mGameControllerBindings[input].active = false;
gameControllerBindings[input].active = false;
successGameController = false;
}
else
@@ -133,6 +130,43 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
return (successKeyboard || successGameController);
}
// Comprueba si hay almenos un input activo
bool Input::checkAnyInput(int device, int index)
{
bool successKeyboard = false;
bool successGameController = false;
if (device == INPUT_USE_ANY)
index = 0;
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
{
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
for (int i = 0; i < 17; ++i)
{
if (mKeystates[keyBindings[i].scancode] != 0)
{
successKeyboard |= true;
}
}
}
if (gameControllerFound())
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
{
for (int i = 0; i < 17; ++i)
{
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[i].button) != 0)
{
successGameController |= true;
}
}
}
return (successKeyboard || successGameController);
}
// Comprueba si hay un mando conectado
bool Input::discoverGameController()
{
@@ -141,43 +175,43 @@ bool Input::discoverGameController()
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError());
int nJoysticks = SDL_NumJoysticks();
mNumGamepads = 0;
numGamepads = 0;
// Cuenta el numero de mandos
for (int i = 0; i < nJoysticks; i++)
for (int i = 0; i < nJoysticks; ++i)
if (SDL_IsGameController(i))
mNumGamepads++;
numGamepads++;
printf("\nChecking for game controllers...\n");
printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads);
printf("** Checking for game controllers ...\n");
printf("%i joysticks found, %i are gamepads\n\n", nJoysticks, numGamepads);
if (mNumGamepads > 0)
if (numGamepads > 0)
{
found = true;
for (int i = 0; i < mNumGamepads; i++)
for (int i = 0; i < numGamepads; ++i)
{
// Abre el mando y lo añade a la lista
SDL_GameController *pad = SDL_GameControllerOpen(i);
if (SDL_GameControllerGetAttached(pad) == 1)
{
mConnectedControllers.push_back(pad);
connectedControllers.push_back(pad);
std::string separator(" #");
std::string name = SDL_GameControllerNameForIndex(i);
name.resize(25);
name = name + separator + std::to_string(i);
std::cout << name << std::endl;
mControllerNames.push_back(name);
controllerNames.push_back(name);
}
else
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
}
// mGameController = mConnectedControllers[0];
// mGameController = connectedControllers[0];
SDL_GameControllerEventState(SDL_ENABLE);
}
@@ -187,7 +221,7 @@ bool Input::discoverGameController()
// Comprueba si hay algun mando conectado
bool Input::gameControllerFound()
{
if (mNumGamepads > 0)
if (numGamepads > 0)
return true;
else
return false;
@@ -196,8 +230,8 @@ bool Input::gameControllerFound()
// Obten el nombre de un mando de juego
std::string Input::getControllerName(int index)
{
if (mNumGamepads > 0)
return mControllerNames[index];
if (numGamepads > 0)
return controllerNames[index];
else
return "";
}
@@ -205,5 +239,5 @@ std::string Input::getControllerName(int index)
// Obten el numero de mandos conectados
int Input::getNumControllers()
{
return mNumGamepads;
return numGamepads;
}

View File

@@ -1,4 +1,5 @@
#pragma once
#include <SDL2/SDL.h>
#include <string>
#include <vector>
@@ -40,20 +41,19 @@ private:
Uint8 scancode; // Scancode asociado
bool active; // Indica si está activo
};
keyBindings_t mKeyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
struct GameControllerBindings_t
{
SDL_GameControllerButton button; // GameControllerButton asociado
bool active; // Indica si está activo
};
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
// SDL_GameController *mGameController; // Manejador para el mando
std::vector<SDL_GameController *> mConnectedControllers;
std::vector<std::string> mControllerNames;
int mNumGamepads;
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
int numGamepads; // Numero de mandos conectados
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
// Comprueba si hay un mando conectado
bool discoverGameController();
@@ -74,6 +74,9 @@ public:
// Comprueba si un input esta activo
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
// Comprueba si hay almenos un input activo
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
// Comprueba si hay algun mando conectado
bool gameControllerFound();

View File

@@ -101,11 +101,11 @@ void Intro::updateCounter()
{
JA_PlayMusic(loadingSound2);
}
counter++;
++counter;
}
else
{
preCounter++;
++preCounter;
}
}
@@ -124,7 +124,7 @@ void Intro::renderLoad()
SDL_Rect rect = {0, 0 + loadCounter, 256, 8 - loadCounter};
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
for (int i = 0; i < 6; ++i)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
@@ -139,7 +139,7 @@ void Intro::renderLoad()
SDL_Rect rect = {0, 64 + (loadCounter - 8), 256, 8 - (loadCounter - 8)};
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
for (int i = 0; i < 6; ++i)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
@@ -154,7 +154,7 @@ void Intro::renderLoad()
SDL_Rect rect = {0, 128 + (loadCounter - 16), 256, 8 - (loadCounter - 16)};
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
for (int i = 0; i < 6; ++i)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
@@ -166,7 +166,7 @@ void Intro::renderLoad()
{
sprite->render();
SDL_Rect rect = {0, 0, 8, 8};
for (int i = 0; i < loadCounter; i++)
for (int i = 0; i < loadCounter; ++i)
{
rect.x = (i * 8) % 256;
rect.y = (i / 32) * 8;

View File

@@ -30,8 +30,8 @@ private:
int preCounter; // Contador previo para realizar una pausa inicial
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
int loadCounter; // Contador para controlar las cargas
bool load1, load2;
JA_Music loadingSound1, loadingSound2, loadingSound3;

View File

@@ -58,7 +58,7 @@ void Item::render()
// Actualiza las variables del objeto
void Item::update()
{
counter++;
++counter;
}
// Obtiene el rectangulo de colision del objeto

View File

@@ -57,31 +57,33 @@ void ItemTracker::addItem(std::string name, SDL_Point pos)
// Busca una entrada en la lista por nombre
int ItemTracker::findByName(std::string name)
{
const int c = -1;
int i = 0;
for (int i = 0; i < list.size(); i++)
for (auto l : list)
{
if (list[i].name == name)
if (l.name == name)
{
return i;
}
++i;
}
return c;
return -1;
}
// Busca una entrada en la lista por posición
int ItemTracker::findByPos(int index, SDL_Point pos)
{
const int c = -1;
int i = 0;
for (int i = 0; i < list[index].pos.size(); i++)
for (auto l:list[index].pos)
{
if ((list[index].pos[i].x == pos.x) && (list[index].pos[i].y == pos.y))
if ((l.x == pos.x) && (l.y == pos.y))
{
return i;
}
++i;
}
return c;
return -1;
}

View File

@@ -16,7 +16,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
texture2->setColor(0, 0, 0);
for (int i = 0; i < texture->getHeight(); i++)
for (int i = 0; i < texture->getHeight(); ++i)
{
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
if (i % 2 == 0)
@@ -110,7 +110,7 @@ void Logo::updateJAILGAMES()
{
if (counter > 30)
{
for (int i = 1; i < sprite.size(); i++)
for (int i = 1; i < (int)sprite.size(); ++i)
{
const int speed = 8;
const int dest = 37;
@@ -227,7 +227,7 @@ void Logo::update()
checkEventHandler();
// Incrementa el contador
counter++;
++counter;
// Gestiona el logo de JAILGAME
updateJAILGAMES();

View File

@@ -27,8 +27,8 @@ private:
std::vector<color_t> color; // Vector con los colores para el fade
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
int initFade; // Tiempo del contador cuando inicia el fade a negro
int endLogo; // Tiempo del contador para terminar el logo
int postLogo; // Tiempo que dura el logo con el fade al maximo

View File

@@ -11,7 +11,7 @@ LTexture::LTexture(SDL_Renderer *renderer, std::string path)
this->path = path;
// Inicializa
texture = NULL;
texture = nullptr;
width = 0;
height = 0;
@@ -35,7 +35,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
int req_format = STBI_rgb_alpha;
int width, height, orig_format;
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
if (data == NULL)
if (data == nullptr)
{
SDL_Log("Loading image failed: %s", stbi_failure_reason());
exit(1);
@@ -60,11 +60,11 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
unload();
// La textura final
SDL_Texture *newTexture = NULL;
SDL_Texture *newTexture = nullptr;
// Carga la imagen desde una ruta específica
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
if (loadedSurface == NULL)
if (loadedSurface == nullptr)
{
printf("Unable to load image %s!\n", path.c_str());
}
@@ -72,7 +72,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
{
// Crea la textura desde los pixels de la surface
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == NULL)
if (newTexture == nullptr)
{
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
}
@@ -89,7 +89,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
// Return success
texture = newTexture;
return texture != NULL;
return texture != nullptr;
}
// Crea una textura en blanco
@@ -97,7 +97,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
{
// Crea una textura sin inicializar
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
if (texture == NULL)
if (texture == nullptr)
{
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
}
@@ -107,17 +107,17 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
this->height = height;
}
return texture != NULL;
return texture != nullptr;
}
// Libera la memoria de la textura
void LTexture::unload()
{
// Libera la textura si existe
if (texture != NULL)
if (texture != nullptr)
{
SDL_DestroyTexture(texture);
texture = NULL;
texture = nullptr;
width = 0;
height = 0;
}
@@ -148,7 +148,7 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
SDL_Rect renderQuad = {x, y, width, height};
// Obtiene las dimesiones del clip de renderizado
if (clip != NULL)
if (clip != nullptr)
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;

View File

@@ -43,7 +43,7 @@ public:
void setAlpha(Uint8 alpha);
// Renderiza la textura en un punto específico
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = NULL, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
// Establece la textura como objetivo de renderizado
void setAsRenderTarget(SDL_Renderer *renderer);

View File

@@ -232,7 +232,7 @@ void Player::checkState()
{
vx = 0.0f;
vy = maxVY;
fallCounter++;
++fallCounter;
playFallSound();
}
@@ -249,7 +249,7 @@ void Player::checkState()
else if (state == s_jumping)
{
jumpCounter++;
++jumpCounter;
playJumpSound();
}
}

View File

@@ -4,13 +4,12 @@
#include <sstream>
// Constructor
Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *itemTracker, int *items, Debug *debug)
Room::Room(std::string file, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *itemTracker, int *items, Debug *debug)
{
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
tilesetWidth = 20;
paused = false;
itemColor1 = stringToColor("magenta");
itemColor2 = stringToColor("yellow");
@@ -24,13 +23,14 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset
this->debug = debug;
// Crea los objetos
load(file_path);
loadMapFile(file);
texture = new LTexture(renderer, asset->get(tileset));
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
tilesetWidth = texture->getWidth() / tileSize;
// debug->clearLog();
// debug->addToLog(tileset);
// Calcula las superficies
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
loadMapTileFile(asset->get(tileMapFile));
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
setLeftSurfaces();
@@ -40,8 +40,11 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mapTexture == NULL)
if (mapTexture == nullptr)
{
printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
@@ -69,13 +72,10 @@ Room::~Room()
}
}
// Carga las variables desde un fichero
bool Room::load(std::string file_path)
// Carga las variables desde un fichero de mapa
bool Room::loadMapFile(std::string file_path)
{
// Indicador de éxito en la carga
bool success = true;
std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
@@ -83,7 +83,7 @@ bool Room::load(std::string file_path)
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n", filename.c_str());
printf("Reading file %s\n\n", filename.c_str());
while (std::getline(file, line))
{
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
@@ -104,7 +104,6 @@ bool Room::load(std::string file_path)
if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
success = false;
}
} while (line != "[/enemy]");
@@ -113,7 +112,7 @@ bool Room::load(std::string file_path)
}
// Si la linea contiene el texto [tilemap] se realiza el proceso de carga del fichero tmx
else if (line == "[tilemap]")
/*else if (line == "[tilemap]")
{
do
{
@@ -159,7 +158,7 @@ bool Room::load(std::string file_path)
}
}
} while (line != "[/tilemap]");
}
}*/
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item
else if (line == "[item]")
@@ -177,12 +176,13 @@ bool Room::load(std::string file_path)
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
success = false;
}
} while (line != "[/item]");
// Añade el item al vector de items
@@ -202,7 +202,6 @@ bool Room::load(std::string file_path)
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
success = false;
}
}
}
@@ -215,10 +214,58 @@ bool Room::load(std::string file_path)
else
{
printf("Warning: Unable to open %s file\n", filename.c_str());
success = false;
return false;
}
return success;
return true;
}
// Carga las variables y texturas desde un fichero de mapa de tiles
bool Room::loadMapTileFile(std::string file_path)
{
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n\n", filename.c_str());
while (std::getline(file, line))
{ // Lee el fichero linea a linea
if (line.find("data encoding") != std::string::npos)
{
// Lee la primera linea
std::getline(file, line);
while (line != "</data>")
{ // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
tilemap.push_back(std::stoi(tmp) - 1);
}
// Lee la siguiente linea
std::getline(file, line);
}
}
}
// Cierra el fichero
printf("Closing file %s\n\n", filename.c_str());
file.close();
}
else
{ // El fichero no se puede abrir
printf("Warning: Unable to open %s file\n", filename.c_str());
return false;
}
return true;
}
// Asigna variables a partir de dos cadenas
@@ -227,7 +274,12 @@ bool Room::setVars(std::string var, std::string value)
// Indicador de éxito en la asignación
bool success = true;
if (var == "name")
if (var == "tilemap")
{
tileMapFile = value;
}
else if (var == "name")
{
name = value;
}
@@ -453,34 +505,36 @@ color_t Room::getBorderColor()
void Room::fillMapTexture()
{
SDL_SetRenderTarget(renderer, mapTexture);
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
// Los tilesets son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
SDL_Rect clip = {0, 0, 8, 8};
for (int y = 0; y < 16; y++)
for (int x = 0; x < 32; x++)
SDL_Rect clip = {0, 0, tileSize, tileSize};
for (int y = 0; y < mapHeight; ++y)
for (int x = 0; x < mapWidth; ++x)
{
// Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n.
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
const int index = (y * 32) + x;
const int index = (y * mapWidth) + x;
if (index > -1)
{
clip.x = (tilemap[index] % 20) * 8;
clip.y = (tilemap[index] / 20) * 8;
texture->render(renderer, x * 8, y * 8, &clip);
clip.x = (tilemap[index] % tilesetWidth) * tileSize;
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
texture->render(renderer, x * tileSize, y * tileSize, &clip);
// ****
if (debug->getEnabled())
{
if (clip.x != -8)
if (clip.x != -tileSize)
{
clip.x = x * 8;
clip.y = y * 8;
clip.x = x * tileSize;
clip.y = y * tileSize;
SDL_SetRenderDrawColor(renderer, 64, 64, 64, 224);
SDL_RenderFillRect(renderer, &clip);
}
}
// ****
}
}
@@ -560,7 +614,7 @@ void Room::renderMap()
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
// Dibuja la textura con el mapa en pantalla
SDL_RenderCopy(renderer, mapTexture, &rect, NULL);
SDL_RenderCopy(renderer, mapTexture, &rect, nullptr);
}
// Dibuja los enemigos en pantalla
@@ -691,8 +745,7 @@ bool Room::enemyCollision(SDL_Rect &rect)
// Indica si hay colision con un objeto a partir de un rectangulo
bool Room::itemCollision(SDL_Rect &rect)
{
bool collision = false;
for (int i = 0; i < items.size(); i++)
for (int i = 0; i < (int)items.size(); ++i)
{
if (checkCollision(rect, items[i]->getCollider()))
{
@@ -701,11 +754,11 @@ bool Room::itemCollision(SDL_Rect &rect)
items.erase(items.begin() + i);
JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1;
collision = true;
return true;
}
}
return collision;
return false;
}
// Recarga la textura
@@ -763,7 +816,7 @@ void Room::setBottomSurfaces()
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
// Hay que recorrer la habitación por filas (excepto los de la última fila)
for (int i = 0; i < tilemap.size() - mapWidth; i++)
for (int i = 0; i < (int)tilemap.size() - mapWidth; ++i)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
{
@@ -780,28 +833,26 @@ void Room::setBottomSurfaces()
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0;
int lastOne = 0;
while (i < tile.size())
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
lastOne = i;
i++;
++i;
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
i++;
++i;
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
if (tile[i] == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
++i;
}
// debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
}
}
@@ -810,11 +861,9 @@ void Room::setTopSurfaces()
{
std::vector<int> tile;
// debug->addToLog(std::to_string(tilemap.size()));
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < tilemap.size(); i++)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
{
@@ -831,28 +880,26 @@ void Room::setTopSurfaces()
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0;
int lastOne = 0;
while (i < tile.size())
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
lastOne = i;
i++;
++i;
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
i++;
++i;
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
if (tile[i] == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
++i;
}
// debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
}
}
@@ -879,18 +926,18 @@ void Room::setLeftSurfaces()
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies
int i = 0;
while (i < tile.size())
while (i < (int)tile.size())
{
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
{
i++;
++i;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line);
i++;
++i;
}
}
@@ -917,18 +964,18 @@ void Room::setRightSurfaces()
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies
int i = 0;
while (i < tile.size())
while (i < (int)tile.size())
{
v_line_t line;
line.x = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
{
i++;
++i;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line);
i++;
++i;
}
}
@@ -937,7 +984,7 @@ void Room::setLeftSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_l
std::vector<int> found;
for (int i = 0; i < tilemap.size(); ++i)
for (int i = 0; i < (int)tilemap.size(); ++i)
{
if (getTile(i) == t_slope_l)
{
@@ -957,7 +1004,7 @@ void Room::setLeftSlopes()
int lookingFor = found[0] + mapWidth + 1;
int lastOneFound = found[0];
found.erase(found.begin());
for (int i = 0; i < found.size(); i++)
for (int i = 0; i < (int)found.size(); ++i)
{
if (found[i] == lookingFor)
{
@@ -970,7 +1017,6 @@ void Room::setLeftSlopes()
line.x2 = ((lastOneFound % mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1;
leftSlopes.push_back(line);
// debug->addToLog("LS: " + std::to_string(line.x1) + "," + std::to_string(line.y1) + "," + std::to_string(line.x2) + "," + std::to_string(line.y2));
}
}
@@ -979,7 +1025,7 @@ void Room::setRightSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_r
std::vector<int> found;
for (int i = 0; i < tilemap.size(); ++i)
for (int i = 0; i < (int)tilemap.size(); ++i)
{
if (getTile(i) == t_slope_r)
{
@@ -999,7 +1045,7 @@ void Room::setRightSlopes()
int lookingFor = found[0] + mapWidth - 1;
int lastOneFound = found[0];
found.erase(found.begin());
for (int i = 0; i < found.size(); i++)
for (int i = 0; i < (int)found.size(); ++i)
{
if (found[i] == lookingFor)
{
@@ -1012,7 +1058,6 @@ void Room::setRightSlopes()
line.x2 = (lastOneFound % mapWidth) * tileSize;
line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1;
rightSlopes.push_back(line);
// debug->addToLog("RS: " + std::to_string(line.x1) + "," + std::to_string(line.y1) + "," + std::to_string(line.x2) + "," + std::to_string(line.y2));
}
}

View File

@@ -45,14 +45,15 @@ class Room
private:
std::string name; // Nombre de la habitación
color_t bgColor; // Color de fondo de la habitación
color_t borderColor; // Color de fondo de la habitación
color_t itemColor1;
color_t itemColor2;
color_t borderColor; // Color del borde de la pantalla
color_t itemColor1; // Color 1 para los items de la habitación
color_t itemColor2; // Color 2 para los items de la habitación
std::string roomUp; // Identificador de la habitación que se encuentra arriba
std::string roomDown; // Identificador de la habitación que se encuentra abajp
std::string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
std::string tileset; // Imagen con los graficos para la habitación
std::string tileMapFile; // Fichero con el mapa de indices de tile
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
std::vector<Item *> items; // Listado con los items que hay en la habitación
@@ -78,8 +79,11 @@ private:
int mapHeight; // Alto del mapa en tiles
int tilesetWidth; // Ancho del tileset en tiles
// Carga las variables desde un fichero
bool load(std::string file_path);
// Carga las variables desde un fichero de mapa
bool loadMapFile(std::string file);
// Carga las variables y texturas desde un fichero de mapa de tiles
bool loadMapTileFile(std::string file);
// Asigna variables a partir de dos cadenas
bool setVars(std::string var, std::string value);
@@ -116,7 +120,7 @@ private:
public:
// Constructor
Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *item_tracker, int *items, Debug *debug);
Room(std::string file, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *item_tracker, int *items, Debug *debug);
// Destructor
~Room();

View File

@@ -96,7 +96,7 @@ void ScoreBoard::render()
const int frame = desp % 4;
sprite->setCurrentFrame(frame);
for (int i = 0; i < board->lives; i++)
for (int i = 0; i < board->lives; ++i)
{
sprite->setPosX(8 + (16 * i) + desp);
index = i % color.size();
@@ -129,7 +129,7 @@ void ScoreBoard::render()
// Actualiza las variables del objeto
void ScoreBoard::update()
{
counter++;
++counter;
sprite->update();
if (!paused)

View File

@@ -21,7 +21,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
// Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == NULL)
if (gameCanvas == nullptr)
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
// Establece el modo de video
@@ -59,14 +59,14 @@ void Screen::start()
void Screen::blit()
{
// Vuelve a dejar el renderizador en modo normal
SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderTarget(renderer, nullptr);
// Borra el contenido previo
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
SDL_RenderClear(renderer);
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(renderer, gameCanvas, NULL, &dest);
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(renderer);
@@ -115,7 +115,7 @@ void Screen::setVideoMode(int fullScreenMode)
int scale = 0;
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight))
{
scale++;
++scale;
}
dest.w = gameCanvasWidth * scale;
@@ -259,7 +259,7 @@ void Screen::updateFade()
return;
}
fadeCounter++;
++fadeCounter;
if (fadeCounter > fadeLenght)
{
iniFade();
@@ -325,7 +325,7 @@ void Screen::updateSpectrumFade()
return;
}
spectrumFadeCounter++;
++spectrumFadeCounter;
if (spectrumFadeCounter > spectrumFadeLenght)
{
iniSpectrumFade();

View File

@@ -33,7 +33,7 @@ Test::~Test()
// Actualiza las variables
void Test::update()
{
for (int i = 0; i < points.size(); ++i)
for (int i = 0; i < (int)points.size(); ++i)
{
points[i].x += points[i].vx;
points[i].y += points[i].vy;

View File

@@ -22,7 +22,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset)
ticks = 0;
ticksSpeed = 15;
longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME P.A.C.O. THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?";
for (int i = 0; i < longText.length(); i++)
for (int i = 0; i < (int)longText.length(); i++)
{
letter_t l;
l.letter = longText.substr(i, 1);
@@ -108,7 +108,7 @@ void Title::checkEventHandler()
// Actualiza la marquesina
void Title::updateMarquee()
{
for (int i = 0; i < letters.size(); i++)
for (int i = 0; i < (int)letters.size(); i++)
{
if (letters[i].enabled)
{

View File

@@ -35,8 +35,8 @@ private:
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
std::string longText; // Texto que aparece en la parte inferior del titulo
int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<letter_t> letters; // Vector con las letras de la marquesina
// Actualiza las variables