
其中关于一个游戏“river pla.net”的类设计图我一定要介绍给大家,让大家明白一个游戏的构成,以及我们常说的游戏引擎(最基本的)究竟是如何构成的……
个人花了点时间把后面的变量与函数的说明给大家翻译了……
水平有限,大家凑合看吧
转载请说明来自:南开大学滨海学院“媒体实验室”或“Lynn的多媒体空间”
===================================================

《River Pla.NET》这个就是最终的游戏了,那么咱们就看看他是如何组成的(大家注意这个游戏的最终实现是用VB完成的,所以有些变量类型要注意一下)看图就知道了,这是个朴实的飞机游戏
类的结构图中包括的类的解释:
GameEngine:Direct3D游戏引擎类
RiverEngine:本游戏引擎类
Player:玩家类
Sprite:敌人类
GameMusic:游戏音乐类
Tile:区块类(不知道这样翻译对吗,所谓区块就是地图由许多小的重复的区块组成,用过RPG Maker都知道吧)
Font:字体类
GameSound:游戏音频类
GameMusic:游戏音乐类
Joystick:操纵杆控制类
Keyboard:键盘控制类
Mouse:鼠标控制类
这个就是结构图了,书上重的不清楚所以我新画的,具体里面的东东都是做什么的,我给大家翻译了,在后面了……(图要仔细看)
类的结构图:

具体的类中的变量与函数的解释:
GameEngine类(通用游戏引擎):
Table 4-1. Interface Members of the DirectX GameEngine Class |
||
TYPE |
NAME |
DESCRIPTION |
Property |
ObjDirect3DDevice |
The Device object, used by all graphical operations.设备对象,用于全部图形操作 |
Property |
BackgroundColor |
The color used when clearing the device. |
Property |
Width |
The width of the game field. |
Property |
Height |
The height of the game field. |
Property |
ScreenWinHandle |
The window handle used by all drawing functions. |
Property |
GameOver |
If true, the game is over. |
Property |
Paused |
If true, the game is paused. This flag and the preceding one store the current game status. Each game uses these flags to end or pause the game. |
Constant |
FVF_CustomVertex |
The constant that will define which flexible vertex |
Constants |
IMAGE_PATH and |
The relative paths where the images and the sound |
Method |
Initialize |
The procedure that will initialize Direct3D. |
Method |
Render |
The rendering procedure. This procedure will be an empty overrideable function that must be implemented in the derived classes. |
Method |
Finalize |
This method will dispose any objects created in the initialize procedure. |
Method |
Run |
This method will simply have a BeginScene-EndScene block inside a loop, allowing the game programmer to start the game by calling the Run method. |
现在接着给大家Sprite类与Player类,如果你仔细观察就会发现Sprite类(玩家类)比Player(玩家类)还要复杂,那让我们来看看究竟他的接口都有什么!
注意敌人的出现要与相应的区块关联。这一点很容易被忽略。还有玩家刚出生时是无敌状态也要注意!
Sprite类(敌人类):
Table 4-2. Interface Members for the DirectX Sprite Class |
||
TYPE |
NAME |
DESCRIPTION |
Properties |
X and Y |
The upper-left position of the sprite. |
Properties |
SizeX and SizeY |
The size of the sprite, in the x and y axes. |
Property |
IsTransparent |
If true, the Draw function will draw a transparent |
Property |
Direction |
The current direction the sprite is moving in. This |
Constant |
IMAGE_SIZE |
The default size for a square sprite. |
Property |
ScaleFactor |
Same as the GDI+ Sprite class, it holds a constant |
Properties |
SpeedX and SpeedY |
The speed (translation increment per frame) of the |
Properties |
TranslationX and |
The current translation value in each axis, from the |
Properties |
ScaleX and ScaleY |
The scale to be applied to the sprite in each axis. |
Properties |
RotationX and |
The rotation in each axis. |
Property |
SpriteImage |
The sprite texture, loaded from an image file. |
Property |
VertBuffer |
The vertex buffer with the vertices of the sprite. |
Method |
New |
Method for creating a new sprite. |
Method |
Load |
Method for loading the image file from disk; it |
Method |
Draw |
Method that draws the sprite. |
Method |
Dispose |
Method that disposes of the texture and the vertex |
Method |
CreateFlexVertex |
Helper method used when creating the sprite vertex |
Player类(玩家类):
Table 4-5. The Player Class |
||
TYPE |
NAME |
DESCRIPTION |
Property |
Status |
The current status for the player: flying, dying, or starting a new life |
Property |
Gas |
The fuel tank value by percentage |
Property |
DyingImage |
Image (image file loaded to create textures) to show when the player dies |
Property |
StartingImage |
Image to show when the player is in invincible mode (starting a new life) |
Property |
DyingSound |
Object that stores the sound to be played when the player dies |
Property |
StartingSound |
Object that stores the sound to be played when the player is in invincible mode (starting a new life) |
Property |
GameSound |
Object that will initialize the sound components and make them ready to play sounds |
Method |
New |
An overloaded method that will load all player images |
Method |
Draw |
An overloaded method that will draw the player image based on the current status |
下面的这个表格就是本游戏的引擎RiverEngine(本游戏的名称叫做River Pla.net),与GameEngine不同的时这个引擎是River pla也就是本游戏的引擎,它实现了游戏的一些一本的操纵以及初始化的工作。而GameEngine引擎是将DirectX建立起来,完成一些最底层的事 情,比如说屏幕的高宽声音图象的初始化(DirectX组件)……
这个类中比较主要的也是Render,注意也是一个继承了的方法!
RiverEngine class本游戏引擎类:
Table 4-6. The RiverEngine class |
||
PROPERTY |
NAME |
DESCRIPTION |
Property |
Lifes |
Specifies the number of lives of the player. |
Property |
GameSpeed |
Indicates the scrolling speed of the game. |
Property |
Tiles |
Represents an array with all the tiles of the game. |
Property |
CurrentLineNumber |
Specifies the number of the current line at the bottom of the screen. This property is used to control the tiles we should draw. |
Property |
Player |
Indicates an object of the Player class. |
Property |
GasSound |
Indicates an object of the GameSound class, which will be played when the player passes over a gas barrel. |
Property |
BackgroundMusic |
Indicates an object of the GameMusic class, which will play the game’s background music. |
Method |
Initialize |
Calls the Initialize method of the base class, loads |
Method |
LoadGameMap |
Loads the game map text file and populates the Tiles |
Method |
Render |
Overrides the Render empty method from the base class, and will be called in the game loop (on the Run base class method). All the drawing functions, physics tests, and sound-playing functions should be called from here. |
Method |
Scroll |
Scrolls the game field by calculating the game world translation matrix. |
Method |
Draw |
Draws the visible tiles of the game field, based on the |
Method |
MovePlayer |
Moves and draws the player, based on the input received from the keyboard. |
Method |
TestCollisions |
Tests the collision of the player against the obstacles of the game field. |
Method |
PlayMotifs |
Plays the random motifs over the background music to add a little variance to it. |
Tile类,区块类:
Table 4-4. The Tile Class |
||
TYPE |
NAME |
DESCRIPTION |
Property |
Type |
A member of an internal enumeration that should store the type of the tile (land, water, enemies, etc.) |
Method |
New |
An overloaded method for each New method of the Sprite class that simply adds an extra parameter for the Type property |
这里我要提几句,区块是由许多小的矩形的位图组成的,然后把每一个区块给一个编号(例如用"T"表示树,用"."表示陆地……),再在外部的文件中用标号画一个地图,然后游戏就可以自动读取这些地图,把他们转变为一幅完整的地图了。这样扩展性很好。
翻译很辛苦,累了,剩下的改天贴出来!
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}