public void CreateUnit(Tile tile) { Unit unit = new Unit(); unit.X = tile.X; unit.Y = tile.Y; unit.Player = this; tile.Unit = unit; unit.Tile = tile; Units.Add(unit); }
public void RemoveUnit(Unit unit) { unit.Tile.Unit = null; unit.Tile = null; }
public void Shoot(Unit unit, ShootAction action) { Shot shot = new Shot(); shot.Direction = action.Direction; shot.X = Tools.GetX(unit.X, action.Direction); shot.Y = Tools.GetY(unit.Y, action.Direction); Tile tile = Data.Map.Tiles[shot.Y][shot.X]; if (tile.IsWall) return; shot.Tile = tile; tile.Shot = shot; ShotList.Add(shot); }
public UnitFormation(List<Unit> units) { this.units = units; this.leader = units.First(); this.leader.IfLeader = true; }
public void Scan(Unit unit, ScanAction action) { ScanInfo scanInfo = new ScanInfo(); if (action.Direction == API.Direction.Down || action.Direction == API.Direction.Up) { int del; if (action.Direction == API.Direction.Down) del = -1; else del = 1; for (int x=-1;x<1;x++) { int ax = unit.X + x; int ay = unit.Y + del; if (ax < 0 || ax >= Data.Map.MapWidth) return; if (ay < 0 || ay >= Data.Map.MapLength) return; Tile tile = Data.Map.Tiles[ay][ax]; if (tile != null) scanInfo.Tiles.Add(tile.GetInfo()); } } if (action.Direction == API.Direction.Left || action.Direction == API.Direction.Right) { int del; if (action.Direction == API.Direction.Left) del = -1; else del = 1; for (int y = -1; y < 1; y++) { int ax = unit.X + del; int ay = unit.Y + y; if (ax < 0 || ax >= Data.Map.MapWidth) return; if (ay < 0 || ay >= Data.Map.MapLength) return; Tile tile = Data.Map.Tiles[ay][ax]; if (tile != null) scanInfo.Tiles.Add(tile.GetInfo()); } } unit.Player.AI.ReceiveScanInfo(scanInfo); }
public void ProcessUnitAction(Unit unit, UnitAction action) { if (action is MoveAction) Move(unit, (MoveAction)action); else if (action is ScanAction) Scan(unit, (ScanAction)action); else if (action is ShootAction) Shoot(unit, (ShootAction)action); }
public void MoveUnit(Unit unit, Tile tile) { unit.Tile.Unit = null; unit.X = tile.X; unit.Y = tile.Y; tile.Unit = unit; unit.Tile = tile; }
public void Move(Unit unit, MoveAction action) { int newX = Tools.GetX(unit.X, action.Direction); int newY = Tools.GetY(unit.Y, action.Direction); // is space off map if (newX < 0 || newX >= Data.Map.MapWidth) return; //fail if (newY < 0 || newY >= Data.Map.MapLength) return; //fail // Is space collision free Tile tile = Data.Map.Tiles[newY][newX]; if (tile.IsWall) return; //fail if (tile.Unit != null) return; MoveUnit(unit, tile); }
public void KillUnit(Unit unit) { unit.Tile.Unit = null; unit.Tile = null; if (unit.Player.Units.Contains(unit)) unit.Player.Units.Remove(unit); unit.Player = null; }