/// <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); } }
public void RemoveCell(Cell cell) { this.mapCells.Remove(cell.Location); if (this.maxCellId == cell.ID) --this.maxCellId; if (cell.HasAttribute(CellAttributes.IsStart)) this.startLocations.Remove(cell.Location.Level); if (cell.HasAttribute(CellAttributes.IsFinish)) this.startLocations.Remove(cell.Location.Level); this.isMapSaved = false; }
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); } } }
public void AddCell(Cell cell) { if (this.mapCells.ContainsKey(cell.Location)) { ReplaceCell(cell); return; } this.mapCells.Add(cell.Location, cell); if (Convert.ToInt32(cell.Location.Level) >= this.levelsCount) ++this.levelsCount; if (cell.HasAttribute(CellAttributes.IsStart)) this.startLocations[cell.Location.Level] = cell.Location; if (cell.HasAttribute(CellAttributes.IsFinish)) this.finishLocations[cell.Location.Level] = cell.Location; if (cell.ID > this.maxCellId) this.maxCellId = cell.ID; this.isMapSaved = false; }