Agregar cansancio.

(1/1)

Tachikomaia:
Esto es para un juego de carreras, aún no agregué cansancio:
Código
fscommand ("fullscreen", "true");
// Estadísticas:
DKMarioMaxStamina = 1000;
DKMarioMaxSpeed = 0.5;
DKMaxStamina = 500;
DKMaxSpeed = 0.7;
// /////////////////////////////////////////////
// //////////////////  Most  ///////////////////
// /////////////////////////////////////////////
function FaceRight (id) {
if (eval(id+".Facing") == -1) {
set (id+".Facing", 1);
eval(id)._xscale = 100;
}
}
function FaceLeft (id) {
if (eval(id+".Facing") == 1) {
set (id+".Facing", -1);
eval(id)._xscale = -100;
}
}
// /////////////////////////////////////////////
// /////////////////  DKMario  /////////////////
// /////////////////////////////////////////////
function ControlDKMario () {
// Aumentar su Stamina si no está al máximo:
if (Player.Stamina<DKMarioMaxStamina) {
Player.Stamina++;
}
if (Key.isDown(39)) {
// Si se presiona derecha:
eval("RightWhen"+Player.Action)();
} else if (Key.isDown(37)) {
// Izquierda:
eval("LeftWhen"+Player.Action)();
} else {
// Nada:
eval("QuietWhen"+Player.Action)();
}
Player.Turn = Player.Turn+Math.abs(Player.Speed)*0.6;
if (Player.Turn>=10) {
Player.Turn = Player.Turn-10;
Player.Movie.play();
}
}
// When Quiet:
function RightWhenQuiet () {
StartToWalk();
WalkToRight();
}
function LeftWhenQuiet () {
StartToWalk();
WalkToLeft();
}
// When Walking:
function RightWhenWalking () {
WalkToRight();
if (Player.hitTest(MetaDePlayer) == true) {
Player.Meta = true;
removeMovieClip(MetaDePlayer);
}
}
function LeftWhenWalking () {
WalkToLeft();
if (Player.Meta == true && Player.hitTest(AliadoDePlayer) == true) {
gotoAndStop(4);
}
}
function QuietWhenWalking () {
Player.Action = "Quiet";
Player.Speed = 0;
}
// To whens:
function StartToWalk () {
Player.Action = "Walking";
Player.gotoAndStop(2);
}
function WalkToRight () {
Player.Speed = (Player.Speed + DKMarioMaxSpeed)/2;
Player._x = Player._x+Player.Speed;
FaceRight("Player");
}
function WalkToLeft () {
Player.Speed = (Player.Speed - DKMarioMaxSpeed)/2;
Player._x = Player._x+Player.Speed;
FaceLeft("Player");
}
// /////////////////////////////////////////////
// ///////////////////  DK  ////////////////////
// /////////////////////////////////////////////
function IAActs () {
if (IA.Stamina < IA.MaxStamina) {
IA.Stamina++;
}
IA.Tic = Math.abs(IA.Speed)*0.3;
IA.Speed = (IA.Speed + IA.MaxSpeed)/2;
IA._x = IA._x+IA.Speed;
IA.Turn = IA.Turn+IA.Tic;
if (IA.Turn>=10) {
IA.Turn = IA.Turn-10;
IA._xscale = IA._xscale*-1;
}
}

Quiero agregarlo, o sea:
- Que el personaje al moverse pierda stamina.
- Cuando queda con 10 o menos, quede en estado de cansado, sin poder moverse, pero recupere stamina y vuelva a su estado normal cuando tenga 50 o más.
- Cuando queda quieto también recupere.

No parece difícil pero la animación de caminar se estaba ejecutando aunque el personaje está cansado, intentaba arreglar eso hasta que me lié:
Código
// /////////////////////////////////////////////
// /////////////////  DKMario  /////////////////
// /////////////////////////////////////////////
function ControlDKMario () {
// Aumentar su Stamina si no está al máximo:
if (Key.isDown(39)) {
// Si se presiona derecha:
if (Player.Stamina > 50) {
Player.Stamina--;
eval("RightWhen"+Player.Action)();
}
} else if (Key.isDown(37)) {
// Izquierda:
if (Player.Stamina > 50) {
Player.Stamina--;
eval("LeftWhen"+Player.Action)();
}
} else {
// Nada:
eval("QuietWhen"+Player.Action)();
}
Player.Turn = Player.Turn+Math.abs(Player.Speed)*0.6;
if (Player.Turn>=10) {
Player.Turn = Player.Turn-10;
Player.Movie.play();
}
}
// When Quiet:
function RightWhenQuiet () {
StartToWalk();
WalkToRight();
}
function LeftWhenQuiet () {
StartToWalk();
WalkToLeft();
}
function QuietWhenTired () {
if (Player.Stamina < DKMarioMaxStamina) {
Player.Stamina++;
}
}
function QuietWhenQuiet () {
if (Player.Stamina < DKMarioMaxStamina) {
Player.Stamina++;
}
}
// When Walking:
function RightWhenWalking () {
WalkToRight();
}
function LeftWhenWalking () {
WalkToLeft();
}
function QuietWhenWalking () {
Player.Action = "Quiet";
Player.Speed = 0;
}
// To whens:
function StartToWalk () {
Player.Action = "Walking";
Player.gotoAndStop(2);
}
function WalkToRight () {
Player.Speed = (Player.Speed + DKMarioMaxSpeed)/2;
Player._x = Player._x+Player.Speed;
FaceRight("Player");
if (Player.hitTest(MetaDePlayer) == true) {
Player.Meta = true;
removeMovieClip(MetaDePlayer);
}
}
function WalkToLeft () {
Player.Speed = (Player.Speed - DKMarioMaxSpeed)/2;
Player._x = Player._x+Player.Speed;
FaceLeft("Player");
if (Player.Meta == true && Player.hitTest(AliadoDePlayer) == true) {
gotoAndStop(4);
}
}
function Tired () {
Player.Action = "Tired";
Player.Speed = 0;
}
 
 

Además la idea no me está resultando buena, no sé por qué.
Estaba poniendo que sólo puede moverse si tiene stamina 50 o más, pero entonces llega un punto en que se mueve un poquito (en teoría), ya no puede moverse, y se repite. Para que el descanso sea más largo supongo que lo soluciona lo que comenté con guiones, pero no suena realista que te puedas cansar mucho pero luego cuando estás un poco cansado no te puedas mover hasta quedar normal, no sé si me explico.
Puedes gastar energía hasta que sólo te queda 10. Pero entonces hasta que tengas 50 no puedes gastar. ¿Por qué antes sí? No tiene mucha lógica. Lo que se me ocurre ahora es que cuando tienes 50 si te mueves la energía te queda en 0 porque el organismo se enfoca en recuperarse, cierto sentido tiene ¿no?

Lo intentaré hacer más despacio a ver si me sale. Los leo.

ringman45:
Yo lo haría con una variable Player.Stamina que empiece en el máximo (DKMaxStamina) y que en cada frame que camina reste algo proporcional a Math.abs(Player.Speed). Cuando llegue a 0 le limitas la velocidad máxima, por ejemplo a la mitad, y en las funciones de cuando está quieto la vas recuperando poco a poco sin pasar del máximo.

Tachikomaia:
Ya casi lo resolví. Me dijeron un juego de la franquicia Monster Hunter, al buscar hallé esto
https://www.youtube.com/watch?v=AfdeaJN_PwA
entendí lo que me interesaba entender. Cuando el monstruo pierde toda su stamina, su fatiga aumenta a 50, y mientras tenga algo de fatiga no puede actuar, en vez de recuperar stamina pierde fatiga.

Cita de: ringman45 en 26 Octubre 2026, 13:17 pm

que en cada frame que camina reste algo proporcional a Math.abs(Player.Speed)
No me convence del todo, moverse más rápido no implica gastar más energía que quien se mueve más lento, es un tema de eficiencia energética, con la misma cantidad puedes moverte más. Aunque eso es para otro stat en el juego, que por ahora no pondré.

Citar

Cuando llegue a 0 le limitas la velocidad máxima, por ejemplo a la mitad
Sobre eso aún no sé, creo que hay 2 tipos de cansancio, un cansancio en que no puedes moverte y otro en que te mueves más lento.
Si tú haces una actividad física intensa, en cierto punto tendrás que parar totalmente para respirar agitadamente.
https://www.youtube.com/shorts/9ejXeTsHkCw
Pero luego puedes volver a hacer algo parecido.
En cambio, hay otro tipo de cansancio del que sólo te puedes recuperar descansando mucho tiempo.
https://www.youtube.com/shorts/Sj4fWOCAkVU
¿Podría existir algo como "vidas"? O sea, las veces que puedes entrar en estado de fatiga, antes de quedar casi sin poder moverte. Yo creo que tiene que ver con la producción de energía, pero no sé bien.

Navegación

[0] Índice de Mensajes