Out of the box, MPAGD includes a script for a vertical moving platform (Lifts/Elevators). It's fairly basic and wasn't what I was looking for, but with a bit of work I managed to get an effect I was happy enough to use in my first game, Cocoa and the Time Machine. I also wrote a script for that game for Crushers, blocks that would rise and fall that the player would need to dodge else suffer a crushing blow. I couldn't help notice the similarities in the code for the two events, so when I set about writing 24 Hour Parsley People I combined the two, so I could use the same script for a Lift and a Crusher, saving a few precious bytes in the process.
First let's take a look at the stock moving platform. In the video below the Yellow block is the standard MPAGD vertical moving platform (the cyan ones are my version...we'll come on to those later)
The standard version works well enough as a moving platform, the player can jump on and off it ok. When the Lift is going down it's not visually great...you can see the player sprite bouncing. Another thing that I wasn't keen on was the fact that the player can seemingly walk right through it, which never looks good - and wasn't going to be suitable for working as a Crusher. Also, the standard version will stop rising if the player is potentially going to get trapped at the top - again I wanted it to work slightly differently - for added danger I want the player to get hurt if he stays on the Lift (it's a Crusher Lift after all!)
Another effect I was keen to add was having the lift go upward slowly and then fall more quickly.
Here's a video running a simplified version of my code that we'll use for this tutorial:
If you notice (if you look at the Health value) the Crusher Lifts will inflict damage if the player gets crushed at the top and if a crusher falls on top of them.
And here's the code:
Also, we're going to need to put a few settings into the Sprite Initialisation script...
IF TYPE {WHATEVER THE NUMBER OF YOUR SPRITE EVENT IS}
LET SETTINGA = 0 ; the initial direction of the crusher/lift
LET SETTINGB = 0 ; the counter for waiting at the top/bottom
LET DIRECTION = 16 ; the number of cycles to wait
ENDIF
As you can see the main code is split into two parts, the first is what to do if the player collides with Crusher/Lift - either on top of it and hitching a ride, or getting crushed either at the top or the bottom, it also handles what to do if the player walks into the side of it.
The second part are the four main actions of the Crusher Lift, it's either going up, waiting at the top, falling, or waiting at the bottom.
I can't remember why I used SETTINGA for, effectively, the directions, and the the DIRECTION parameter as the number of cycles which controls the waiting time that SETTINGB increments to when the Crusher/Lift is at the top/bottom!...but if its not broke I'm not going to fix it!
There's a lot going on in this script but it's quite flexible and can give you two new features in one, obviously feel free to adapt it to the needs of your own games and environments.
Hope this helps!
Comments