Thursday, January 1, 2009

How To Shave And Noy Bump Up

Remake (partial) Fruity Frank ... 24 - Enemies smarter

So far, our enemies simply moved from side to side. Now let's try to make movement a little more "intelligent" and more like the original Frank Fruity.
 We used a single method "Move" common all elements of the class enemy. " Now we do not all behave the same enemies:  


First not all appear at the initial instant: each has a slightly larger delay than the others, to appear one by one.
To follow, the intelligence of the movements that will make everyone dependent on the type of enemy in question. For details:

  
The lords nose almost always move through the holes of the screen, and rarely break walls.


The lords cucumber "will be much more impatient, and break walls more easily.




Both types of enemies move basically at random, tending to continue their march until they collide with something, when you change direction. Later there will be a third enemy, the "strawberry", whose movement is basically to pursue the character.
addition, each type enemy appears at a different point of the screen:

  
The "nose" out from a central area of \u200b\u200bthe screen, we'll call her "nest."


The "cucumber" fall from the top.


Let
 seeing how to do this ... For  
enemies may know if you can move to a certain box will need to be able to communicate with the level that contains them, so in the constructor that will indicate which level: public

Nose (Level n) {
miNivel = n;
...
  addition, the "EsPosibleMover" that already existed was designed for the character, which could through walls and eating fruit, but the enemies can not eat fruit, and move preferably cavities. Therefore, we are interested in a new role, which could be called "MovilidadEnemigo", and would have 3 possible values: It would 



0 to indicate when you can not get into that position because there is a fruit, an apple or other enemy.


1 when you can get would be difficult, breaking walls, something that will rarely nose, but the cucumber itself may do more frequency.


be 2 when the hollow space, which can be moved without problem.

should also check that box if there is another enemy (or is already going into it), it should not be overlapped both in the same screen position, but this will leave for a little later.
  


/ / / Indicates if the enemy can move at a certain screen position
/ / / (2 = yes, hollow, 1 = sometimes, wall, 0 = never, fruit). Public byte
MovilidadEnemigo (short x, short y) {

short XMap = (short) ((x-xIniPantalla) / anchoCasilla) short
yMapa = (short) ((y-yIniPantalla) / altoCasilla)

if ((x \u0026lt;xIniPantalla)
if ((symbol == 'X') / / If it's wall, can with difficulty
elect a new random directions. Aa start moving in that direction if there are no obstacles, if there is a wall, begin to move with a low probability (eg 25%). If there is an obstacle or a wall but if the random number indicated above should not cross it, will remain stationary, and the next frame of game will get to choose a random direction and repeat the process.


  public override void Move () {

/ / if not active, I hope the stipulated time
to display if (! active) {

contadorHastaRetardo + +;
if (contadorHastaRetardo> = delay)
active = true;
return;}

/ / If you are standing, look for new directions
if (stopped) {
calcularNuevaDireccion ();
return;}
/ / If you can move in horizontal or vertical position, advances (short) (x + miNivel.GetAnchoCasilla ()), y) == 2) X + = incrX
;

else stopped = true;}

    ...

  • And the routine of moving the enemy "Pepino", which it can pass through walls, now could be very similar, with the difference that may come in boxes of "Mobility 1" (walls) and that should clear the box to the incoming:

  • ...
      / / If you can move in horizontal or vertical position, advances
      if ((! Standing) & & (incrX> 0)) {
    • if (miNivel.MovilidadEnemigo (
    • (short) (X + miNivel.GetAnchoCasilla ()), y)> = 1)
    • {x + = incrX;
    • miNivel.BorrarPosicionPantalla (x, y);}

    else stopped = true;}
  • ...
  • Regarding the position of each enemy, defined from the constructor of each level. For example, for the Level 1 could be: public

      Level1 ()
    • {byte i;
      MIMAP
    • map1 = new ();
    • enemy = new Enemy [NUMENEMIGOS]
    enemies [0] = new nose (this);
    enemies [0]. Move (miMapa.posXnido, miMapa.posYnido)
enemies [0]. SetRetardo (25), / / \u200b\u200b1 second after the start

enemies [1] = new nose (this);
enemies [1]. Move (miMapa.posXnido, MIMAP. posYnido)
enemies [1]. SetRetardo (75), / / \u200b\u200b3 seconds after the start
  enemies [2] = new Cucumber (this); 
enemies [2]. Move (
(short) (miMapa.GetXIni () + 5 * miMapa.GetAnchoCasilla ()),
miMapa.GetYIni ());
enemies [2]. SetRetardo (150) / / 6 seconds after the start
enemies [2]. SetVelocidad (0.4) ;}

  • As always, the entire project's source is:
    code.google.com / p / fruityfrank

0 comments:

Post a Comment