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
  

0 comments:

Post a Comment