// for moving in game public void MoveTo(Square location) { if(this.location != null) this.location.SetOccupant(null); this.location = location; location.SetOccupant(this); animation.Position = location.Position(); }
private List<Unit> units; // list of your units on map #endregion Fields #region Constructors /* constructor - note that we probably won't use this one much in the final game. * Rather, we will usually use the default constructor (which initializes all the variables as nulls) * and then use the Load method to get all the info from a text file * */ public Map(Square[,] squares, List<Unit> enemies, int rows, int cols) { this.squares = squares; this.enemies = enemies; this.rows = rows; this.cols = cols; this.offset = Vector2.Zero; this.units = new List<Unit>(); }
public void Initialize() { map = (MapGenerator.GenerateRandomMap(15, 15)); map.AddUnit(new Unit()); map.Unit(0).SetLocation(map.Square(5, 5)); cursor = new Vector2(0, 0); currentSquare = map.Square((int)cursor.Y, (int)cursor.X); input = new InputManager(); unitSelected = false; screenDimensions = new Vector2(1000, 500); }
public void Update(GameTime gameTime) { input.Update(); //updates the input manager currentSquare.Deselect(); // deselect previously selected square currentSquare = map.Square((int)cursor.Y, (int)cursor.X); currentSquare.Select(); // reset the selected square to the one which the cursor is over // note that if the cursor doesn't move, it just deselects and selects the same square. updateOffset(); MapInput(); //helper function, defined below. Deals with the key input, updates the cursor position etc. map.Update(gameTime); //calls the map to update }
public static Map GeneratePlainMap(int rows, int cols) { Square[,] squares = new Square[rows, cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { squares[i, j] = new Square(i, j, "plains"); } } return new Map(squares, new List<Unit>(), rows, cols); }
public static Map GenerateRandomMap(int rows, int cols) { Random r = new Random(); Square[,] squares = new Square[rows, cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { switch (r.Next(4)) { case 0: squares[i, j] = new Square(i, j, "plains"); break; case 1: squares[i, j] = new Square(i, j, "forest"); break; case 2: squares[i, j] = new Square(i, j, "hills"); break; case 3: squares[i, j] = new Square(i, j, "mountain"); break; } } } return new Map(squares, new List<Unit>(), rows, cols); }
// for setting initial position public void SetLocation(Square location) { if(this.location != null) this.location.SetOccupant(null); this.location = location; location.SetOccupant(this); }