Game Development Reference
In-Depth Information
A single cloud is defined by the Clouds inner class Cloud , which also inherits from
AbstractGameObject . So, a Cloud object is the actual cloud object, while Clouds is
the container that maintains a list of all the currently created clouds. A new cloud can
be created by simply calling the spawnCloud() method of Clouds . This will create a
new Cloud object, assign a random cloud image to it, move it to the end of the level,
and randomly shift it up or down a bit. The newly created cloud is also added to the
list and returned to the calling method.
Implementing the level loader
We will now implement the level loader that will be able to read and interpret the
image data.
You might want to refer to the handling of level data section
in Chapter 3 , Configuring the Game , where we defined and
discussed the level format.
Create a new file for the Level class and add the following code:
package com.packtpub.libgdx.canyonbunny.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array;
import com.packtpub.libgdx.canyonbunny.game.objects.
AbstractGameObject;
import com.packtpub.libgdx.canyonbunny.game.objects.Clouds;
import com.packtpub.libgdx.canyonbunny.game.objects.Mountains;
import com.packtpub.libgdx.canyonbunny.game.objects.Rock;
import com.packtpub.libgdx.canyonbunny.game.objects.WaterOverlay;
public class Level {
public static final String TAG = Level.class.getName();
public enum BLOCK_TYPE {
EMPTY(0, 0, 0), // black
ROCK(0, 255, 0), // green
PLAYER_SPAWNPOINT(255, 255, 255), // white
ITEM_FEATHER(255, 0, 255), // purple
ITEM_GOLD_COIN(255, 255, 0); // yellow
private int color;
 
Search WWH ::




Custom Search