top of page
  • Writer's pictureBruce

Creating proximity triggered falling nasties in MPAGD

Updated: Nov 22, 2020

...well I couldn't think of a better name for them. But these are hazards that fall from the ceiling just as the player is about to walk under them. This is another mechanic that I used in Cocoa and the Time Machine and improved in 24 Hour Parsley People.

They are pretty easy to implement, and in the code below I'll show you how you can adapt them to suit your own games.

First lets take a look at them in action. Here's an example in a demo screen....

So, a couple of things to note here.

1. I only want to trigger the fall when the player is just beneath them

2. The player must be within a specific vertical range of the falling nasty to trigger

In other words, we need to be careful not trigger them if the player walks above the nasty. And in my example I don't want the player on the ground level to trigger the fall in the upstairs level.

Obviously, your use case may need different rules - but the code below should be easily adaptable.

Firstly, lets think about how MPAGD sprites work, and specifically how their co-ordinates work. Each sprite is a 16px by 16px square. And each instance of a Sprite has an X and Y value, this is the x & y coordinate of the top left hand corner of the sprite as it appears on the screen. So if your sprite is in the very top left corner of the screen, it's X would be 0 and its Y would be 0.

Now, the problem is, with a falling nasty, we'll need to know the X and Y of both the nasty AND the player. And our code is going to need to live in one of the Sprite events, it probably makes sense to use one of our EVENTSPRITETYPE's for the falling nasty. So we are going to need a couple of variables that will store the X & Y values of the player. I tend to use F & G for these, purely out of can use what you like, either way open up your player event and lets add some cod ( I tend to drop it in at the bottom of the Player script):


OK, now we'll be able to use the players X & Y values when we are in the falling nasty script...

In this example I was using IMAGE 12, obviously remove that IF/ENDIF as required, or change it to reference your falling nasty sprite image.

What we are doing here is effectively checking the position of the player relative to the falling nasty - first is the player beneath the falling nasty, and, if so, is it within our given height range ?

In the falling nasties SETTINGA I am actually storing the the X value of the Player minus 18 - in other words 18 pixels to the left of the player

I'm doing a similar thing with variable M, this time I am storing the X value of the players current position PLUS 18 - or 18 pixels top the right of the player

You can change to any value you like, rather than use 18 - depending on how early or late you want the fall to be triggered.

So, as soon as M or SETTINGA match the x value of the falling nasty, we trigger the fall.

NOTE: In this script I am using multiple 'SPRITEDOWNS' to dictate the speed of the fall, you can use as many (or few) as your game requires to make it easier or more difficult to avoid. As an alternative you could replace the SPRITEDOWNS with FALL (thanks to Alessandro Grussu for the suggestion). With FALL the sprite will accelerate as it drops.

What you do within your collision IF statement is up to you, I've kept it simple for the purpose of the tutorial. I've then used the falling nasties SETTINGB parameter to act as a timer (how long it remains on the floor before being removed)...again, you can adapt this however you like, maybe having an explosion sprite, or something else entirely!

It would also be easy to adapt this code, so that, for example, you could trigger from above, perhaps as a fun way to kill an enemy!

Hope this helps!

276 views1 comment

Recent Posts

See All

1 Comment

Raul Gubert
Raul Gubert
Mar 11, 2021

thank you for this tutorial, I'm at the beginning so I'm learning slowly the mechanisms...Watching the video falling nasties I had a problem to understand what x and y were, I thought were related to the player, but then I understood that because we are in the nasty page, x and y refers to the nasties position...One doubt: the settingB is setting the time for the duration of the nastie once it has landaed, but I don't really understand how the loop is formed...add 1 to settingB and the if it is 21 this adding is automatic? 1,2,3,4,5... thank you again...I hope to be able to do a small game so I can show what I come up once…


Want to support my work?....Buy my games!


Hello, I'm Bruce and I write games for old 8bit computers using Jonathan Cauldwell's excellent Multi-Platform Arcade Games Designer (MPAGD)

I've written a few successful* games for the Sinclair ZX Spectrum and MSX platforms that have been (largely) well received including Twenty Four Hour Parsley People scoring a 10 out of 10 on Planeta Sinclair.

In my blog I am sharing lots of the code that I wrote for my games, in a way that you can use in your own games.   I've commented it so that you'll learn some of the techniques I use to create interesting new mechanics and help your games stand out from the pack.

MPAGD includes lots of standard scripts, they're great to get you started, but if you're new (or just rusty) when it comes to writing code, hopefully my tutorials will help you get started and  turn your imagination into awesome 8 bit games!

All my code is free to use and do with as you please, but if you find them useful please feel free to buy me a coffee ...or better still - buy or download my games :)

*successful is a very relative term in 8bit computer games

bottom of page