Game Development Reference
In-Depth Information
C H A P T E R 3
■ ■ ■
Building a Java Game from Scratch
If you don't like C and want to stay as far away from it as possible, the next two chapters will show you
how simple and fun writing a Java-only game can be. We start by taking a look at the differences between
Android and the Java Micro Edition (Java ME), which is the standard for mobile development. Next, we
take a look at some basic gaming techniques such as sprite rendering and sound manipulation, as an
appetizer to the main course—building a real game called Space Blaster. In this fun game, you must
shoot or duck incoming asteroids that threaten to destroy your space ship. A shield will also help you in
your quest for a high score. Let's get started.
Android Gaming vs. Java ME Gaming
If you have written many Android applications, perhaps you have noticed how different the Android Java
API is from the Java SE and Java ME APIs, the standards for Java and mobile development respectively.
As a matter of fact, according to Wikipedia, this is a major source of criticism about Android
( http://en.wikipedia.org/wiki/Android_(operating_system) ).
Android does not use a conventional Linux kernel. It does not have a native X
Window system, nor does it support the standard GNU libraries, making reusing
existing Linux applications or libraries difficult.
Android does not use established Java standards (Java SE and Java ME). This
prevents compatibility among Java applications. It does not provide the full set of
Java SE or ME classes, libraries, and APIs.
• Android does not officially allow applications to be installed on or run from an SD
card. This is a serious mistake as many advanced 3D games use big files to store
graphics and sound. Storing these files in the main file system will quickly drain
precious disk space.
These shortcomings are evident just by looking at the Android library within your IDE. Consider
Figure 3-1, which displays the classes for the android.jar library. On the right side, you will notice that
most of the packages of Java SE are included, which is good. However, some useful classes for games,
such as java.awt.Polygon and java.awt.Dimension , are still missing. Although in version 1.5 of the SDK
Google has added the important Java Bean property change support (see the java.beans package). The
middle of the figure shows where Android and Java SE are two different animals—none of the classes in
the Android package are part of the Java SE and ME standards. Finally, in the left view, you can see that
Search WWH ::




Custom Search