Minilop Retroware

MPAGD Advanced

Creating patterns for static nasties in MPAGD

16 November 2020

Here's a really simple way to add a pattern to the appearance/disappearance of a static nasty...without making it random. We'll be using MPAGDs DATA and READ commands to do this.

So, the effect I was trying to create in 24 Hour Parsley People: Episode 2 was of steam venting from a broken pipe (platform game clichés FTW!). But rather than it vent for x seconds and stop venting for y seconds, I wanted it to work in a pattern for example:

...and so on ( for a reasonable but not ridiculous number of variations)

This would then require the player to try and figure out the pattern before making their move.

Here's an example of the code running in a demo screen. I'm using the DIRECTION variable to store the pattern's current time setting - note that a higher DIRECTION value = a longer time period in the pattern:

This kind of pattern is ideal for using MPAGDs 'DATA' and 'READ' functions. But first we're going to create a sprite. As a minimum you'll need 2 frames, 1 for the nasty and a blank one. In my example, I'm using 5 frames the first 4 (numbers 0 to 3) are the Steam animation and the fifth one (#4) is blank...

So, when the steam is venting we will cycle through frames 0-3 and then when it stops venting we will hold the sprite on frame 4.

This means we can inflict damage if the player collides with the steam sprite ONLY when the steam frame is in the range 0 to 3.

And here's the code for your Steam Event...

;=============================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)

Now, this wont quite work on it's own. We're going to need to initialise some of the parameters when the Sprite first draws on screen.

We're going to set an initial time length in DIRECTION (since in the code above Direction only gets set when it equals SETTINGA. By default, a sprites DIRECTION is always initially 0 unless you change it in the sprite initialisation screen.

but we can also add a bit of variety here too, for example, we could randomise whether the steam is ON or OFF initially (SETTINGB), so your code in your Sprite Initialisation event might look something like:

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

And that's it. Now your static nasties can appear and disappear in a pattern, entirely at your command :)

Hope this helps!

All MPAGD Advanced