Changeset b97a618 in advance-wars for src


Ignore:
Timestamp:
Feb 2, 2011, 4:51:03 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
78d3c6f
Parents:
6a639f7
Message:

Touching a unit now displays its movement area. Touching a square without a unit will stop displaying any previously displayed movement area. THe movement area is now drawn under the unit itself.

Location:
src/com/medievaltech
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/com/medievaltech/advancewars/GameView.java

    r6a639f7 rb97a618  
    6161        private com.medievaltech.gui.Window wndMainMenu, wndBattleMap;
    6262        private Unit selectedUnit;
    63         private boolean test = false;
    6463       
    6564        public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) {
     
    111110            Tile oceanTile = new Tile(mTilePaint2);
    112111           
    113             mMap = new Map(grassTile, 6, 8);
     112            mMap = new Map(grassTile, 6, 8, new Point(10, 25));
    114113           
    115114            boolean land = true;
     
    127126           
    128127            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));
    132129           
    133130            mGameState = GameState.MAIN_MENU;
     
    350347                        mTextPaint.setTextSize(12);
    351348               
    352                 mMap.draw(canvas, 10, 25);
     349                mMap.draw(canvas);
    353350               
    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                        }
    358355                }
    359                 test = true;
    360356               
    361                 text = "Advance Wars grid test";
    362                 canvas.drawText(text, 0, 450-(metrics.ascent+metrics.descent)/2, mTextPaint);
     357                mMap.drawUnits(canvas);
     358               
    363359                        break;
    364360                }
     
    432428                case BATTLE_MAP:
    433429                        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                       
    435438                        break;
    436439                }
  • src/com/medievaltech/game/Map.java

    r6a639f7 rb97a618  
    66public class Map {
    77        private Tile[][] grid;
     8        public Point offset;
    89       
    9         public Map(int width, int height) {
     10        public Map(int width, int height, Point offset) {
    1011                grid = new Tile[width][height];
     12                this.offset = offset;
    1113        }
    1214       
    13         public Map(Tile t, int width, int height) {
     15        public Map(Tile t, int width, int height, Point offset) {
    1416                grid = new Tile[width][height];
     17                this.offset = offset;
    1518               
    1619                for(int x=0; x<getWidth(); x++)
     
    3942        }
    4043       
    41         public void draw(Canvas c, int xStart, int yStart) {
     44        public void draw(Canvas c) {
    4245                for(int x=0; x<getWidth(); x++)
    4346                        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);
    4554        }
    4655}
  • src/com/medievaltech/game/Tile.java

    r6a639f7 rb97a618  
    4343        public void draw(Canvas c, int x, int y) {
    4444                c.drawRect(x, y, x+50, y+50, p);
    45                
     45        }
     46       
     47        public void drawUnit(Canvas c, int x, int y) {
    4648                if(currentUnit != null)
    4749                        currentUnit.draw(c, x+25, y+25);
  • src/com/medievaltech/game/Unit.java

    r6a639f7 rb97a618  
    6060                                        visited[p.x-location.x+move-1][p.y-location.y+move] = true;
    6161                                }
    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]) {
    6363                                        cur.add(new Point(p.x+1, p.y));
    6464                                        visited[p.x-location.x+move+1][p.y-location.y+move] = true;
     
    6868                                        visited[p.x-location.x+move][p.y-location.y+move-1] = true;
    6969                                }
    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]) {
    7171                                        cur.add(new Point(p.x, p.y+1));
    7272                                        visited[p.x-location.x+move][p.y-location.y+move+1] = true;
Note: See TracChangeset for help on using the changeset viewer.