Changeset b97a618 in advance-wars
- Timestamp:
- Feb 2, 2011, 4:51:03 PM (14 years ago)
- Branches:
- master
- Children:
- 78d3c6f
- Parents:
- 6a639f7
- Location:
- src/com/medievaltech
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/medievaltech/advancewars/GameView.java
r6a639f7 rb97a618 61 61 private com.medievaltech.gui.Window wndMainMenu, wndBattleMap; 62 62 private Unit selectedUnit; 63 private boolean test = false;64 63 65 64 public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) { … … 111 110 Tile oceanTile = new Tile(mTilePaint2); 112 111 113 mMap = new Map(grassTile, 6, 8 );112 mMap = new Map(grassTile, 6, 8, new Point(10, 25)); 114 113 115 114 boolean land = true; … … 127 126 128 127 mMap.getTile(2, 3).addUnit(new Soldier(mUnitPaint)); 129 mMap.getTile(5, 7).addUnit(new Soldier(mUnitPaint)); 130 131 selectedUnit = mMap.getTile(2, 3).currentUnit; 128 mMap.getTile(5, 6).addUnit(new Soldier(mUnitPaint)); 132 129 133 130 mGameState = GameState.MAIN_MENU; … … 350 347 mTextPaint.setTextSize(12); 351 348 352 mMap.draw(canvas , 10, 25);349 mMap.draw(canvas); 353 350 354 for(Point p : selectedUnit.getMovementRange()) {355 canvas.drawRect(p.x*50+10, p.y*50+25, p.x*50+50+10, p.y*50+50+25, mSelectionPaint); 356 if(!test) 357 Log.i("AdvanceWars", "("+p.x+","+p.y+")"); 351 if(selectedUnit != null) { 352 for(Point p : selectedUnit.getMovementRange()) { 353 canvas.drawRect(p.x*50+10, p.y*50+25, p.x*50+50+10, p.y*50+50+25, mSelectionPaint); 354 } 358 355 } 359 test = true;360 356 361 text = "Advance Wars grid test";362 canvas.drawText(text, 0, 450-(metrics.ascent+metrics.descent)/2, mTextPaint);357 mMap.drawUnits(canvas); 358 363 359 break; 364 360 } … … 432 428 case BATTLE_MAP: 433 429 Log.i("AdvanceWars", "Touch event detected on battle map"); 434 thread.mGameState = GameState.MAIN_MENU; 430 431 if(event.getX() >= thread.mMap.offset.x && event.getY() >= thread.mMap.offset.y) { 432 int x = ((int)event.getX() - thread.mMap.offset.x) / 50; 433 int y = ((int)event.getY() - thread.mMap.offset.y) / 50; 434 435 thread.selectedUnit = thread.mMap.getTile(x, y).currentUnit; 436 } 437 435 438 break; 436 439 } -
src/com/medievaltech/game/Map.java
r6a639f7 rb97a618 6 6 public class Map { 7 7 private Tile[][] grid; 8 public Point offset; 8 9 9 public Map(int width, int height ) {10 public Map(int width, int height, Point offset) { 10 11 grid = new Tile[width][height]; 12 this.offset = offset; 11 13 } 12 14 13 public Map(Tile t, int width, int height ) {15 public Map(Tile t, int width, int height, Point offset) { 14 16 grid = new Tile[width][height]; 17 this.offset = offset; 15 18 16 19 for(int x=0; x<getWidth(); x++) … … 39 42 } 40 43 41 public void draw(Canvas c , int xStart, int yStart) {44 public void draw(Canvas c) { 42 45 for(int x=0; x<getWidth(); x++) 43 46 for(int y=0; y<getHeight(); y++) 44 grid[x][y].draw(c, xStart+50*x, yStart+50*y); 47 grid[x][y].draw(c, offset.x+50*x, offset.y+50*y); 48 } 49 50 public void drawUnits(Canvas c) { 51 for(int x=0; x<getWidth(); x++) 52 for(int y=0; y<getHeight(); y++) 53 grid[x][y].drawUnit(c, offset.x+50*x, offset.y+50*y); 45 54 } 46 55 } -
src/com/medievaltech/game/Tile.java
r6a639f7 rb97a618 43 43 public void draw(Canvas c, int x, int y) { 44 44 c.drawRect(x, y, x+50, y+50, p); 45 45 } 46 47 public void drawUnit(Canvas c, int x, int y) { 46 48 if(currentUnit != null) 47 49 currentUnit.draw(c, x+25, y+25); -
src/com/medievaltech/game/Unit.java
r6a639f7 rb97a618 60 60 visited[p.x-location.x+move-1][p.y-location.y+move] = true; 61 61 } 62 if(p.x< 8&& p.x<location.x+move && !visited[p.x-location.x+move+1][p.y-location.y+move]) {62 if(p.x<5 && p.x<location.x+move && !visited[p.x-location.x+move+1][p.y-location.y+move]) { 63 63 cur.add(new Point(p.x+1, p.y)); 64 64 visited[p.x-location.x+move+1][p.y-location.y+move] = true; … … 68 68 visited[p.x-location.x+move][p.y-location.y+move-1] = true; 69 69 } 70 if(p.y< 6&& p.y<location.y+move && !visited[p.x-location.x+move][p.y-location.y+move+1]) {70 if(p.y<7 && p.y<location.y+move && !visited[p.x-location.x+move][p.y-location.y+move+1]) { 71 71 cur.add(new Point(p.x, p.y+1)); 72 72 visited[p.x-location.x+move][p.y-location.y+move+1] = true;
Note:
See TracChangeset
for help on using the changeset viewer.