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, ShipEntity, AlienEntity 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),例如外星人實例。因此,似乎讓精靈作為一個單獨的對象更加符合邏輯。此外,我們不想浪費顯存,所以我們希望每一個精靈只加載一次。為了管理這一點,增加一個類來管理精靈的加載,并存儲起來供將來使用是一個非常不錯的主意。因此,我們在設計中加入了Sprite和SpriteStore兩個類。
學軟件開發,到蜂鳥科技!
超強的師資力量 、完善的課程體系 、超低的培訓價格 、真實的企業項目。
網址:www.ntcsoft.com
電話:0371-63839606
鄭州軟件開發興趣小組群:38236716
posted on 2010-11-25 23:29
whistler 閱讀(1014)
評論(0) 編輯 收藏