Changeset ebaddd9 in advance-wars for src


Ignore:
Timestamp:
Feb 2, 2011, 3:36:46 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
6a639f7
Parents:
5d77d43
Message:

Added code to draw a unit's possible movement options on the map.

Location:
src/com/medievaltech
Files:
5 edited

Legend:

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

    r5d77d43 rebaddd9  
    4848
    4949        /** Paint to draw the lines on screen. */
    50         private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2,
     50        private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2, mSelectionPaint,
    5151                mUnitPaint;
    5252       
     
    6060       
    6161        private com.medievaltech.gui.Window wndMainMenu, wndBattleMap;
     62        private Unit selectedUnit;
     63        private boolean test = false;
    6264       
    6365        public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) {
     
    9496            mUnitPaint.setAntiAlias(true);
    9597            mUnitPaint.setARGB(255, 255, 0, 0);
     98           
     99            mSelectionPaint = new Paint();
     100            mSelectionPaint.setAntiAlias(true);
     101            mSelectionPaint.setARGB(255, 255, 127, 0);
    96102           
    97103            wndMainMenu = new com.medievaltech.gui.Window(0, 0, 320, 450);;
     
    112118                        for(int y=0; y<mMap.getHeight(); y++) {
    113119                                if(land)
    114                                         mMap.setTile(x, y, new Tile(grassTile));
     120                                        mMap.setTile(x, y, new Tile(grassTile, new Point(x, y)));
    115121                                else
    116                                         mMap.setTile(x, y, new Tile(oceanTile));
     122                                        mMap.setTile(x, y, new Tile(oceanTile, new Point(x, y)));
    117123                                land = !land;
    118124                        }
     
    122128            mMap.getTile(2, 3).addUnit(new Soldier(mUnitPaint));
    123129            mMap.getTile(5, 7).addUnit(new Soldier(mUnitPaint));
     130           
     131            selectedUnit = mMap.getTile(2, 3).currentUnit;
    124132           
    125133            mGameState = GameState.MAIN_MENU;
     
    343351               
    344352                mMap.draw(canvas, 10, 25);
     353               
     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+")");
     358                }
     359                test = true;
    345360               
    346361                text = "Advance Wars grid test";
  • src/com/medievaltech/game/Map.java

    r5d77d43 rebaddd9  
    1616                for(int x=0; x<getWidth(); x++)
    1717                        for(int y=0; y<getHeight(); y++)
    18                                 grid[x][y] = new Tile(t);
     18                                grid[x][y] = new Tile(t, new Point(x, y));
    1919        }
    2020       
  • src/com/medievaltech/game/Soldier.java

    r5d77d43 rebaddd9  
    99        public Soldier(Paint p) {
    1010                super(p);
     11               
     12                move = 2;
    1113        }
    1214       
     
    2426
    2527        @Override
    26         public List<Point> getRange() {
    27                 // TODO Auto-generated method stub
    28                 return null;
     28        public List<Point> getMovementRange() {
     29                return super.getMovementRange();
    2930        }
    3031
  • src/com/medievaltech/game/Tile.java

    r5d77d43 rebaddd9  
    2222        }
    2323       
    24         public Tile(Tile t) {
     24        public Tile(Tile t, Point point) {
    2525                this.type = t.type;
    2626                this.moveCoefficent = t.moveCoefficent;
    2727                this.p = t.p;
     28                this.point = point;
    2829        }
    2930       
    3031        public void addUnit(Unit unit) {
    31                 currentUnit = unit;     
     32                currentUnit = unit;
     33                unit.location = point;
    3234        }
    3335       
  • src/com/medievaltech/game/Unit.java

    r5d77d43 rebaddd9  
    11package com.medievaltech.game;
    22
     3import java.util.LinkedList;
    34import java.util.List;
    45
     
    2627       
    2728        public int sightRange;
    28         public int move;
     29        protected int move;
    2930       
    3031        public int minAttackRange;
     
    3637        }
    3738       
    38         public abstract void move(Point point);
    39         public abstract void attack(Point point);
     39        public abstract boolean move(Point point);
     40        public abstract boolean attack(Point point);
    4041       
    41         public abstract List<Point> getRange();
     42        public List<Point> getMovementRange() {
     43                List<Point> l = new LinkedList<Point>();
     44                List<Point> prev = new LinkedList<Point>();
     45                List<Point> cur = new LinkedList<Point>();
     46                boolean[][] visited = new boolean[move*2+1][move*2+1];
     47               
     48                for(int x=0; x<=move*2; x++)
     49                        for(int y=0; y<=move*2; y++)
     50                                visited[x][y] = false;
     51               
     52                prev.add(new Point(location));
     53                l.addAll(prev);
     54                visited[move][move] = true;
     55
     56                for(int dist=1; dist <= move; dist++) {
     57                        for(Point p : prev) {
     58                                if(p.x>0 && p.x>location.x-move && !visited[p.x-location.x+move-1][p.y-location.y+move]) {
     59                                        cur.add(new Point(p.x-1, p.y));
     60                                        visited[p.x-location.x+move-1][p.y-location.y+move] = true;
     61                                }
     62                                if(p.x<8 && p.x<location.x+move && !visited[p.x-location.x+move+1][p.y-location.y+move]) {
     63                                        cur.add(new Point(p.x+1, p.y));
     64                                        visited[p.x-location.x+move+1][p.y-location.y+move] = true;
     65                                }
     66                                if(p.y>0 && p.y>location.y-move && !visited[p.x-location.x+move][p.y-location.y+move-1]) {
     67                                        cur.add(new Point(p.x, p.y-1));
     68                                        visited[p.x-location.x+move][p.y-location.y+move-1] = true;
     69                                }
     70                                if(p.y<6 && p.y<location.y+move && !visited[p.x-location.x+move][p.y-location.y+move+1]) {
     71                                        cur.add(new Point(p.x, p.y+1));
     72                                        visited[p.x-location.x+move][p.y-location.y+move+1] = true;
     73                                }
     74                        }
     75                       
     76                        l.addAll(cur);
     77                        prev.clear();
     78                        prev.addAll(cur);
     79                        cur.clear();
     80                }
     81               
     82                return l;
     83        }
     84       
    4285        public abstract List<Point> getAttackRange();
    4386       
Note: See TracChangeset for help on using the changeset viewer.