此篇文章主要介绍使用Java语言进行游戏编程,并不是介绍Java语法特性的书籍。
01. 源码下载地址
https://pan.baidu.com/s/1o8e5HTS
书本下载地址
https://pan.baidu.com/s/1geRSLLh
02. 确定Java环境是否正确:
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
Ubuntu下下载解压,
vim ~/.bashrc
增加java javac的路径到全局变量PATH中
#export JAVA_HOME=/home/wang/Downloads/jdk1.7.0_79
#export JAVA_HOME=/home/wang/Downloads/jdk1.6.0_45
export PATH=${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH
export CLASSPATH=.:$CLASSPATH:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib
source ~/.bashrc 使配置生效
03. 运行代码
可以在命令行中直接编译运行,不需要IDE工具。
解压之后生成的目录,在Fundamental-2D-Game-Programming-With-Java/CH01/src下执行
javac javagames/render/DisplayModeExample.java
记得目录不要多也不要少,因为文件中有import 到package目录,如果目录不正确javac就会找不到相应的类。
执行
java javagames.render.DisplayModeExample
运行结果
再次强调这不是一本教Java语法的书,如果需要学习Java语法,请参考Core Java上下册,或者其它书籍。
该程序可以选择屏幕的尺寸,然后按第二个按钮进入相应大小的界面。
(04)目录
Introduction
Part I The Foundations
Chapter 1 Hello World
1.1 Using the FrameRate Class
1.2 Creating the Hello World Application
1.3 Creating a Custom Rendering Thread
1.4 Creating an Active Rendered Window
1.5 Changing the Display Mode
1.6 Active Rendering in Full-Screen Display Mode
Resources and Further Reading
Chapter 2 Input
2.1 Handing Keyboard Input
2.2 Keyboard Improvement
2.3 Handing Mouse Input
2.4 Relative Mouse Movement
Resources and Further Reading
Chapter 3 Transformations
3.1 Using the Vector2f Class
3.2 Using Polar Coordinates
3.3 Understanding Points and Vectors
3.4 Using Matrix Transformations
3.5 Row-Major vs. Column-Major Matrices
3.6 Understanding the Matrix3x3f Class
3.7 Affine Transformation
Resources and Further Reading
Chapter 4 Time and Space
4.1 Calculating Time Delta
4.2 Screen Mapping
4.3 Adjusting the Viewport Ratio
4.4 Cannon Physics
Resources and Further Reading
Chapter 5 Simple Game Framework
5.1 Screen-to-World Conversion
5.2 Understanding the Simple Framework
5.3 Using the Simple Framework Template
Resources and Further Reading
Chapter 6 Vector2f Updates
Chapter 7 Intersection Testing
7.1 Point in Polygon Testing
7.2 Using an Axis Aligned Bounding Box for Intersection Testing
7.3 Using Circles for Intersections
7.4 Using the Separating Axis Method
7.5 Using the Line-Line Overlap Method
7.6 Using the Rectangle-Rectangle Overlap Method
7.7 Optimizing Your Tests
Resources and Further Reading
Chapter 8 Game Prototype
8.1 Creating a Polygon Wrapper Classes
8.2 Making a Prototype Asteroid
8.3 Creating a Prototype Editor
8.4 Making Rocks with a Prototype Asteroid Factory
8.5 Prototype Bullet Class
8.6 Prototype Ship Class
8.7 Coding the Prototype Game
Resources and Further Reading
PART II The Polish
Chapter 9 Files and Resources
9.1 Understanding How Java Handles Files and Directories
9.2 Understanding Input/Output Streams
9.3 Creating the Resources.jar File for Testing
9.4 Putting Resources on the Classpath
9.5 Making a Resource Loader Utility
9.6 Exploring Java Properties
9.7 An Overview of XML Files
Resources and Further Reading
Chapter 10 Images
10.1 Learning About Colors in Java
10.2 Exploring Different Image Types
10.3 Performing Color Interpolation
10.4 Using Volatile Images for Speed
10.5 Creating Transparent Images
10.6 Using the Alpha Composite Rules
10.7 Drawing Sprites
10.8 Exploring Different Scaling Algorithms
Resources and Further Reading
Chapter 11 Text
11.1 Understanding Java Fonts
11.2 Making a Draw String Utility
11.3 Using Text Metrics for Layout
11.4 Enabling Thread-Safe Keyboard Input
Resources and Further Reading
Chapter 12 Threads
12.1 Using the Callback Task with Threads
12.2 Using Threads to Load Files
12.3 Using the FakeHardware Class for Testing
12.4 Using the Wait/Notify Methods
12.5 Using Threads in the Game Loop
12.6 Using a State Machine
12.7 The OneShotEvent Class
12.8 The LoopEvent Class
12.9 The RestartEvent Class
12.10 The Multi-Thread Event Example
Resources and Further Reading
Chapter 13 Sound
13.1 Working with Sound Files
13.2 Problems with the Sound Library
13.3 Developing Blocking Audio Classes
13.4 Using the Blocking Clip Class
13.5 Using the AudioDataLine Class
13.6 Creating the BlockingDataLine Class
13.7 Creating a SoundEvent Class
13.8 Using the LoopEvent Class
13.9 Using the RestartEvent Class
13.10 Adding Sound Controls
Resources and Further Reading
Chapter 14 Deployment with ANT
14.1 Installing the ANT Software
14.2 Understanding the Format of a Build Script
14.3 Learning Common ANT Tasks
14.4 Building an Extendable Build Script
Resources and Further Reading
Chapter 15 Collision Detection
15.1 Bouncing Balls with Collision Detection
15.2 Using the Parametric Line Equation
15.3 Finding a Line-Rectangle Intersection
15.4 Finding a Line-Line Intersection
15.5 Calculating a Reflection Vector
15.6 Calculating a Point Inside a Polygon
15.7 Bouncing a Point Inside a Polygon
Resources and Further Reading
Part III The Complete Game
Chapter 16 Tools
16.1 Creating a Game Framework
16.2 Updating the Polygon Editor
16.3 Drawing a Sprite
16.4 Creating a Simple Particle Engine
Resources and Further Reading
Chapter 17 Space Rocks
最后的游戏
Chapter 18 Conclusion
Index