/// <summary> /// Initializes a new instance of the Deimos class. /// </summary> public Deimos() { this.unitType = UnitTypes.Deimos; this.unitSide = UnitSides.Evil; Position = new GPS(Home, 25, 25); this.motionMaster = new RandomMovementGenerator(this); //currentCell = GetWorldMap().GetCell(Position.Location); }
/// <summary> /// Initialize by copying Position with custom X and Y coords /// </summary> public GPS(GPS Position, int X, int Y) { this = Position; this.X = X; this.Y = Y; }
/// <summary> /// Returns the unit to its Home location and changes the state to <see cref="DeathState.Alive"/>. /// </summary> protected void Respawn() { // Return to start location Position = new GPS(Home, 25, 25); SetDeathState(DeathStates.Alive); }
/// <summary> /// Relocates the unit to the specifed destination <see cref="Cell"/>. /// </summary> /// <param name="destinationCell">A cell where the unit is relocating</param> public void TeleportTo(Cell destinationCell) { // save old position GPS prevPosition = Position; Position = new GPS(destinationCell.Location, 25, 25); if (Relocated != null) Relocated(this, new PositionEventArgs(prevPosition, Position)); }
public void Create(GPS position, BonusEffect effect) { this.bonusEffect = effect; base.Create(position); }
/// <summary> /// Defines the next <see cref="GPS"/> (or <see cref="Cell"/>) where the mover is directed. /// </summary> protected void DefineNextGPS() { this.nextGPS = new GPS(mover.Position, 25, 25); for (int i = 0; i < 2; ++i) switch (i == 0 ? CurrentDirection.First : CurrentDirection.Second) { case Directions.Up: --this.nextGPS.Location.Y; break; case Directions.Down: ++this.nextGPS.Location.Y; break; case Directions.Left: --this.nextGPS.Location.X; break; case Directions.Right: ++this.nextGPS.Location.X; break; } this.remainDistance = this.mover.Position.GetDistance(this.nextGPS); }
void pbMap_MouseClick(object sender, MouseEventArgs e) { // Only Left Mouse Button if (e.Button != System.Windows.Forms.MouseButtons.Right) return; GridLocation cursorLocation = new GridLocation(); // Calculate Mouse absolute position // i.e How far it is from the cetral position cursorLocation.X = this.centralGPS.Absolute.X - (this.pbMap.Size.Width / 2 - e.Location.X); cursorLocation.Y = this.centralGPS.Absolute.Y - (this.pbMap.Size.Height / 2 - e.Location.Y); cursorLocation.Z = this.centralGPS.Absolute.Z; cursorLocation.Level = this.centralGPS.Location.Level; GPS cursorGPS = new GPS(); cursorGPS.Absolute = cursorLocation; Cell cell = GetCell(cursorGPS.Location); // Prevent double BlockEdit window openning if (this.cellEditForm == null) this.cellEditForm = new CellEdit(cell); else { this.cellEditForm.Close(); this.cellEditForm = new CellEdit(cell); } this.cellEditForm.FormClosing += (sender_, e_) => { this.pbMap.Refresh(); }; this.cellEditForm.ShowDialog(); }
public void Create(GPS position, Movement.Direction currentDirection) { ((CustomMovement)this.motionMaster).SetDirection(currentDirection); base.Create(position); }
/// <summary> /// Initializes a new instance of the PositionEventArgs class. /// </summary> /// <param name="prevPosition">The previous <see cref="Object"/> position.</param> /// <param name="newPosition">The new <see cref="Object"/> position.</param> public PositionEventArgs(GPS prevPosition, GPS newPosition) { PrevPosition = prevPosition; NewPosition = newPosition; }
private void pbMap_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.W && e.KeyCode != Keys.A && e.KeyCode != Keys.S && e.KeyCode != Keys.D && e.KeyCode != Keys.Z && e.KeyCode != Keys.R) return; // Compute the cursor GPS Point cursorPoint = this.pbMap.PointToClient(Cursor.Position); //Point cursorLocation = new Point(Cursor.Position.X - pbMapPoint.X, Cursor.Position.Y - pbMapPoint.Y); GridLocation cursorLocation = new GridLocation(); // Calculate Mouse absolute position // i.e How far it is from the cetral position cursorLocation.X = this.centralGPS.Absolute.X - (this.pbMap.Size.Width / 2 - cursorPoint.X); cursorLocation.Y = this.centralGPS.Absolute.Y - (this.pbMap.Size.Height / 2 - cursorPoint.Y); cursorLocation.Z = this.centralGPS.Absolute.Z; cursorLocation.Level = this.centralGPS.Location.Level; GPS cursorGPS = new GPS(); cursorGPS.Absolute = cursorLocation; Cell cell = GetCell(cursorGPS.Location); if (cell.Type == (uint)Directions.None) cell.Type = 0; byte modifiedDirection = 0; switch (e.KeyCode) { case Keys.W: modifiedDirection += (byte)Directions.Up; break; case Keys.A: modifiedDirection += (byte)Directions.Left; break; case Keys.S: modifiedDirection += (byte)Directions.Down; break; case Keys.D: modifiedDirection += (byte)Directions.Right; break; case Keys.Z: modifiedDirection += (byte)Directions.Up + (byte)Directions.Left + (byte)Directions.Down + (byte)Directions.Right; break; case Keys.R: // Mark the cell with every direction to change // then change the current cell Type to these direction // that allows to change all the neighbours and // remove the cell because it will be marked as 'no way to go'. modifiedDirection += (byte)Directions.Up + (byte)Directions.Left + (byte)Directions.Down + (byte)Directions.Right; cell.Type = modifiedDirection; break; } if ((modifiedDirection & (byte)Directions.Up) != 0) { cell.Type ^= (uint)Directions.Up; // Neighbour Cell Cell neighbourCell = GetCell(new GridLocation(cell.Location.X, cell.Location.Y - 1, cell.Location.Z, cell.Location.Level)); if (neighbourCell.ID == -1) { neighbourCell.ID = NewCellID; neighbourCell.Type = 0; } if ((cell.Type & (uint)Directions.Up) != (neighbourCell.Type & (uint)Directions.Down)) neighbourCell.Type ^= (uint)Directions.Down; if (neighbourCell.Type == 0) RemoveCell(neighbourCell); else AddCell(neighbourCell); } if ((modifiedDirection & (byte)Directions.Down) != 0) { cell.Type ^= (uint)Directions.Down; // Neighbour Cell Cell neighbourCell = GetCell(new GridLocation(cell.Location.X, cell.Location.Y + 1, cell.Location.Z, cell.Location.Level)); if (neighbourCell.ID == -1) { neighbourCell.ID = NewCellID; neighbourCell.Type = 0; } if ((cell.Type & (uint)Directions.Down) != (neighbourCell.Type & (uint)Directions.Up)) neighbourCell.Type ^= (uint)Directions.Up; if (neighbourCell.Type == 0) RemoveCell(neighbourCell); else AddCell(neighbourCell); } if ((modifiedDirection & (byte)Directions.Left) != 0) { cell.Type ^= (uint)Directions.Left; // Neighbour Cell Cell neighbourCell = GetCell(new GridLocation(cell.Location.X - 1, cell.Location.Y, cell.Location.Z, cell.Location.Level)); if (neighbourCell.ID == -1) { neighbourCell.ID = NewCellID; neighbourCell.Type = 0; } if ((cell.Type & (uint)Directions.Left) != (neighbourCell.Type & (uint)Directions.Right)) neighbourCell.Type ^= (uint)Directions.Right; if (neighbourCell.Type == 0) RemoveCell(neighbourCell); else AddCell(neighbourCell); } if ((modifiedDirection & (byte)Directions.Right) != 0) { cell.Type ^= (uint)Directions.Right; // Neighbour Cell Cell neighbourCell = GetCell(new GridLocation(cell.Location.X + 1, cell.Location.Y, cell.Location.Z, cell.Location.Level)); if (neighbourCell.ID == -1) { neighbourCell.ID = NewCellID; neighbourCell.Type = 0; } if ((cell.Type & (uint)Directions.Right) != (neighbourCell.Type & (uint)Directions.Left)) neighbourCell.Type ^= (uint)Directions.Left; if (neighbourCell.Type == 0) RemoveCell(neighbourCell); else AddCell(neighbourCell); } if (cell.ID == -1) cell.ID = NewCellID; if (cell.Type == 0) RemoveCell(cell); else AddCell(cell); this.pbMap.Refresh(); }
/// <summary> /// Set Position.X and Position.Y considering object model size and current Cell /// </summary> protected GPS NormalizePosition(GPS position) { Cell cell = Map.Instance.GetCell(position.Location); int lowerXBound = GlobalConstants.CELL_BORDER_PX + objectSize.Width / 2; int upperXBound = GlobalConstants.CELL_WIDTH - lowerXBound; int lowerYBound = GlobalConstants.CELL_BORDER_PX + objectSize.Height / 2; int upperYBound = GlobalConstants.CELL_HEIGHT - lowerYBound; if (position.X < lowerXBound) if (!cell.CanMoveTo(Directions.Left)) position.X = lowerXBound; if (position.X > upperXBound) if (!cell.CanMoveTo(Directions.Right)) position.X = upperXBound; if (position.Y < lowerYBound) if (!cell.CanMoveTo(Directions.Up)) position.Y = lowerYBound; if (position.Y > upperYBound) if (!cell.CanMoveTo(Directions.Down)) position.Y = upperYBound; return position; }
/// <summary> /// <see cref="Object.Create"/> an object with the specified position. /// </summary> /// <param name="position">Object default position</param> public virtual void Create(GPS position) { Position = position; Create(); }
/// <summary> /// Gets a Cell of the map with the specified Position. /// </summary> /// <param name="location">Location where the Cell is expected to be.</param> /// <returns>Found Cell or default Cell value when no cells were found.</returns> public Cell GetCell(GPS position) { return GetCell(position.Location); }
public bool Equals(GPS p) { if (p == null) return false; return this == p; }
public void LevelChanged() { this.respawnLocation = Map.Instance.StartLocation; Position = new GPS(Home, 25, 25); }
/// <summary> /// Calculates the absolute distance to another GPS value. /// </summary> /// <param name="point">Target position.</param> /// <returns>Distance to the point (in arbitrary units or in visual pixels on the Map).</returns> public double GetDistance(GPS point) { double distance = Math.Sqrt(Math.Pow(this.X - point.X + (this.Location.X - point.Location.X) * GlobalConstants.CELL_WIDTH, 2) + Math.Pow(this.Y - point.Y + (this.Location.Y - point.Location.Y) * GlobalConstants.CELL_HEIGHT, 2)); return distance; }
/// <summary> /// Initialized a new instance of the GridObject class. /// </summary> public GridObject() { pr_GridObjectState = GridObjectStates.Active; ObjectType = ObjectTypes.GridObject; this.gridObjectType = GridObjectTypes.GridObject; // Always in center of the cell Position = new GPS(Position, 25, 25); // Flags by default this.gridObjectsFlags = GridObjectFlags.Usable; }