Random Terrain asked me to make a tutorial series on how to make a game scroll like Princess Rescue. Let me begin by saying it's not as hard as you think. I've heard that some people have had a hard time doing it while still having cpu time to play with. Yes, horizontal screen scrolling can eat up those precious cpu clocks, but if you are making a simple game, you may still be able to do it all within one screen draw. Princess Rescue on the other hand, required 3 screen draws per full game cycle, where as Zippy took only 2 (I refined the method a little). I will be using the Princess Rescue method for the example for simplification reasons, so you can learn and you can take what you learn and build upon it if you'd like. So let's start with this before we even start programming. Let's make a level first!
Before we can make a level, we need to know how it's constructed.
At the standard kernel, standard resolution, you have a 32x11 playfield block screen. That is 32 across and 11 down.
Let's say going across the screen is a row and going from top to bottom is a column. Each column will take 2 bytes of data because it's going to require 11 bits for the 11 playfield blocks you can have in a column. Since we're going to have the ability to scroll in either direction, we will need to use the regular Data statement for the data table. With this, you can use a variable pointer to read data at any point in the level. However, this will limit how much data you can have in one table to 256 bytes, meaning that our level can only be 128 playfield blocks wide, or 4 screens wide. To kind of get around this limitation, I added the feature of going down a pipe at the end of the first half of a level, which sends you to the 2nd half of the level, contained in its own 256 byte table, making each level 512 bytes in total.
With this in mind, we are going to design our level in 128 characters across, and you can do this in a TEXT EDITOR!
This is how I designed all of my Princess Rescue levels. I used good old fashioned EDIT.COM, however you can use any text editor that saves out a plain Jane text file. Keep in mind that the dimensions of whatever text editor you use, won't look like what will be in your game and will look really stretched out. An X represents a playfield block and a . (period) represents no block. Your text file will be 128x12 characters. What's with the 12th row you ask? The bottom 12th row is your spawn in data. Remember, each column is 11 bits for playfield blocks, meaning we have 5 bits leftover for other things, like information on what item will be scrolled in, using the player 2 sprite. That 12th row will contain rather a . (period) for nothing will spawn there when scrolled in, or a value from 0-F that your program will take and do what it needs with it.
Included in this post is a ZIP file that contains the program I wrote in QB64 called TXT2LEV that will take your text file data and convert it into a DAT file that you can open in, let's say Notepad, and then copy and paste the data into a data table in your code. It's a simple program. When you run it, it will ask for the filename of the file you want to convert. Just put the filename MINUS the txt extensions, so for example, level1.txt, you would just type in level1. It will immediately convert and then ask if you want to do another. Since we're doing just 1 level, press N. Be sure all these files are in the same folder! When you unzip this file, just make a new directory somewhere on your hard drive, and put everything there, including your levels that you create.
Also included is the 2nd half of the first level of Princess Rescue, so you can see how I did it. You'll notice for the spawn data, I used a long series of the same number/letter. This is because you can only scroll on one thing at a time, and if something else was on the screen it wouldn't scroll it on. So, to remedy this I made the spawn points consecutive to almost insure that one will eventually scroll on. Your Batari BASIC program will determine how high or low it will show up in the column, so you don't need to worry about that right now. Have fun making your level. The next lesson we'll talk about taking your data file that you created, put it in your program, and then writing up some code to interact with it.
TXT2LEV.zip 2.99MB 17 downloads
Click below for the next lesson!
Edited by Sprybug, Thu Feb 7, 2019 2:46 AM.