Ejemplo n.º 1
0
        public bool Equals(GridLocation p)
        {
            if (p == null)
                return false;

            return this == p;
        }
Ejemplo n.º 2
0
 // Some constructors for the simplified initialization
 /// <summary>
 /// Initialize with Custom Location.
 /// X = Y = 25;
 /// </summary>
 public GPS(GridLocation location)
     : this(location, 25, 25)
 {
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initialize with Custom Location and X, Y block coords
 /// </summary>
 public GPS(GridLocation Location, int X, int Y)
 {
     this.Location = Location;
     this.X = X;
     this.Y = Y;
 }
Ejemplo n.º 4
0
Archivo: Unit.cs Proyecto: scerdam/Maze
 /// <summary>
 /// Registers this unit in <see cref="ObjectContainer"/> and sets its Home location.
 /// </summary>
 /// <param name="respawnLocation">Home location of the unit.</param>
 public void Create(GridLocation respawnLocation)
 {
     this.respawnLocation = respawnLocation;
     base.Create(new GPS(respawnLocation));
 }
Ejemplo n.º 5
0
Archivo: Unit.cs Proyecto: scerdam/Maze
 /// <summary>
 /// Relocates the unit to the secified destination position.
 /// </summary>
 /// <param name="destinationGPS">A new position where the unit is relocating.</param>
 public void TeleportTo(GridLocation destinationGPS)
 {
     Cell destinationCell = Map.Instance.GetCell(destinationGPS);
     TeleportTo(destinationCell);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// RePaint PlayForm map pictures.
        /// Include images of the player, blocks and objects on a block
        /// </summary>
        private void RebuildGraphMap(Graphics gCellBP)
        {
            GridLocation PBLocation = new GridLocation();
            Cell Block = new Cell();

            List<Maze.Classes.Object> objectsOnMap = new List<Maze.Classes.Object>();

            // CellGraph
            for (int i = 0; i < GlobalConstants.GRIDMAP_WIDTH; ++i)
                for (int j = 0; j < GlobalConstants.GRIDMAP_HEIGHT; ++j)
                {
                    // Calculated location point for every block
                    int x, y;
                    x = /*CellPB.Location.X*/ +(i - 1) * GlobalConstants.CELL_WIDTH - (Player.Position.X - 25);
                    y = /*CellPB.Location.Y*/ +(j - 1) * GlobalConstants.CELL_HEIGHT - (Player.Position.Y - 25);
                    PBLocation.X = Player.Position.Location.X + i - GlobalConstants.GRIDMAP_WIDTH / 2;
                    PBLocation.Y = Player.Position.Location.Y + j - GlobalConstants.GRIDMAP_HEIGHT / 2;
                    PBLocation.Z = Player.Position.Location.Z;
                    PBLocation.Level = Player.Position.Location.Level;
                    Block = Map.Instance.GetCell(PBLocation);

                    // Draw Grid Cell image
                    gCellBP.DrawImage(PictureManager.GetPictureByType(Block.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);

                    // Draw Start Block
                    if (Block.HasAttribute(CellAttributes.IsStart))
                    {
                        gCellBP.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
                    }

                    // Draw Finish Block
                    if (Block.HasAttribute(CellAttributes.IsFinish))
                    {
                        gCellBP.DrawImage(PictureManager.FinishImage, x + 5, y + 5, 40, 40);
                    }

                    // Include all objects in this grid
                    objectsOnMap.AddRange(ObjectContainer.Instance.GetObjects(Block.Location));

                }

            /* Draw Visible Objects
             * Order:
             * 1. Slime
             * 2. GridObjects
             * 3. Units
             * 4. Slug
             */
            Image objectImage;

            for (int j = 0; j < 4; ++j)
                for (int i = 0; i < objectsOnMap.Count; ++i)
                {
                    // Default NULL
                    objectImage = null;
                    switch (j)
                    {
                        case 0:
                            // Slime
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject &&
                                ((GridObject)objectsOnMap[i]).GridObjectType == GridObjectTypes.Slime)
                            {
                                objectImage = PictureManager.SlimeImage;
                            }
                            else
                                continue;
                            break;
                        case 1:
                            // GridObjects
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject)
                            {
                                GridObject gridObject = (GridObject)objectsOnMap[i];
                                if (gridObject.GridObjectType == GridObjectTypes.Slime)
                                    continue;

                                objectImage = PictureManager.GetGridObjectImage(gridObject);
                            }
                            else
                                continue;
                            break;
                        case 2:
                            // Units
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Unit)
                            {
                                Unit unit = (Unit)objectsOnMap[i];

                                // Check Smoke Cloud
                                // Draw objects with 'Smoke Cloud' effect if Slug also has it and vice versa
                                if (!(Player.HasEffectType(EffectTypes.SmokeCloud) ^ unit.HasEffectType(EffectTypes.SmokeCloud)))
                                    objectImage = PictureManager.GetUnitImage(unit);
                            }
                            else
                                continue;
                            break;
                        case 3:
                            // Slug
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Slug)
                                objectImage = PictureManager.GetSlugImage((Slug)objectsOnMap[i]);
                            else
                                continue;
                            break;
                    }

                    if (objectImage == null)
                        continue;

                    // Determine object image coords
                    // relative to the object position on Cell and Player (as a center of the GridMap)
                    int xCoord = this.pbGridMap.Size.Width / 2 - ((Player.Position.Location.X - objectsOnMap[i].Position.Location.X) *
                            GlobalConstants.CELL_WIDTH + Player.Position.X - objectsOnMap[i].Position.X) - objectImage.Size.Width / 2;
                    int yCoord = this.pbGridMap.Size.Height / 2 - ((Player.Position.Location.Y - objectsOnMap[i].Position.Location.Y) *
                            GlobalConstants.CELL_HEIGHT + Player.Position.Y - objectsOnMap[i].Position.Y) - objectImage.Size.Height / 2;

                    gCellBP.DrawImage(objectImage, xCoord, yCoord,
                        objectImage.Size.Width, objectImage.Size.Height);
                }
        }
Ejemplo n.º 7
0
Archivo: Unit.cs Proyecto: scerdam/Maze
        /// <summary>
        /// Initializes a new instance of the Unit class.
        /// </summary>
        public Unit()
        {
            SetDeathState(DeathStates.Alive);
            this.unitFlags = UnitFlags.None;

            this.respawnLocation = new GridLocation();

            ObjectType = ObjectTypes.Unit;
            this.unitType = UnitTypes.Unit;
            this.unitSide = UnitSides.Evil;

            this.effectList = new EffectCollection(this);

            this.collidingUnits = new List<Unit>();

            BaseSpeed = 1.0d;
            SpeedRate = BaseSpeed;

            this.respawnTimer = 3000;

            this.effectList.EffectApplied += new EffectCollection.EffectHandler(OnEffectApplied);
            this.effectList.EffectRemoved += new EffectCollection.EffectHandler(OnEffectRemoved);
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        void pbMap_Paint(object sender, PaintEventArgs e)
        {
            Graphics gGraphic = e.Graphics;

            GridLocation cellLocation = new GridLocation();
            Cell cell = new Cell();
            // CellGraph
            int cellsCountWidth = (int)Math.Ceiling(this.pbMap.Size.Width / 2d / GlobalConstants.CELL_WIDTH) * 2 + 1;
            int cellsCountHeight = (int)Math.Ceiling(this.pbMap.Size.Height / 2d / GlobalConstants.CELL_HEIGHT) * 2 + 1;

            // HACK: Correction values because the width and height of drawing region are not a multiple of CELL_WIDTH and CELL_HEIGHT
            int xCorrection = ((int)Math.Ceiling(this.pbMap.Size.Height * 1d / GlobalConstants.CELL_HEIGHT) * GlobalConstants.CELL_HEIGHT - this.pbMap.Size.Height) / 2;
            int yCorrection = ((int)Math.Ceiling(this.pbMap.Size.Width * 1d / GlobalConstants.CELL_WIDTH) * GlobalConstants.CELL_WIDTH - this.pbMap.Size.Width) / 2;

            for (int i = 0; i < cellsCountWidth; ++i)
                for (int j = 0; j < cellsCountHeight; ++j)
                {
                    int x, y;
                    x = (i - 1) * GlobalConstants.CELL_WIDTH - this.centralGPS.X + xCorrection + 25;
                    y = (j - 1) * GlobalConstants.CELL_HEIGHT - this.centralGPS.Y + yCorrection + 25;
                    cellLocation.X = centralGPS.Location.X + i - cellsCountWidth / 2;
                    cellLocation.Y = centralGPS.Location.Y + j - cellsCountHeight / 2;
                    cellLocation.Z = centralGPS.Location.Z;
                    cellLocation.Level = centralGPS.Location.Level;
                    cell = GetCell(cellLocation);

                    gGraphic.DrawImage(PictureManager.GetPictureByType(cell.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);

                    // Draw Start Block
                    if (cell.HasAttribute(CellAttributes.IsStart))
                    {
                        gGraphic.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
                    }

                    // Draw Finish Block
                    if (cell.HasAttribute(CellAttributes.IsFinish))
                    {
                        gGraphic.DrawImage(PictureManager.FinishImage, x + 5, y + 5, PictureManager.FinishImage.Width, PictureManager.FinishImage.Height);
                    }

                    // Draw Ooze Drop
                    if (cell.HasAttribute(CellAttributes.HasDrop))
                    {
                        gGraphic.DrawImage(PictureManager.DropImage, x + 15, y + 10, 20, 30);
                    }

                    // Portal
                    if (cell.HasOption(CellOptions.Portal))
                    {
                        Image image = PictureManager.PortalImage;
                        gGraphic.DrawImage(image,
                            x + (GlobalConstants.CELL_WIDTH - image.Width) / 2,
                            y + (GlobalConstants.CELL_HEIGHT - image.Height) / 2,
                            PictureManager.PortalImage.Width, PictureManager.PortalImage.Height);
                    }
                }
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        public Cell GetCell(GridLocation location)
        {
            Cell cell;
            if (!this.mapCells.TryGetValue(location, out cell))
            {
                // default cell
                cell.Initialize();
                // but specified location
                cell.Location = location;
            }

            return cell;
        }
Ejemplo n.º 12
0
Archivo: Map.cs Proyecto: scerdam/Maze
        /// <summary>
        /// Gets a Cell of the map with the specified Location.
        /// </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(GridLocation location)
        {
            if (this.mapCells.ContainsKey(location))
                return this.mapCells[location];

            // return default cell
            Cell cell = new Cell();
            cell.Initialize();
            return cell;
        }
Ejemplo n.º 13
0
        // Find all passable neighbors
        private void FindNeighbors(Cell Block, CellParam FinalPoint)
        {
            CellParam currentCell = FindCell(openList, Block);

            for (int i = -1; i <= 1; ++i)
            {
                for (int j = -1; j <= 1; ++j)
                {
                    // Skip this cell
                    if (i == 0 && j == 0)
                        continue;

                    GridLocation location = new GridLocation();
                    location.X = Block.Location.X + i;
                    location.Y = Block.Location.Y + j;
                    location.Level = Block.Location.Level;

                    // Skip non-existed cell
                    if (Map.Instance.GetCell(location).Type == 16)
                        continue;

                    bool isNeighbourReachable = false;

                    switch (i * j)
                    {
                        case -1:
                            if (i == -1)    // diagonal moving - left and down
                            {
                                GridLocation locDown = Block.Location;
                                locDown.Y++;
                                GridLocation locLeft = Block.Location;
                                locLeft.X--;

                                // Check cell's passability
                                if ((Block.CanMoveTo(Directions.Down) &&
                                    Map.Instance.GetCell(locDown).CanMoveTo(Directions.Left)) &&
                                    (Block.CanMoveTo(Directions.Left) &&
                                    Map.Instance.GetCell(locLeft).CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // diagonal moving - right and up
                            {
                                GridLocation locUp = Block.Location;
                                locUp.Y--;
                                GridLocation locRight = Block.Location;
                                locRight.X++;

                                if ((Block.CanMoveTo(Directions.Up) &&
                                    Map.Instance.GetCell(locUp).CanMoveTo(Directions.Right)) &&
                                    (Block.CanMoveTo(Directions.Right) &&
                                    Map.Instance.GetCell(locRight).CanMoveTo(Directions.Up)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                        case 1:
                            if (i == -1)    // diagonal moving - left and up
                            {
                                GridLocation locUp = Block.Location;
                                locUp.Y--;
                                GridLocation locLeft = Block.Location;
                                locLeft.X--;

                                if ((Block.CanMoveTo(Directions.Left) &&
                                    Map.Instance.GetCell(locLeft).CanMoveTo(Directions.Up)) &&
                                    (Block.CanMoveTo(Directions.Up) &&
                                    Map.Instance.GetCell(locUp).CanMoveTo(Directions.Left)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // diagonal moving - right and down
                            {
                                GridLocation locDown = Block.Location;
                                locDown.Y++;
                                GridLocation locRight = Block.Location;
                                locRight.X++;

                                if ((Block.CanMoveTo(Directions.Down) &&
                                    Map.Instance.GetCell(locDown).CanMoveTo(Directions.Right)) &&
                                    (Block.CanMoveTo(Directions.Right) &&
                                    Map.Instance.GetCell(locRight).CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                        case 0:
                            if (i == 0)    // moving up or down
                            {
                                if ((j == -1 && Block.CanMoveTo(Directions.Up)) ||
                                    (j == 1 && Block.CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // moving - right or left
                            {
                                if ((i == 1 && Block.CanMoveTo(Directions.Right)) ||
                                    (i == -1 && Block.CanMoveTo(Directions.Left)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                    }

                    if (!isNeighbourReachable)
                        continue;

                    CellParam Cell = new CellParam();
                    Cell.ID = Map.Instance.GetCell(location).ID;
                    Cell.MID = Block.ID;
                    if (i == 0 || j == 0)
                        Cell.G = currentCell.G + 10;    // Vertical or horizontal movement
                    else
                        Cell.G = currentCell.G + 14;    // Diagonal movement

                    Cell.H = (Math.Abs(location.X - FindCell(openList, FinalPoint).Location.X) + Math.Abs(location.Y - FindCell(openList, FinalPoint/*, CurrentMap*/).Location.Y)) * 10;
                    Cell.F = Cell.G + Cell.H;

                    if (!SearchInList(openList, Cell) && !SearchInList(closeList, Cell))
                    {
                        openList.Add(Cell);

                        if (!SearchInList(closeList, currentCell))
                            closeList.Add(currentCell);

                        if (SearchInList(openList, currentCell))
                            openList.Remove(currentCell);
                    }

                    if (Cell.ID == FinalPoint.ID)
                    {
                        if (!SearchInList(closeList, currentCell))
                            closeList.Add(currentCell);
                        closeList.Add(Cell);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public void SetDestination(GridLocation destinationGPS)
 {
     Cell destinationCell = Map.Instance.GetCell(destinationGPS);
     SetDestination(destinationCell);
 }