【译】完整游戏是如何组成的!

      动画,游戏 2006-12-2 15:35
昨天在看《.NET Game Programming with DirectX 9.0》这本书时其中的第四章的内容深深的吸引了我,所以这一章一口气都看完了。接着我决定要分享给大家……





其中关于一个游戏“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.


如果为”true”游戏结束

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


format we’ll be using when creating the device and the vertices of the sprites.


这个常量将灵活的定义顶点格式,我们使用它创建设备与怪物的顶点

Constants

IMAGE_PATH and


SOUND_PATH

The relative paths where the images and the sound


files are stored.


存储图象与声音文件的相对路径

Method

Initialize

The procedure that will initialize Direct3D.


这个函数将初始化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.


这个函数将简单的在一个循环中包括一个开始场景与结束场景,它允许游戏程序师调用Run这个函数开始游戏



现在接着给大家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.

在x与y轴上怪物的尺寸

Property

IsTransparent

If true, the Draw function will draw a transparent

sprite, loaded in the Load function. We don’t need to store a color key property to say which color will be transparent; such a color is used only when loading the textures.

为“true”则绘制函数将绘制一个透明的怪物,在函数“Load”中读取。我们不需要存储一个颜色的属性,也就是说颜色将透明;当读取材质时这样的颜色是最合适的

Property

Direction

The current direction the sprite is moving in. This

property can be used to choose which image must

be drawn.

移动进来的怪物的当前位置。这个属性通常决定图象是否要被绘制出来

Constant

IMAGE_SIZE

The default size for a square sprite.

一个正方形怪物的默认尺寸

Property

ScaleFactor

Same as the GDI+ Sprite class, it holds a constant

used when creating the sprite, indicating whether

the x and y values are pixel values or based on

IMAGE_SIZE. Useful for creating tiled game fields.

所谓的GDI+怪物类,当创建一个怪物它掌握着一个常数的使用,标志着x和y值是像素值还是基于IMAGE_SIZE。这有助于创建平铺游戏的区域。

Properties

SpeedX and SpeedY

The speed (translation increment per frame) of the

sprite on the x and y axes.

怪物在x与y轴的速度(每帧的平移增量)

Properties

TranslationX and

TranslationY

The current translation value in each axis, from the

initial x,y position.

从初始的x,y位置开始到当前各个轴上的平移量

Properties

ScaleX and ScaleY

The scale to be applied to the sprite in each axis.

怪物的比例在每个轴上

Properties

RotationX and

RotationY

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

creates the vertices used to draw the image on the

screen.

从磁盘中读取图象文件;它的创建常用于在屏幕上绘制顶点集

Method

Draw

Method that draws the sprite.

绘制怪物的函数

Method

Dispose

Method that disposes of the texture and the vertex

buffer used by the sprite.

销毁被怪物使用的材质贴图与顶点缓冲

Method

CreateFlexVertex

Helper method used when creating the sprite vertex

buffer.

创建怪物顶点缓冲的辅助函数



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

当前的玩家状态:flying,dying或是开始新生命

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.


声明Player类的对象

Property

GasSound

Indicates an object of the GameSound class, which will be played when the player passes over a gas barrel.


声明GameSound类的对象,当玩家忽略油箱时播放

Property

BackgroundMusic

Indicates an object of the GameMusic class, which will play the game’s background music.


声明一个GameMusic类的对象,播放背景音乐

Method

Initialize

Calls the Initialize method of the base class, loads


the game map, and creates all game objects (Player,


GasSound, and BackgroundMusic).


调用基类的声明函数,读取游戏地图,和创建全部游戏对象(Player,GasSound,和BackgroundMusic)

Method

LoadGameMap

Loads the game map text file and populates the Tiles


array.


读取游戏地图文本文件和组织区块排列

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.


从基类继承Render的空函数,读取游戏循环(在运行基类函数时)。全部的绘制功能,物理测试,和播放声音的功能将从这里被读取

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


CurrentLineNumber property and the Height of the


screen.


绘制显示的游戏区块,基于CurrentLineNumber变量和屏幕的Height实现

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.)


一个枚举类型存储着区块的类型(land,water,enemies,等等)

Method

New

An overloaded method for each New method of the Sprite class that simply adds an extra parameter for the Type property


每一个怪物类的“New”函数调用的一个重载函数,简单的添加一个额外的参数给“Type”变量


这里我要提几句,区块是由许多小的矩形的位图组成的,然后把每一个区块给一个编号(例如用"T"表示树,用"."表示陆地……),再在外部的文件中用标号画一个地图,然后游戏就可以自动读取这些地图,把他们转变为一幅完整的地图了。这样扩展性很好。


翻译很辛苦,累了,剩下的改天贴出来!
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}


注册5D通行证,立刻拥有自己的博客Join 5D!发表留言

用户Name:  密码Password: 匿名Guest
内容Comment: 
加粗 下划线 文本颜色 居中 插入链接 建立Google搜索链接 插入图片 引用文本
 
汗 喜欢 骄傲的笑 哭 酷! 愤怒 黑线 什么? 猥琐 偷笑 无语 晕 吃惊 诱惑
smile frown redface biggrin wink rolleyes mad eek 禁止笑脸转换 No smiley
zoom inzoom out
验证Verify: checkcode 换一个change the code