Design Principles of the Role Playing Game Engine

Source: Internet
Author: User
Tags transparent image

Original link http://www.chinadogame.com.cn/201103/95392986330.html

A role-playing game (RPG) is a favorite of many game fans. It attracts countless players with unique interactions and stories. It provides people with a vast virtual world beyond real life, so that they can try to assume different roles to experience and experience different life journeys or fantasy experiences. These experiences cannot be realized in real life. After playing many games, many players no longer simply satisfy the identity of a game player. Instead, they will think about how the game is made and plan to make their own game, various online game production groups have sprung up. Next, I will introduce the principles and production of the role-playing game engine, hoping to help the game makers.

Principle of a game engine

When it comes to engines, game fans are familiar with them. The game engine is designed to be recognized by machines that run certain types of games.Code(Command) set. It is like an engine that controls the running of games. A game can be divided into two parts: Game Engine and game resources. Game resources include images, sounds, and animations. A formula is as follows: Game = engine (ProgramCode) + resources (images, sound, animation, etc ). The game engine calls these resources in the order required by the game design.

Create a role-playing game

The production of a complete role-playing game can be divided into planning, program design, artist, music production, project management, and subsequent testing.
The main task of planning is to design the game plot, type, and mode, and analyze the complexity, content, and progress of the game.
The task of programming is to use someProgramming LanguageTo complete the game design and cooperate with the planning to achieve the expected purpose.
The artist mainly designs game scenarios and images of various roles based on the game's background and themes.
Music production is to make the game's music and sound effects based on the game's plot and background.
Project management mainly controls the game production process and makes full use of the existing resources (personnel, funds, equipment, etc.) to achieve the maximum benefit with the amount of money used up.
Tests in the future are also very important. For a game that has dozens of people who have spent several months or even years of preparation, many problems can be found during the tests, only improved programs can ensure the secure release of the game.

BecauseArticleThis article mainly explains how to create a game program. For details about the planning, artist, and music production, please refer to other articles. Next I will talk about the design of the game program.

(1) development tools and main technologies

1. Development Tools

There are many game program development tools and different development tools on different game platforms. On personal computers, you can use streaming software development tools such as C, C ++, VC ++, Delphi, and C ++ builder. Thanks to the popularity of Windows operating systems and their powerful multimedia functions, more and more games support Windows operating systems. As VC is a Microsoft product, it is used to compile Windows programs with powerful program interfaces and rich development resources. In addition, VC's rigorous memory management, with good distribution processing on the stack, the size of generated code is small and the stability is high. Therefore, VC ++ has become the mainstream development tool for games.

2. DirectX component knowledge

Speaking of Game Development in windows, let's talk about Microsoft's DirectX SDK.

A major advantage of Windows is the independence between applications and devices. However, the device independence of applications is achieved by sacrificing partial speed and efficiency. Windows adds an intermediate abstraction layer between hardware and software, through these intermediate layers, our applications can be easily used on different hardware. However, we cannot fully utilize the features of hardware to obtain the maximum computing and display speed. This is fatal when writing windows games. DirectX is designed to solve this problem. DirectX is composed of a fast underlying library and does not add too many constraints to the game design. Microsoft's DirectX software development kit (SDK) provides a set of excellent application programming interfaces (APIS ), this programming interface provides you with various resources required to develop high-quality, real-time applications.

The six components of DirectX are:

DirectDraw: uses the page switching method to implement animation. It can not only access the system memory, but also access the Display memory.
Direct3d: Provides 3D hardware interfaces.
Directsound: stereo and 3D sound effects, while managing the memory of the sound card.
Directplay: supports the development of multiplayer online games and can handle communication problems between networks in games.
Directinput: Provides input support for a large number of devices.
Directsetup: automatically installs the DirectX driver.

As the DirectX version improves, directmusic for music playing is also added.

3. alphablend Technology 

Nowadays, many games adopt alphablend technology to achieve transparent effects of light and shade or images. The so-called alphablend technology is actually to mix the source and target pixels according to the value of the "Alpha" hybrid vector, which is generally used to deal with translucent effects. Images in the computer can be represented by three primary colors: R (red), g (green), and B (blue. Assume that one image is a, and the other transparent image is B. Then, through B, the image C looks like a hybrid image of B and, set the transparency of Image B to alpha (values 0-1 and 0 to completely transparent, and 1 to completely opaque). The Alpha mixing formula is as follows:

R (c) = Alpha * R (B) + (1-alpha) * R ()

G (c) = Alpha * g (B) + (1-alpha) * g ()

B (c) = Alpha * B (B) + (1-alpha) * B ()

R (x), g (x), and B (X) indicate the primary colors of the RGB component. As you can see from the above formula, Alpha is actually a value that determines the transparency of the mixture. Using Alpha hybrid technology, you can achieve many special effects in the game, such as fire, smoke, shadow, dynamic light source, and other translucent effects.

4. *Algorithm

In many games, you need to use the mouse to control the movement of characters, and the shortest path should be taken to move the character from the current position to the target position. This requires the use of the shortest path search algorithm (A * algorithm.

A * the algorithm is actually a heuristic search. The so-called heuristic search is to use an evaluation function to evaluate the value of each decision and decide which method to first try. If an estimate function can find the shortest path, we call it adoption. A * algorithm is the best priority algorithm that can be adopted. The evaluation function of a * algorithm can be expressed:

F (n) = g (n) + H (N)

Here, F (n) is the estimated function of node N, g (n) is the shortest path value from the start point to the end point, H (N) it is the inspiration value from N to the target's most Broken Circuit. Due to the complexity of the * algorithm, I would like to give a brief introduction here. For more information about the theory, I would like to read a book on artificial intelligence.

Other technologies include particle systems, audio and video calls, formats of image files, and information storage. You can learn more technologies on the basis of DirectX learning.

(2) specific game production

1. Create a map editor

RPG games often have a large number of scenarios, where lawns, lakes, trees, houses, furniture, and so on are available as needed. As a game requires many scenarios and the map is growing, in order to save space and improve the reusability of image files, RPG games use a lot of repetitive units (which can be called "blocks"), which requires the map editor. Before creating a game engine, we need to complete the creation of a map editor. In RPG games, scenes are recorded in the order of block arrangement. First, create a format for the scenario composition file. In this file, record the order of the graph blocks required for the scenario, because we have created an index for each graph block, therefore, you only need to record these indexes. The composition of a scene is divided into several layers: the ground, buildings and plants, furniture, and the characters or objects (such as flags) active in the scene ), they are displayed on the screen in sequence to form a multi-sampling scenario. We can use arrays to represent the process of generating map scenarios.

 

Mapdata [x] [Y]; // Map Data. X indicates the map width, and y indicates the map height.

Picture [num]; // Item image. Num indicates the total number of items.

Void Makebackground () // Generate scenario Functions
{

IntN;

For ( Int I = 0 ; I < Y; I ++ ) // Y rows in total
{
For ( Int J = 0 ; J < X; j ++ ) // X columns in total
{
N = Mapdata [I] [J]; // Get the item number for this location

Draw (J * 32 , I * 32 , Picture [N]); // Draw items in this position (J * 32, I * 32)
}
}
}

2. Division of game modules

The game is divided into three main parts by function: Message Processing System, scenario display and walking system, and fighting system. The message processing system is the core module, and the rest is closely centered around it.

I. Message Processing System

The message processing system is the core part of the game. The message processing system used by the game waits for the message, and then forwards the message to the corresponding function for processing. For example, when the protagonist encounters an enemy, the program will generate a 'fighting message'. After receiving the message, the message processing system will immediately switch to the fighting module. The general framework of message processing is as follows:

// Define the variables to be used in the program

DWORD message; // Message variable

Winmain () // Enter the program
{
Initialize the main window;

Initialize the DirectDraw environment and call the graphic and map data required by the program;

while ( 1 ) // message loop
{< br> Switch (Message)
{< br> case walking message:
walking module ();
case fighting message:
fighting module ();
case event message:
event module ();
}< BR >}

Ii. Scene display and Walking System

As an RPG Game, the occurrence of all events is almost related to the scene. For example, different places may encounter different enemies, and different people may talk about different things. In view of the importance of this part, we can further divide it into three submodules: Background display, walking, and event occurrence to process their respective functions. The following is a detailed analysis.

(1) Background display

After the program runs, read the Order of the graph blocks required for the scenario created by the preceding map editor, and splice the images into a complete scenario in the order of arrangement. The general practice is: one or two screen cache zones are opened in the memory, and the image data to be displayed is prepared in the cache zone in advance, and then moved to the real screen buffer zone at one time.

The images used by the game are prepared and stored in other graphics files in advance. The scenario File Created by the map editor is only the corresponding data, not the real image. In the game, scenario generation is the inverse process of map editing. One is to generate data based on the scenario, and the other is to generate a scenario based on the data.

(2) walking

To let the main character walk in the scene, at least four walking directions: top, bottom, left, and right. Each Direction has four pictures (standing, walking left leg, walking right leg, and walking left leg ), in the game, you must set the background of the image to transparent, so that the background color will not be overwritten when you draw the character (this technology in DirectDraw only needs to use setcolorkey () the function filters out the background color of the original image ). We move the main character without moving the scene, that is, the scrolling technology is used to move the role scene. In this way, the role is always in the middle of the screen, and the work to be done is to change the picture continuously according to the walking direction and pace. Obstacle judgment during walking is also a must in every scenario. Some items such as trees and houses cannot be crossed. In this regard, I mainly use a two-dimensional array to correspond to a scenario. Each array value represents a small cell of the scenario (see figure 3 ). Where there is an obstacle, the corresponding value of this array is 1, and the value of the allowed place is 0.

 

(3) event occurrence

When an event occurs, the sequence number of the event is stored in some grids of the map. When the protagonist step into this lattice, the corresponding event is triggered. For example, at the beginning of the game, the main character is at his home. If he wants to go out, he needs to execute the scenario to switch the processing function. Assume that the event number is 001, set the grid value at the intersection of the home gate to 001 on the map. In this way, when the main character arrives at the intersection, the scenario switching function numbered 001 will be triggered, so the main character will be in the next scenario. The procedure is as follows:

Void Messageloop ( Int MSG) // Message Loop
{
Char Addressname [ 16 ]; // Array addressname [16] is used to store the name of the location where the main character is located.

Switch (MSG)
{
Case Address =   001 : // The scene value is determined by the address value)
Screenx = 12 ; Screeny = 0 ; // Initialize the game background location
Hero. x = 360 ; Hero. Y = 80 ; // Protagonist coordinates

Move (); // Main Character mobile Function

//The following program is used to display the location of the main character

Sprintf (addressname,"Name of the next game scenario");

Printtext (lpddsprimary,280,330, Addressname, RGB (255,255,255));//Display the name of the scene on the screen

Break;
}
}

Iii. Combat System

The vast majority of RPG games have battles. Therefore, the fight system has become an important part of the RPG system. Many RPG games adopt the turn-based combat mode because it is easy to implement. Upgrading is closely related to fighting. After a battle ends, the experience of the main character increases. When the experience value reaches a certain level, the role is upgraded.

I briefly introduced how to create a role-playing game. As this article aims to give readers a basic understanding of the creation of a role-playing game, readers and friends can study the relevant information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.