In the first tutorial, I showed you how I kept my player actor locked in to the camera on a vertical auto-scrolling scene. Now, as useful as that is, it doesn't really cover the whole topic of how to keep your actors from going off screen. When you break it down, there are a ton of reasons why keeping your actors on screen is useful, but what is even more useful is being able to customize that feature to fit any type of game play or scenario.
In part two of how to keep your actors from going off screen, I will teach you how to customize the blocks I gave you in the first tutorial to fit other types of game play, such as a platformer where you want your character to be able to fall through the bottom. I will also show you how to customize this even further to add Mario style effects for fall through's, etc.
Let's get started:
Platform Games
In a typical platform game, you want to be able to move left or right freely, except in the case of the far left and right borders of the scene. Most likely, you also want your actor to not shoot in to space, but you do want them to be able to fall into holes and traps.
To accomplish this, we would first set blocks of code in place that prevent our player actor from moving beyond zero pixels to the left, and greater than our highest pixel to the right on the X axis (horizontal).
Note: The exact numbers in this block of code may not be right for you. As this is just an example script I am using a standard scene size of 20 x 15 at 32 pixels per tile. You may need to adjust your numbers slightly to get the right performance for your game.
This prevents us from running backwards through the screen at the beginning of the level, as well as running straight through the end of the scene at the end of the level. Now, all we need to do is set a Y parameter for the top of the screen, and a death event that will occur when he falls off of a platform into the abyss.
This block of code prevents us from moving above the scene boundaries at the top of the screen. Quick tip: Optionally, if you wanted to create a scenario where you could move above the screen, like in the instance of Super Mario with his trusty Flying P, you could create the scene a tile or two larger on the Y axis, and then set your boundaries at the actual scene height. Now, if you use a camera actor like in my last tutorial, you will see that the screen is exactly the same but there is added space above the cameras view point that you can use to set up secret areas, etc.
Now, we move on to the death event. In just about 100% of classic platform games, if you fall off the platforms into an empty space in the scene, you die. This is how I would accomplish this:
One thing to note about the above block, is that it is very basic, and not aesthetically please. Basically, in a nut shell, all this does is, if you player actor falls into a hole, it deletes him from memory. Spruce yours up with a little eye candy. When your character falls, make your block change to a special animation just for falling deaths. Also add a sound effect to it that you would use for any other kind of death event for your player actor. Now, make your block of code fade out of the scene and return to a start screen, or even better, a "Try Again?" screen.
Other Game Types
In just about any game type you will find reasons for some level of customization of the screens boundaries at some point or another. In general, if you want to be able to leave the screen on one side, just don't set a boundary for that side. Or, for instance, say you want to have one scene run into another. Simply set the boundary of the scene to move you to the corresponding X or Y position on the next scene.
There are a lot you can do with screen boundaries to enhance the flow of game play over just about any and every genre of game that there is. Play around with your code blocks a little and see what you can come up with. And, as always, if you have any questions feel free to drop a comment here, and I assure you, I will respond as promptly as possible. Until next time, Cheers!
No comments:
Post a Comment