posts - 0,  comments - 6,  trackbacks - 0

Space Invaders (太空侵略者)java 2D 游戏开发指南系列文章来自 Coke and Code ,主要包括下面四篇:

 

我现在翻译的是 Space Invaders 101  第一部分 简介 (整篇文档和源代码请点击下载

通过 Space Invaders 太空侵略者 系列译文,我们将学习类似于经典小游戏“小蜜蜂”的 2D Java游戏如何一步一步开发出来。游戏效果如图:

 
图片


Introduction

简介


This tutorial hopes to give the reader a simple introduction to the world of 2D games using Java. We're going to cover the following areas at a fairly simplistic level:


译:本指南希望能给读者一个使用Java开发2D 游戏的简单介绍。文章将在相当简单的水平上涵盖以下领域:


· Accelerated Mode Graphics 图形加速模式

· Simple game loops 简单游戏循环

· Keyboard Input 键盘输入

· Brute force collision detection强力碰撞检测


The final game can be see here. The complete source for the tutorial can be found here. Its intended that you read through this tutorial with the source code at your side. The tutorial isn't going to cover every line of code but should give you enough to fully understand how it works.


译:你可以点击这里下载游戏的可运行版本。点击这里下载本文的完整源代码。请在阅读本文前下载好完整的源代码,以便在阅读本文过程中随时参考。本文在介绍某一主题时仅包括足以让你理解该主题编程思路的主要代码片段。


Context highlighted source is also available here:

译:你也可以通过下面高亮显示的源程序连接下载源程序:
Game.java
SpriteStore.java
Sprite.java
Entity.java
ShipEntity.java
ShotEntity.java
AlienEntity.java


Disclaimer: This tutorial is provided as is. I don't guarantee that the provided source is perfect or that that it provides best practices.

译:免责声明:我不保证本教程提供的源代码是完美的或是最佳的实现。


Design

译:设计思路


Before starting any game its always a good idea to work out what's going to be in the game and how you're going to build your classes around that. You don't need to read this section unless you're interested in why the source is written the way it is.


译:在开始设计任何游戏之前,明确我们的游戏有什么内容,以及围绕游戏内容如何构建类是一个好主意。除非你对源程序为什么要这样写感兴趣,否则你不需要阅读本章节。


For our space invaders game we're going to have a main window. The window needs to use acceleated graphics. It also needs to respond to the player's key presses to move our player's ship around. For now we can call this class Game since it represents our main game.


译:我们的太空侵略者游戏将有一个主窗口。该窗口需要图形加速,也必须能够根据玩家的键盘操作来控制飞船的移动。我们给这个窗口类起个名字叫“Game”,因为他是游戏的核心部分。


In that window we want to see some things moving around. The player's ship, the aliens and the shots that the players fire. Since all of these things have common properites (i.e. they display a graphic and move around the screen) we can infer a common class to represent each one with potentially subclasses to define the specific behaviours of these different types. Since "thing" is such a terrible name for a class, for our design I'm going to call them Entities. From this we get 4 classes. Entity with 3 subclasses, ShipEntityAlienEntity and ShotEntity


译:在“Game”窗口中,我们想看见玩家的战船、外星人和玩家射出的子弹这些“东西”在屏幕中飞来飞去。因为“东西”对一个类来说是如此糟糕的一个名字,所以我们准备叫他们实体。因为所有的这些实体都拥有一些共同的特征(都用图形来表示,并能够在屏幕上来回移动),所以我们可以设计一个公共父类抽象描述所有可能的子类型,在不同类型实体的子类中定义具体行为。于是我们得到4个类,一个公共父类和三个实体子类,战船实体,外星人实体和子弹实体。


Finally for each Entity we have we'd like to have an image displayed, using an old term, a Sprite. However, we might use the same Sprite for multiple entities, for instance the aliens. It seems logically therefore to keep the sprite as a seperate object from the entity. In addition we don't want to waste graphics memory so we'd like to only load each sprite once. To manage this it'd be nice to add a class to manage loading of the Sprites and storing them for future use. So we add a pair of classes to our design, Sprite and SpriteStore.


译:最后,对于每一个实体,我们用一个图片来展示,并且用一个老术语“精灵(Sprite)”来称呼。但是,多个实体对象可能会是同一种精灵(Sprite,例如外星人实例因此,似乎精灵作为一个单独的对象更加符合逻辑此外,我们不想浪费显存,所以我们希望每一个精灵只加载一次。为了管理这一点,增加一个管理精灵的加载,并存储起来供将来使用是一个非常不错的主意。因此,我们在设计中加入了SpriteSpriteStore两个类。

学软件开发,到蜂鸟科技!
超强的师资力量 、完善的课程体系 、超低的培训价格 、真实的企业项目。

网址:www.ntcsoft.com 
电话:0371-63839606 
郑州软件开发兴趣小组群:38236716

posted on 2010-11-25 23:29 whistler 阅读(953) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

留言簿(2)

我参与的团队

文章档案(22)

搜索

  •  

最新评论