Game Development Reference
In-Depth Information
Next, make the following changes to the init() method in which we want to
initialize a new array for the carrot game objects, and create a new goal game object
if the corresponding pixel color was found in the level image:
private void init (String filename) {
// objects
rocks = new Array<Rock>();
goldcoins = new Array<GoldCoin>();
feathers = new Array<Feather>();
carrots = new Array<Carrot>();
// load image file that represents the level data
Pixmap pixmap = new Pixmap(Gdx.files.internal(filename));
// scan pixels from top-left to bottom-right
int lastPixel = -1;
for (int pixelY = 0; pixelY<pixmap.getHeight(); pixelY++) {
for (int pixelX = 0; pixelX<pixmap.getWidth(); pixelX++) {
// gold coin
else if
(BLOCK_TYPE.ITEM_GOLD_COIN.sameColor(currentPixel)) {
...
}
// goal
else if (BLOCK_TYPE.GOAL.sameColor(currentPixel)) {
obj = new Goal();
offsetHeight = -7.0f;
obj.position.set(pixelX, baseHeight + offsetHeight);
goal = (Goal)obj;
}
// unknown object/pixel color
else {
}
lastPixel = currentPixel;
}
}
}
 
Search WWH ::




Custom Search