Permalink
Browse files

Init board drawing is a go

  • Loading branch information...
1 parent 15ed362 commit df323404e7e0cc0e7fe1a1b5c7fcbe9cce8bd5f8 @ivanarellano committed Mar 30, 2012
@@ -1,14 +1,10 @@
package com.ivanarellano.game.pm;
-import com.badlogic.gdx.scenes.scene2d.ui.Image;
-
-
public class Board {
- static final int ROWS = 3;
- static final int COLS = 3;
- Image grassBoard = new Image(Assets.atlas.findRegion("grassboard"));
+ public static final int ROWS = 3;
+ public static final int COLS = 3;
- Tile[][] tiles = new Tile[ROWS][COLS];
+ public Tile[][] tiles = new Tile[ROWS][COLS];
int totalMoves;
String goal = new String("123456780");
@@ -2,16 +2,24 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.scenes.scene2d.Group;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
+import com.ivanarellano.game.pm.Assets;
import com.ivanarellano.game.pm.Board;
import com.ivanarellano.game.pm.PmGame;
import com.ivanarellano.game.pm.PmScreen;
public class GameScreen extends PmScreen {
Board board = new Board("745216803");
+ Group groupBoard = new Group("board");
+ Group groupTiles = new Group("tiles");
+ public Image grassBoard = new Image(Assets.atlas.findRegion("grassboard"));
public GameScreen(PmGame game) {
super(game);
Gdx.gl.glClearColor(game.bgColor.r, game.bgColor.g, game.bgColor.b, game.bgColor.a);
+
+ initStage();
}
@Override
@@ -45,5 +53,35 @@ public void resume() {
public void dispose() {
game.stage.dispose();
}
+
+ void initStage() {
+ // add some grass
+ groupBoard.addActor(grassBoard);
+
+ // add tiles
+ int XOffset = 0;
+ int YOffset = 0;
+ for (int row = 0; row < Board.ROWS; row++) {
+ for (int col = 0; col < Board.COLS; col++) {
+ board.tiles[row][col].x = XOffset;
+ board.tiles[row][col].y = YOffset;
+
+ groupTiles.addActor(board.tiles[row][col]);
+
+ if (col >= 2)
+ XOffset = 0;
+ else
+ XOffset += 50;
+ }
+
+ YOffset += 50;
+ }
+
+ // layer tiles on top of grass
+ groupBoard.addActor(groupTiles);
+
+ // place it all on the stage
+ game.stage.addActor(groupBoard);
+ }
}

0 comments on commit df32340

Please sign in to comment.