Game Development Reference
In-Depth Information
Laying foundations
Let's now move on from theory to practice and get down to the actual
implementation details. We will begin with implementing the first basic version
of CanyonBunnyMain , WorldController , and WorldRenderer . Additionally, we
will use a utility class to store constant values in a new class called Constants . It
is true that this class does not appear in the class diagram, as it is just there for our
convenience to avoid scattering or, even worse, duplicating certain constants all over
the source code files. Also, as the stored values in Constants are meant to be used in
virtually any other class, it would only clutter up the class diagram by drawing one
additional line for each class to Constants .
For simplicity, we will use the Constants class to store our constant
values. Alternatively, game constants could be made data-driven via a
settings file. This would avoid the need to recompile your code when
a constant is changed.
Implementing the Constants class
Here is the listing of the code for Constants :
package com.packtpub.libgdx.canyonbunny.util;
public class Constants {
// Visible game world is 5 meters wide
public static final float VIEWPORT_WIDTH = 5.0f;
// Visible game world is 5 meters tall
public static final float VIEWPORT_HEIGHT = 5.0f;
}
First, we need to define the visible world size that can be seen at once when it is not
moving around in the game world. In this case, we have chosen a visible world size
of five meters in terms of its width and height.
Next, we will create the other three mentioned classes, but will only add the
so-called method stubs (empty methods). This way, we can focus on the layout
first and gradually implement the code and other new features later, when needed.
Hopefully, this approach will give you the best insight into the whole development
process from start to finish.
 
Search WWH ::




Custom Search