This came out of an MPAGD forum request, and as I had already created the mechanic in Cocoa and the Time Machine and expanded/improved it in 24 Hour Parsley People, it wasn't too difficult to create a simplified version that you can use as a building block and then adapt and expand for your MPAGD games.
Our objective is to create a Crate that the player can push left and right, and jump on to reach higher platforms.
In addition we will make it subject to gravity, such that if the player pushes it off a platform it will drop to the platform beneath.
There is a stock Pushable Sprite script in standard MPAGD, but its not really suitable for a 2D platform game, originally I used it as a starting point but in the end I rewrote it and stripped it back (I was trying to save as many bytes as possible!.
So, here's what you should end up with...
OK, so the first thing were going to need is a couple of variables that will store the X an Y co-ords of the Player, in my demo I am using V & W, so in your player script add the following lines:
LET V = X
LET W = Y
Now create an event for your crate, this is where all the work will take place, and add the following code (not substitute V & W if you already have other variable for your Player's X & Y values)
This is a much simplified version of what I used within my games, but is the core mechanic, obviously you can adapt it for your game. Things you can expand it with include:
What should happen if an enemy collides with a crate?
What should happen if a crate is pushed onto an enemy? (maybe squash them against the wall!)
What happens if a crate is pushed onto another crate (in Cocoa 2: 24 Hour Parsley People I have crates that can be stacked on top of each other)
Hopefully this building block mechanic will help you with your own game development and give you some idea for creating new, unique mechanics!
*UPDATE: I've changed the code above so that it now uses the UNDOSPRITEMOVE command rather than adding and subtracting from the Players X when a push fails, I think this is a better use of MPAGDs scripting language
Kommentare