Minilop Retroware

MPAGD Avanzado

Crear patrones para bichos estáticos en MPAGD

16 de noviembre de 2020

Aquí tienes una forma muy sencilla de añadir un patrón a la aparición y desaparición de un bicho estático... sin hacerlo aleatorio. Para ello usaremos los comandos DATA y READ de MPAGD.

El efecto que intentaba crear en 24 Hour Parsley People: Episode 2 era el de vapor saliendo de una tubería rota (¡clichés de los juegos de plataformas, a por ellos!). Pero en lugar de que expulse vapor durante x segundos y deje de hacerlo durante y segundos, quería que funcionara según un patrón, por ejemplo:

...y así sucesivamente (con un número razonable, pero no ridículo, de variaciones)

Esto obligaría al jugador a intentar descubrir el patrón antes de hacer su movimiento.

Aquí tienes un ejemplo del código funcionando en una pantalla de demostración. Uso la variable DIRECTION para guardar el tiempo actual del patrón: ten en cuenta que un valor mayor de DIRECTION = un periodo más largo en el patrón:

Este tipo de patrón es ideal para las funciones 'DATA' y 'READ' de MPAGD. Pero primero vamos a crear un sprite. Como mínimo necesitarás 2 fotogramas, 1 para el bicho y uno en blanco. En mi ejemplo uso 5 fotogramas: los 4 primeros (números 0 a 3) son la animación del vapor y el quinto (#4) está en blanco...

Así que, cuando el vapor sale, recorreremos los fotogramas 0-3 y, cuando deja de salir, mantendremos el sprite en el fotograma 4.

Esto significa que podemos causar daño si el jugador colisiona con el sprite del vapor SOLO cuando el fotograma del vapor está en el rango de 0 a 3.

Y aquí está el código de tu evento de vapor...

;=============================STEAM
IF IMAGE 4                       ; image number of the Steam sprite
   IF FRAME <> 4                 ; this part ensures the steam is white
      SPRITEINK 7                ; when venting
   ELSE                          ; but uses the players sprite colour when 
      SPRITEINK 6                ; off, else the sprite would take on the steams colour
   ENDIF
                                 ; STEAM IS VENTING
   IF SETTINGB = 0               ; I'm using SETTINGB as the ON/OFF state,  of the stem
      IF A = 1                   ; I'm using A in my main loop, used for slowing down
         ADD 1 TO SETTINGA       ; Im using SETTING A as the counter, spo let's increment iy
         ADD 1 TO FRAME          ; I cant use animate so lets increment the frame
         IF FRAME = 4            ; if the next frame is the Blank one
            LET FRAME = 0        ; dont show it, instead go back to the first frame
         ENDIF
      ENDIF

      IF SETTINGA >= DIRECTION   ; I'm using DIRECTION to hold the length of the pattern, has the counter reached it?
         LET FRAME = 4           ; If so, switch to the blank frame
         LET SETTINGB = 1        ; And switch to the OFF state routine
         LET SETTINGA = 0        ; Reset the counter
         READ DIRECTION          ; Get the next time length from the DATA and store it in DIRECTION
      ENDIF
   ENDIF
   IF SETTINGB = 1               ; STEAM IS OFF
      ADD 1 TO SETTINGA          ; Increment the counter
      LET FRAME = 4              ; Remain on the Blank frame
      IF SETTINGA >= DIRECTION   ; have we reached the end of the timer?
         LET FRAME = 0           ; If so,switch to the first frame
         LET SETTINGB = 0        ; Switch to the ON routine (venting)
         LET SETTINGA = 0        ; Reset the counter
         READ DIRECTION          ; Get the next time length from the DATA and store it in DIRECTION
      ENDIF
   ENDIF

   IF COLLISION 0                ; Player has collided with the steam,
      IF FRAME <> 4              ; If the steam is active
         SUBTRACT 1 FROM L       ; do some damage
         BEEP 25                 ; ouchy noise!
         OTHER                   ; turn the player red...because it hurts!
         SPRITEINK 2
	 ENDSPRITE
      ENDIF
   ENDIF
ENDIF




DATA 50 40 20 40 80 30 50 40 10 30 ; add your timings (alternate between OFF and ON)

Ahora bien, esto no funcionará del todo por sí solo. Tenemos que inicializar algunos de los parámetros cuando el sprite se dibuja por primera vez en pantalla.

Vamos a fijar una duración inicial en DIRECTION (ya que en el código de arriba DIRECTION solo se establece cuando es igual a SETTINGA. Por defecto, el DIRECTION de un sprite siempre es 0 al principio, a menos que lo cambies en la pantalla de inicialización del sprite.

pero también podemos añadir algo de variedad aquí, por ejemplo, podríamos hacer aleatorio si el vapor está ENCENDIDO o APAGADO al principio (SETTINGB), de modo que tu código en el evento Sprite Initialisation podría parecerse a esto:

IF TYPE 4                ; this is the event type that contains our Steam sprite
   LET SETTINGA = 0      ; start the counter at 0
   GETRANDOM 2           ; get a random number (either 0 or 1) 
   LET SETTINGB = RND    ; make the steam either ON or OFF at random initally
   LET DIRECTION = 50    ; set the time to remain in the current state to 50 cycles
ENDIF

Y ya está. Ahora tus bichos estáticos pueden aparecer y desaparecer según un patrón, totalmente a tu mando :)

¡Espero que te sirva de ayuda!

Todo MPAGD Avanzado