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...
Player has defeated an enemy
Randomly drop a bonus item (selected from 4 potential bonuses, weighted so that more powerful bonuses drop more rarely)
Player collects bonus item
Bonus item awards energy/points/whatever
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.
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!