top of page
  • Writer's pictureBruce

How to do Bonus item drops and flashy banner messages in MPAGD

A bit of a different tutorial today, rather than focusing on enemy sprite events here's a method for adding random item bonus drops...and flashy banner messages in your MPAGD games.


This is something I first wrote for Cocoa and the Time Machine and then improved in 24 Hour Parsley People.


What I wanted to achieve was...

  1. Player has defeated an enemy

  2. Randomly drop a bonus item (selected from 4 potential bonuses, weighted so that more powerful bonuses drop more rarely)

  3. Player collects bonus item

  4. Bonus item awards energy/points/whatever

  5. Banner flashes on screen

Here's an example of it in action in a demo screen, using some of the code from my latest game in which our hero Cocoa can deflect the Agents bullets using the Tesla Device...and when an Agent is defeated we drop a bonus item for Cocoa to collect.

In this example I have four potential Bonus drops:

  • Standard Parsley (restores 1/3 health) - 40% chance of dropping

  • Mega Parsley (restores all health) - 12% chance of dropping

  • Device fuel cell (restores 1/3 device power) - 30% chance of dropping

  • One Up (an extra life) - 8% chance of dropping

Which leaves us with a 10% chance of no-drop


Here's it in action:




First we're going to need to design some OBJECTS that will be used as the collectible drops, I've created 4 objects, and I've set them all to 'Hidden' (as they won't be positioned in a specific screen or automatically in the players inventory)




We're also going to need some text for our flashing banner. I'm going to keep the code as efficient as possible so it will be a good idea for each MESSAGE number to correspond to its respective OBJECT number.

i.e


  • OBJECT 0 (Standard Parsley ) MESSAGE 0

  • OBJECT 1 (Ultra Parsley) MESSAGE 1

  • OBJECT 2 (Standard Parsley ) MESSAGE 2

  • OBJECT 3 (Ultra Parsley) MESSAGE 3

So open up your TEXT MESSAGES file, make sure it starts with DEFINEMESSAGES and add your messages, I've added some spaces at the start of some of them as we are going to be printing them in the same place on the screen and I want them as centred as possible:





Next, were going to write a little code that will trigger our bonus routine. I'm going to use the variable B for the Bonus routine itself, and specifically the value 2 will be used to call the routine.


I'm going to trigger the Bonus routine when the Enemy is killed by a rebounded bullet. (So I could put this is the Bullet Sprite event or The Agent's event) In this case I've set it in the Agent's event and the Bullet sprite is a Type 2,

Next, we'll create the bonus routine itself, this will select a Random bonus drop based on our preferred weightings, you need to drop this into a MAIN LOOP script:



So now, when the player defeats the enemy there's a 90% chance they will be rewarded with a bonus object to collect. The bonus will appear at N,O (which was the X and y coordinates of the AGENT when he was neutralized.


Now, we'll add some code to the Player Event that will handle what happens when the player collects their bonus:




Ok, so that will handle the players reward when they collect the bonus, now we want to print a flashy banner to the screen for a bit of fun

Let's go back to the MAIN LOOP script and beneath our IF B=2 ...ENDIF lets add the banner code:


As you can see from the code above I'm using the variable C as a counter so that it flashes the banner 30 times. I chose this method rather than a REPEAT loop as I wanted the game to continue while the banner is active, rather than have to wait until the banner has finished before moving on.


And that's it in its simplest form.


Obviously, you can customise this to your hearts content. I use the banner routine for several other things during my games, but essentially, this is how I do it.


Hope this helps!





524 views0 comments

Recent Posts

See All

Comments


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

aboutME

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