Compare commits

2 Commits

Author SHA1 Message Date
de8c714132 migrats els fitxers .ani a segons/frame 2025-10-28 09:49:57 +01:00
da65777a5b migrades les clases Sprite a time based 2025-10-28 09:48:58 +01:00
68 changed files with 209 additions and 88 deletions

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=-1 loop=-1
frames=0,1,2,3,4,5,6,7 frames=0,1,2,3,4,5,6,7
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2 frames=0,1,2
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3,4,5,6,7,8,9 frames=0,1,2,3,4,5,6,7,8,9
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 frames=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3,3,3,3,3,3,3,3,3,3,3,3,2,1,0,0,0 frames=0,1,2,3,3,3,3,3,3,3,3,3,3,3,3,2,1,0,0,0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=7
[animation] [animation]
name=default name=default
speed=3 speed=0.0500
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5 frames=0,1,2,3,4,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5,6,7,8,9,10,11 frames=0,1,2,3,4,5,6,7,8,9,10,11
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=10 speed=0.1667
loop=0 loop=0
frames=0,1,2,3,4 frames=0,1,2,3,4
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=32
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5,6,7,6,5,4,3,2,1 frames=0,1,2,3,4,5,6,7,6,5,4,3,2,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5 frames=0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5 frames=0,1,2,3,4,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5 frames=0,1,2,3,4,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=7
[animation] [animation]
name=default name=default
speed=10 speed=0.1667
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=15
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=13
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,1,3,5,1,3,5,1,3,5 frames=0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,1,3,5,1,3,5,1,3,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3,4,5 frames=0,1,2,3,4,5
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=12 speed=0.2000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3,4,5,6,7 frames=0,1,2,3,4,5,6,7
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3,4,5,6,7 frames=0,1,2,3,4,5,6,7
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=32
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=5 speed=0.0833
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5,4,3,2,1 frames=0,1,2,3,4,5,4,3,2,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=44
[animation] [animation]
name=default name=default
speed=100 speed=1.6667
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=90
[animation] [animation]
name=default name=default
speed=100 speed=1.6667
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=47
[animation] [animation]
name=default name=default
speed=100 speed=1.6667
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=64
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=-1 loop=-1
frames=18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 frames=18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=10 speed=0.1667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3,4,5,6,7,8,9,10,11,12 frames=0,1,2,3,4,5,6,7,8,9,10,11,12
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3,3,2,1,0 frames=0,1,2,3,3,2,1,0
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=18
[animation] [animation]
name=default name=default
speed=5 speed=0.0833
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=4 speed=0.0667
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1 frames=0,1
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=8
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=32
[animation] [animation]
name=default name=default
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,21 +3,21 @@ frame_height=16
[animation] [animation]
name=stand name=stand
speed=8 speed=0.1333
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]
[animation] [animation]
name=walk name=walk
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]
[animation] [animation]
name=walk_menu name=walk_menu
speed=0 speed=0.0
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -3,21 +3,21 @@ frame_height=16
[animation] [animation]
name=stand name=stand
speed=8 speed=0.1333
loop=0 loop=0
frames=0 frames=0
[/animation] [/animation]
[animation] [animation]
name=walk name=walk
speed=8 speed=0.1333
loop=0 loop=0
frames=0,1,2,3,4,5,6,7 frames=0,1,2,3,4,5,6,7
[/animation] [/animation]
[animation] [animation]
name=walk_menu name=walk_menu
speed=0 speed=0.0
loop=0 loop=0
frames=0,1,2,3,4,5,6,7 frames=0,1,2,3,4,5,6,7
[/animation] [/animation]

View File

@@ -3,7 +3,7 @@ frame_height=18
[animation] [animation]
name=default name=default
speed=6 speed=0.1000
loop=0 loop=0
frames=0,1,2,3 frames=0,1,2,3
[/animation] [/animation]

View File

@@ -63,20 +63,72 @@ auto SurfaceAnimatedSprite::getIndex(const std::string& name) -> int {
return -1; return -1;
} }
// Calcula el frame correspondiente a la animación // Calcula el frame correspondiente a la animación (time-based)
void SurfaceAnimatedSprite::animate() { void SurfaceAnimatedSprite::animate(float delta_time) {
if (animations_[current_animation_].speed == 0) { if (animations_[current_animation_].speed <= 0.0F) {
return; return;
} }
// Calcula el frame actual a partir del contador // Acumula el tiempo transcurrido
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed; animations_[current_animation_].accumulated_time += delta_time;
// Calcula el frame actual a partir del tiempo acumulado
const int TARGET_FRAME = static_cast<int>(
animations_[current_animation_].accumulated_time /
animations_[current_animation_].speed
);
// Si alcanza el final de la animación, maneja el loop
if (TARGET_FRAME >= static_cast<int>(animations_[current_animation_].frames.size())) {
if (animations_[current_animation_].loop == -1) {
// Si no hay loop, congela en el último frame
animations_[current_animation_].current_frame =
static_cast<int>(animations_[current_animation_].frames.size()) - 1;
animations_[current_animation_].completed = true;
// Establece el clip del último frame
if (animations_[current_animation_].current_frame >= 0) {
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
} else {
// Si hay loop, vuelve al frame indicado
animations_[current_animation_].accumulated_time =
static_cast<float>(animations_[current_animation_].loop) *
animations_[current_animation_].speed;
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
// Establece el clip del frame de loop
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
} else {
// Actualiza el frame actual
animations_[current_animation_].current_frame = TARGET_FRAME;
// Establece el clip del frame actual
if (animations_[current_animation_].current_frame >= 0 &&
animations_[current_animation_].current_frame <
static_cast<int>(animations_[current_animation_].frames.size())) {
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
}
}
// Calcula el frame correspondiente a la animación (frame-based, deprecated)
void SurfaceAnimatedSprite::animate() {
if (animations_[current_animation_].speed == 0.0F) {
return;
}
// Calcula el frame actual a partir del contador (sistema antiguo)
animations_[current_animation_].current_frame =
static_cast<int>(animations_[current_animation_].counter / animations_[current_animation_].speed);
// Si alcanza el final de la animación, reinicia el contador de la animación // 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 // en función de la variable loop y coloca el nuevo frame
if (animations_[current_animation_].current_frame >= static_cast<int>(animations_[current_animation_].frames.size())) { if (animations_[current_animation_].current_frame >= static_cast<int>(animations_[current_animation_].frames.size())) {
if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size(); animations_[current_animation_].current_frame =
static_cast<int>(animations_[current_animation_].frames.size()) - 1;
animations_[current_animation_].completed = true; animations_[current_animation_].completed = true;
} else { // Si hay loop, vuelve al frame indicado } else { // Si hay loop, vuelve al frame indicado
animations_[current_animation_].counter = 0; animations_[current_animation_].counter = 0;
@@ -104,7 +156,8 @@ void SurfaceAnimatedSprite::setCurrentAnimation(const std::string& name) {
if (current_animation_ != NEW_ANIMATION) { if (current_animation_ != NEW_ANIMATION) {
current_animation_ = NEW_ANIMATION; current_animation_ = NEW_ANIMATION;
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].accumulated_time = 0.0F; // Time-based
animations_[current_animation_].counter = 0; // Frame-based (deprecated)
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]); setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
} }
@@ -116,13 +169,20 @@ void SurfaceAnimatedSprite::setCurrentAnimation(int index) {
if (current_animation_ != NEW_ANIMATION) { if (current_animation_ != NEW_ANIMATION) {
current_animation_ = NEW_ANIMATION; current_animation_ = NEW_ANIMATION;
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].accumulated_time = 0.0F; // Time-based
animations_[current_animation_].counter = 0; // Frame-based (deprecated)
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]); setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
} }
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto (time-based)
void SurfaceAnimatedSprite::update(float delta_time) {
animate(delta_time);
SurfaceMovingSprite::update(delta_time);
}
// Actualiza las variables del objeto (frame-based, deprecated)
void SurfaceAnimatedSprite::update() { void SurfaceAnimatedSprite::update() {
animate(); animate();
SurfaceMovingSprite::update(); SurfaceMovingSprite::update();
@@ -131,7 +191,8 @@ void SurfaceAnimatedSprite::update() {
// Reinicia la animación // Reinicia la animación
void SurfaceAnimatedSprite::resetAnimation() { void SurfaceAnimatedSprite::resetAnimation() {
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].accumulated_time = 0.0F; // Time-based
animations_[current_animation_].counter = 0; // Frame-based (deprecated)
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
} }
@@ -183,7 +244,8 @@ auto parseAnimationParameter(const std::string& key, const std::string& value, A
return true; return true;
} }
if (key == "speed") { if (key == "speed") {
animation.speed = std::stoi(value); // Soporta tanto float (segundos) como int (compatibilidad con sistema antiguo)
animation.speed = std::stof(value);
return true; return true;
} }
if (key == "loop") { if (key == "loop") {

View File

@@ -13,11 +13,14 @@ class Surface; // lines 9-9
struct AnimationData { struct AnimationData {
std::string name; // Nombre de la animacion std::string name; // Nombre de la animacion
std::vector<SDL_FRect> frames; // Cada uno de los frames que componen la animación std::vector<SDL_FRect> frames; // Cada uno de los frames que componen la animación
int speed{5}; // Velocidad de la animación float speed{0.083F}; // Velocidad de la animación (segundos por frame)
int loop{0}; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva int loop{0}; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
bool completed{false}; // Indica si ha finalizado la animación bool completed{false}; // Indica si ha finalizado la animación
int current_frame{0}; // Frame actual int current_frame{0}; // Frame actual
int counter{0}; // Contador para las animaciones float accumulated_time{0.0F}; // Tiempo acumulado para las animaciones (time-based)
// DEPRECATED: Mantener compatibilidad con sistema antiguo
int counter{0}; // Contador para las animaciones (frame-based, deprecated)
AnimationData() AnimationData()
@@ -35,7 +38,10 @@ class SurfaceAnimatedSprite : public SurfaceMovingSprite {
std::vector<AnimationData> animations_; // Vector con las diferentes animaciones std::vector<AnimationData> animations_; // Vector con las diferentes animaciones
int current_animation_ = 0; // Animacion activa int current_animation_ = 0; // Animacion activa
// Calcula el frame correspondiente a la animación actual // Calcula el frame correspondiente a la animación actual (time-based)
void animate(float delta_time);
// Calcula el frame correspondiente a la animación actual (frame-based, deprecated)
void animate(); void animate();
// Carga la animación desde un vector de cadenas // Carga la animación desde un vector de cadenas
@@ -51,7 +57,11 @@ class SurfaceAnimatedSprite : public SurfaceMovingSprite {
// Destructor // Destructor
~SurfaceAnimatedSprite() override = default; ~SurfaceAnimatedSprite() override = default;
// Actualiza las variables del objeto // Actualiza las variables del objeto (time-based)
void update(float delta_time) override;
// Actualiza las variables del objeto (frame-based, deprecated)
[[deprecated("Use update(float delta_time) instead")]]
void update() override; void update() override;
// Comprueba si ha terminado la animación // Comprueba si ha terminado la animación

View File

@@ -39,8 +39,26 @@ void SurfaceMovingSprite::clear() {
SurfaceSprite::clear(); SurfaceSprite::clear();
} }
// Mueve el sprite // Mueve el sprite (time-based)
// Nota: vx_, vy_ ahora se interpretan como pixels/segundo
// Nota: ax_, ay_ ahora se interpretan como pixels/segundo²
void SurfaceMovingSprite::move(float delta_time) {
// Aplica aceleración a velocidad (time-based)
vx_ += ax_ * delta_time;
vy_ += ay_ * delta_time;
// Aplica velocidad a posición (time-based)
x_ += vx_ * delta_time;
y_ += vy_ * delta_time;
// Actualiza posición entera para renderizado
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Mueve el sprite (frame-based, deprecated)
void SurfaceMovingSprite::move() { void SurfaceMovingSprite::move() {
// Versión antigua: suma directa sin delta_time
x_ += vx_; x_ += vx_;
y_ += vy_; y_ += vy_;
@@ -51,7 +69,12 @@ void SurfaceMovingSprite::move() {
pos_.y = static_cast<int>(y_); pos_.y = static_cast<int>(y_);
} }
// Actualiza las variables internas del objeto // Actualiza las variables internas del objeto (time-based)
void SurfaceMovingSprite::update(float delta_time) {
move(delta_time);
}
// Actualiza las variables internas del objeto (frame-based, deprecated)
void SurfaceMovingSprite::update() { void SurfaceMovingSprite::update() {
move(); move();
} }

View File

@@ -22,7 +22,10 @@ class SurfaceMovingSprite : public SurfaceSprite {
SDL_FlipMode flip_; // Indica como se voltea el sprite SDL_FlipMode flip_; // Indica como se voltea el sprite
// Mueve el sprite // Mueve el sprite (time-based)
void move(float delta_time);
// Mueve el sprite (frame-based, deprecated)
void move(); void move();
public: public:
@@ -34,8 +37,12 @@ class SurfaceMovingSprite : public SurfaceSprite {
// Destructor // Destructor
~SurfaceMovingSprite() override = default; ~SurfaceMovingSprite() override = default;
// Actualiza las variables internas del objeto // Actualiza las variables internas del objeto (time-based)
virtual void update(); void update(float delta_time) override;
// Actualiza las variables internas del objeto (frame-based, deprecated)
[[deprecated("Use update(float delta_time) instead")]]
void update() override;
// Reinicia todas las variables a cero // Reinicia todas las variables a cero
void clear() override; void clear() override;

View File

@@ -46,3 +46,15 @@ void SurfaceSprite::clear() {
pos_ = {.x = 0, .y = 0, .w = 0, .h = 0}; pos_ = {.x = 0, .y = 0, .w = 0, .h = 0};
clip_ = {.x = 0, .y = 0, .w = 0, .h = 0}; clip_ = {.x = 0, .y = 0, .w = 0, .h = 0};
} }
// Actualiza el estado del sprite (time-based)
void SurfaceSprite::update(float delta_time) {
// Base implementation does nothing (static sprites)
(void)delta_time; // Evita warning de parámetro no usado
}
// Actualiza el estado del sprite (frame-based, deprecated)
void SurfaceSprite::update() {
// Llama a la versión time-based con 0.0f para compatibilidad
update(0.0F);
}

View File

@@ -23,6 +23,13 @@ class SurfaceSprite {
// Destructor // Destructor
virtual ~SurfaceSprite() = default; virtual ~SurfaceSprite() = default;
// Actualiza el estado del sprite (time-based)
virtual void update(float delta_time);
// Actualiza el estado del sprite (frame-based, deprecated)
[[deprecated("Use update(float delta_time) instead")]]
virtual void update();
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
virtual void render(); virtual void render();
virtual void render(Uint8 source_color, Uint8 target_color); virtual void render(Uint8 source_color, Uint8 target_color);

View File

@@ -57,9 +57,9 @@ void GameOver::update() {
// Actualiza el color usado para renderizar los textos e imagenes // Actualiza el color usado para renderizar los textos e imagenes
updateColor(); updateColor();
// Actualiza los dos sprites (con delta time escalado por velocidad) // Actualiza los dos sprites con delta time
player_sprite_->update(); player_sprite_->update(delta);
tv_sprite_->update(); tv_sprite_->update(delta);
// Actualiza el objeto Screen // Actualiza el objeto Screen
Screen::get()->update(); Screen::get()->update();