top of page
Writer's pictureBruce

Horizontal moving platforms in MPAGD

Updated: May 12, 2022

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:



Much nicer.


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!


697 views2 comments

Recent Posts

See All

2 Comments


sloanysoft
Aug 29, 2021

Once again this is a really impressive solution to something I want to implement in a game, I really hope you don't mind me using chunks of this code. It is very generous of you to share it like this.

Like
Bruce
Bruce
Aug 29, 2021
Replying to

Glad you found it useful. All the code on my blog is free to use and adapt in your own games.

Like

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