To make the character movement is smooth, the solution may be not equal 40 to the X coordinate each see it press the "right" (for example), but increased gradually to reach those 40. Still, when you press the "right", its position will continue to increase for several "frames" of the game, so we can use a Boolean variable to see if we are in the midst of a movement:
Some of the attributes that were once
/ / The character will move to 1 in 1 square, / / when you press each key
incrX = 41;
incrY = 34;
could now
be an
/ / The character will move several pixels in several
/ / when you press each key
anchoCasilla = 41;
altoCasilla = 34;
incrX = 4;
incrY = 4;
enMovimiento = false;
And the routine of moving to the right, formerly
MoverDerecha public void () {
if (miJuego.GetNivelActual (). EsPosibleMover ((short) (x + incrX), y)) {
CambiarDireccion (RIGHT);
SiguienteFotograma (); x + = incrX; miJuego.GetMarcador (). IncrPuntuacion ( miJuego.GetNivelActual (). PuntosMover (x, y));
}}
- now could be modified and
- MoverDerecha public void ()
return;
if (miJuego.GetNivelActual (). EsPosibleMover ((short) (x + anchoCasilla) y)) {
CambiarDireccion (RIGHT);
enMovimiento = true;
incrXActual = incrX; incrYActual = 0;
xFinal = (short) (x + anchoCasilla) yFinal = y;
miJuego.GetMarcador (). IncrPuntuacion (
miJuego.GetNivelActual (). PuntosMover ((short) (x + anchoCasilla), y));}
} That is, the movement starts (enMovimiento = true), calculates the increments to be used to move and the end position, total points ... but leaves the intermediate moves to another function, which could be called "Move" to be called from "SiguienteFotograma" (the game), and could be:
new public void Move ()
{if (! enMovimiento) / / If you are not moving , not to do anything
return;
SiguienteFotograma ();
x + = incrXActual / / Increase a little the position y + = incrYActual
;
/ / Check if I step (step width may not be proportional )
if ((incrXActual> 0) & & (x> = xFinal)) x =
xFinal;
if ((incrXActual \u0026lt;0) & & (x \u0026lt;= xFinal)) x = xFinal
; if ((incrYActual> 0) & & (y> = yFinal)) y = yFinal; if ((incrYActual \u0026lt;0) & & (y \u0026lt;= yFinal)) y = yFinal
;
/ / I check if I have advanced across the box to stop moving if (( xFinal == x) & & (y == yFinal))
enMovimiento = false;}
This feature increases position increases as expected, check that we have not passed (because the increase may not be an exact divisor of the width of the box), and marks the movement as completed when appropriate.
Incidentally, in this version I've improved the graphics a bit, retaining the original beauty and the 16 original colors, but with somewhat smaller points so that the images are ma ; s clear. The original images are still available in a subfolder, so that the final version of the game could even allow the user to choose whether to use the original graphics of the game or a slightly revised aesthetic.
As usual, the entire project's source is:
code.google.com / p / fruityfrank
0 comments:
Post a Comment