Horizontal moving platforms in MPAGD
Updated: May 12
Platforms that move are a staple of most platform games, a genre that MPAGD is ideally suited for coding smooth 8 bit retro games. However the tool does not come with an 'off the shelf' script for horizontally moving platforms.
This is something I tried to tackle in my first game, Cocoa and the Time Machine. First, I had in mind an idea of how I wanted them to work. I had seen some attempts in other AGD games that were close, but not quite what I wanted. Predominantly these required the player to press the direction key to remain on the platform, so if the platform were moving right...the player needs to press the right key to remain on it.
But that's not what I wanted. I wanted the player to land on the platform and transported automatically, but also be able to move left and right on top of the platform to adjust their position, and jump on and off.
After many, many attempts, I got an effect that worked, although was not visually as good as it could have been, in Cocoa and the Time Machine
As you can see, Cocoa can walk or jump onto and off the platform, he can also adjust his position on the platform. The problem is more the aesthetics...the Cocoa sprite is, well, a bit jerky.
The code for this involved using a few variables so that I could tell whether the player was currently on the platform or not, and the platforms current direction of travel and so on.
In 24 Hour Parsley People I set out to improve this....and here's the new code applied to the original game:
So here's how its done.
First in the Event for the platform sprite:
OK, so that will control how the platform will operate, check if the player is on the platform, if so keep them there and move them, but still allow them to adjust their position.
Now we're going to need some code for the player event:
Note that in the above code I am also checking ahead to see if the platform is going to hit a wall block, this is useful for keeping the player moving in the correct direction when the platform itself changes direction...the lag between the two events also has an accidental benefit of simulating inertia as the player changes direction which you can see in the video above...bonus!
This code, also lends itself nicely to putting obstacles in the way that the player has to jump over like these ones in 24 Hour Parsley People...
I'm sure people far cleverer than me will be able to improve these, I'm just pleased that I've been able to improve them from my first game to my second :)
I also used this in the third episode of 24 Parsley People, but in a slightly different way. This time I used my Pushables code (I'll blog about that another day) but when a certain pushable item gets pushed into water it becomes a horizontal moving platform....here's what I mean...
This would have been better if I hadn't run out of memory, as I had another frame for the log so that you see it side on when it is floating in the water...ah well, such is 8bit code in 39K of available memory :)
Hope this helps!