March 29
From April 1: Scene display and walking system
If the 'message processing' is the core of the entire program! Then 'scene display and walking system' is the core of the entire game. Because as RPG games, all events have almost all related to scenes, such as: Different places will encounter different enemies, dialogue with different people, learn different things, can find treasures in specific locations, etc. All of this shows the important position in 'scene' in an RPG game. Given the importance of this part, we can divide it into: background display, walking and events, and handle their respective functions. Pay attention to this is a difficult point of RPG game production! The following is a specific analysis.
(1) Background display
Usually the scene of the RPG game is generated by puzzle (such as "Xianjian Qi Chuan Chuan", "Jin Yong Qun Xia Chuan", etc.), the advantage of puzzles is to save memory consumption, fast running and easy implementation of scroll operation. At the same time, it also reduces the workload of the art. This is especially important for me.
We use the computer screen as a puzzle, first set the screen resolution to 640x480x256 colors, then divide it with a 32x32 size, so that the entire screen is divided into 15 rows of small latches (shown in Figure 3) This is the stage we used to express the game.
After the stage is built, you can put we need the 'props', such as: trees, stones, houses, etc., all of them must be 32X32, such a plaid can put down a 'props'; but you I will definitely ask: Is there a big props? Of course, if it is too untrue, we use 32X32 as the smallest props unit, and a big props can take multiple plaids. Such as: a mountain size is 96x64, then you can place it with 3x2 grid. It should be noted that all props are long and wide must be an integer multiple of 32, which requires you to handle them in advance.
Remember that each item must have its unique number (such as tree = 100, stone = 101, house = 102, the number of the mountain is 200 ~ 205, because it accounts for 6 lattices). In this way, after the scene is arranged, our map data is naturally produced, as shown in Figure 4:
The above is the principle of the scene editor (I wrote a scene editor before the game production, used to generate the scene to be used in the game. Scene editor is included in the program: Mapedit.exe), editing with scene After designing the scene, there is a disk in order to call in the game. Note: The image of the props should be made in advance and stored in another graphic file. It is only the corresponding data to be stored here, not a real picture.
After you know the principle, it is very simple to generate a scene in the game. In fact, it is the inverse process of the scene, one is based on the scene generation, and the other is based on the data generation scenario. My algorithm is as follows: mappdata [20] [15]; // Map data generated by the Scene Editor, Picture Nums Nums Represents the Total number of props indicates the total number of props () // Generate Scene Function {INT N;
For (int i = 0; i <15; i ) / / total 15 line for (int J = 0; j <20; j ) // Total 20 column {n = mapdata [i] [j]; // get The props of this location BLT (j * 32, i * 32, Picture [n]); // This location (j * 32, i * 32) draws the props}} Everything is so simple, look at Figure 4 The game scene, is your mood very excited? I think you must be like me! However, I have been busy with busy first, and the content below will be more exciting.
(2) walking
The stage is built, and finally came to our protagonist (note! Light, play music ...), let the small flying knife freely walking freely in the scene, not a easy thing, calculate a total, Next, left, right four walking directions, 3 maps in each direction (standing, left leg, right leg), so do 12 pictures in advance, as follows: The background of the game must be set to transparent In this way, it will not cover the background color when drawing the characters (this technology is very easy to implement in DirectDraw, as long as the background color is set to ColorKey).
In fact, let the role move in the scene and not difficult, only to change his screen coordinates (Y), however, the general map is much larger than the screen, if only the screen coordinate is changed, the small flying knife is not Will you go outside the screen? So we have to make the lead position to move the scene. Have you noticed that Li Xiaoyao in the "Xianjian" is always in the middle of the screen? When he walks, the scene moves in the opposite direction. Yes, this is the effect of scrolling technology.
The map is a big picture, and the screen is the window we use to observe. Use our previous puzzle method to make it easy to implement rolling operation. Only a relative coordinate (SX, SY) is required, indicating the position of the upper left corner of the current screen relative to the top left corner of the entire map. Then, add this relative coordinate when generating a scene, look at the improved algorithm:
// Scene generation algorithm int W = 100, h = 80; // If the size of the map is 100 * 80 lattice mappdata [w] [h]; // Map data generated by the Scene Editor Picture [NUMS]; // Picture of the item NUMS indicates the total number of props
Void makebackground () // Generate a scene function {
INT N; for (int I = Sy; i how about it? Change is not big but it is very effective, which is also the charm of game programming! At this time, let the character move to redraw the background in the opposite direction, and the role has been kept in the middle of the screen, and the job that needs to be done is just based on the direction of walking and pace. Also note that the obstacles when walking are judged because there are some props to be unscrupulous, such as trees, houses, etc. So, when we walk, you should first calculate whether the next step will encounter obstacles, and cancel the movement if there is obstacle. In this program, it is to determine whether the data in the next lattice is 0 because 0 represents the ground. Ok, until now, a complete walking system is basically coming. Run, look at the RPG game you do, it feels not bad better than others! It seems that as long as you use your heart, you will have a good mood! (3) incident occurrence Don't forget, this part has a very important feature, that is, the incident happened. In fact, the principle is very simple, that is, put the numbers of the corresponding events in some plaids of the map, then when the protagonist step into this grid will trigger the corresponding event. E.g: When we set the game, the little flying knife was in his room. So if he wants to go out, you need to perform the scene to switch this processing function, but when should I do? This needs to trigger a certain event. We assume that the number of the event is 1000, then set the lattice value at the door to 1000 on the map. This doesn't matter whether the little flying knife moves in the room, and once he walked to the door, the number of scenes called 1000 will be triggered, so the small flying knife came to the house from the house. There are many similar events, stepped onto the trap, encounter the enemy, discover the treasure, etc., can be processed with the same method, and the different methods are only called. OK! The most difficult time is finally over, let us review the work of these days with a very relaxed mood! First, we built a game display system with a puzzle. Then, the movement of the role on the scene is achieved with scrolling technology. Finally, I understand the general principles of the incident. So far, we already have a RPG that can be actually running, really cut. But now she has just learned to walk, but also you need to use a lot of nutrients to water. This will make her grow rapidly and become more beautiful!