Saturday, December 27, 2008

Arpad Miklos Gaywatch

Remake (partial) Fruity Frank ... 23 - A smoother character movement

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 ()
    {if (enMovimiento) / / If it is moving, I go
    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

    Friday, December 19, 2008

    Synyster Gates Haircut The Sims 2

    Remake (partial) Fruity Frank ... 22 - Redesigning using classes (3 - Animated characters)

    still one thing left to do for the game to be redesigned using the same classes functionality than the previous version: an animated character. We
     said that ideally the class "ElementoGráfico" allow us to manage both elements with a single static image elements that have multiple images that act as different frames to give a real sense of movement. Even desirable that we asked to have different sequences of images in the sense that the character is shown (left, right, up or down).  
    Neither is particularly difficult. Come on with it ...



    First, we will now have an array of images within ElemGrafico class. We are interested in not declaring the array as "Picture [,]", but as" Picture [][]", to allow you a different number of frames in one direction or another:





    / / The sequence of images, whether animated
    protected Image [] [] sequence;





    variables will need to know in what direction we are, and what frame number. For the source more readable, we can create variables (or constant) called UP, DOWN, etc.



    fotogramaActual protected byte;
    protected byte address; byte public const DOWN = 0; public const byte UP = 1;


      Draw Now the routine will display a static image or animated image as we have loaded: 



    public void Draw ()
     {if (contieneSecuencia)  sequence [address] [fotogramaActual]. Draw (x, y); 
    else if (contieneImagen)
    MyPicture . Draw (x, y);

    Hardware.ErrorFatal else ("He has tried to draw a picture not loaded! ");}



     Where variable contieneSecuencia" declared value "false" in the constructor, and get the value "true" when loading.  


    public

    ElemGrafico () {

    contieneImagen = false;
    contieneSecuencia = false;
    direction = DOWN;
    fotogramaActual = 0;
    sequence = new Image [4] []}


      

    When you load, we will receive an "Array" image name. We will reserve space for all of them and load them one by one:



    public void

    CargarSecuencia (byte direcc, string [] names) {

    contieneImagen = true;
    contieneSecuencia = true;
    Tammany byte = (byte) nombres.Length;
    sequence [ADDRESS] = new Image [Tammany]
    for (byte i = 0; i \u0026lt;nombres.Length; i + +) {
    sequence [ADDRESS] [i] = new Image (names [i]) ;
    }}
      



    when changing direction, we must return the frame number 0, just in case in one direction would have more frames than the other. If the address you ask us is where we are, you should not need to go back to frame 0:



    public void

    CambiarDireccion (byte nuevaDir)

    {if (address! = NuevaDir)
    address = {
    nuevaDir;
    fotogramaActual = 0;
    }}




    The character will change the constructor, which now does not load an image but a sequence:



    public Character (Game j) / / Constructor { ...
    CargarSecuencia (UP,
    new string [] {"imagenes/personajea1.png"
    "imagenes/personajea2.png"});
    CargarSecuencia (RIGHT
    new string [] {"imagenes/personajed1.png"
      "imagenes/personajed2.png"});
      ...
    • }


      
    addition, we must decide when we want to change the character's appearance. Could be in every frame of the game, and then include "miPersonaje.SiguienteFotograma" within the method "SiguienteFotograma" Game, but in the original Frank Fruity, the character just changes shape when it moves, so what will we do "MoverDerecha" and similar methods:


    • MoverDerecha public void ()

    • {if (miJuego.GetNivelActual (). EsPosibleMover ((short) (x + incrX), y)) {

    CambiarDireccion (RIGHT);
     SiguienteFotograma ();  x + = incrX; 
    miJuego.GetMarcador (). IncrPuntuacion (
    miJuego.GetNivelActual (). PuntosMover ( x, y));
    }}



      With that we have matched nearly all the features of version "not object oriented," except the shot. Rejoin soon, but now is a shot a little more "real", instead of always move to the right, there are obstacles or not exist.

    If you want to see the full source, the entire project's source is:
    code.google.com / p / fruityfrank