/// <summary> /// Draws a single decoration /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="decoration">DecorationSet handle</param> /// <param name="position">Position of the square in the view</param> /// <param name="view">Viewing direction</param> /// <param name="alignview">True if the side is facing south (horizontaly span the decoration)</param> public void DrawDecoration(SpriteBatch batch, DecorationSet set, ViewFieldPosition position, bool alignview) { if (batch == null || set == null) { return; } // Location of the decoration on the screen Point location = GetLocation(position); // Tile id int tileid = GetTileId(position); // Offset the decoration if facing to the view point if (alignview) { location = PrepareLocation(position); tileid = PrepareTile(position); } // Draws the decoration batch.DrawTile(set.Tileset, tileid, location, Color.White, 0.0f, GetSwap(position) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0.0f); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { // Foreach wall side foreach (TileDrawing td in DisplayCoordinates.GetWalls(position)) { // Not the good side if (Compass.GetDirectionFromView(direction, td.Side) != Side) { continue; } DecorationSet decoset = field.Maze.Decoration; if (decoset == null) { return; } Decoration deco = decoset.GetDecoration(IsActivated ? ActivatedDecoration : DeactivatedDecoration); if (deco == null) { return; } deco.DrawDecoration(batch, decoset, position, Compass.IsSideFacing(direction, Side)); } }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) { return; } TileDrawing td = DisplayCoordinates.GetPit(position); if (td == null) { return; } if (IsActivated) { //batch.FillRectangle(new Rectangle(td.Location, new Size(50, 50)), Color.Red); Decoration.Draw(batch, field.Maze.FloorPitDeco, position); } //TODO //if (td != null && !IsHidden) // batch.DrawTile(TileSet, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); }
/// <summary> /// Gets the tile id if the decoration is facing the view point /// </summary> /// <param name="position">Viewfield position</param> /// <returns>Tile id</returns> public int PrepareTile(ViewFieldPosition position) { ViewFieldPosition[] pos = new ViewFieldPosition[] { ViewFieldPosition.C, // A ViewFieldPosition.C, // B ViewFieldPosition.C, // C ViewFieldPosition.C, // D ViewFieldPosition.C, // E ViewFieldPosition.H, // F ViewFieldPosition.H, // G ViewFieldPosition.H, // H ViewFieldPosition.H, // I ViewFieldPosition.H, // J ViewFieldPosition.L, // K ViewFieldPosition.L, // L ViewFieldPosition.L, // M ViewFieldPosition.N, // N ViewFieldPosition.Team, // Team ViewFieldPosition.O, // O }; return(GetTileId(pos[(int)position])); }
/// <summary> /// Draws a simple sliding door /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="tileid">Tile id</param> /// <param name="location">Location on the screen</param> /// <param name="distance">Distance between the view point and the door</param> void DrawSimpleDoor(SpriteBatch batch, int tileid, Point location, ViewFieldPosition distance) { Vector2 scale = new Vector2(); Color color = Color.White; Point button = new Point(); switch (distance) { case ViewFieldPosition.K: case ViewFieldPosition.L: case ViewFieldPosition.M: { location.Offset(56, 16); scale = Vector2.One; button = new Point(252, 90); } break; case ViewFieldPosition.F: case ViewFieldPosition.G: case ViewFieldPosition.H: case ViewFieldPosition.I: case ViewFieldPosition.J: { location.Offset(32, 10); scale = new Vector2(0.66f, 0.66f); color = Color.FromArgb(130, 130, 130); button = new Point(230, 86); } break; case ViewFieldPosition.A: case ViewFieldPosition.B: case ViewFieldPosition.C: case ViewFieldPosition.D: case ViewFieldPosition.E: { location.Offset(12, 6); scale = new Vector2(0.50f, 0.50f); color = Color.FromArgb(40, 40, 40); button = new Point(210, 84); } break; } InternalDraw(batch, TileSet, tileid, new Point(location.X, location.Y + VPosition * 5), new Rectangle(location, new Size(144, 150)), scale, color); if (HasButton) { batch.DrawTile(TileSet, 15, button, color, 0.0f, scale, SpriteEffects.None, 0.0f); } }
/// <summary> /// Gets the screen location of a decoration if a decoration is facing the view point /// </summary> /// <param name="position">Viewfield position</param> /// <returns>On screen location</returns> public Point PrepareLocation(ViewFieldPosition position) { Point location = Point.Empty; switch (position) { case ViewFieldPosition.A: location = GetLocation(ViewFieldPosition.C); location.X += -96 * 2; break; case ViewFieldPosition.B: location = GetLocation(ViewFieldPosition.C); location.X += -96; break; case ViewFieldPosition.D: location = GetLocation(ViewFieldPosition.C); location.X += 96; break; case ViewFieldPosition.E: location = GetLocation(ViewFieldPosition.C); location.X += 96 * 2; break; case ViewFieldPosition.G: location = GetLocation(ViewFieldPosition.H); location.X += -160; break; case ViewFieldPosition.I: location = GetLocation(ViewFieldPosition.H); location.X += 160; break; case ViewFieldPosition.K: location = GetLocation(ViewFieldPosition.L); location.X -= 256; break; case ViewFieldPosition.M: location = GetLocation(ViewFieldPosition.L); location.X += 256; break; default: { location = GetLocation(position); } break; } return(location); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) return; TileDrawing td = DisplayCoordinates.GetFloorPlate(position); if (td == null) return; Decoration.Draw(batch, DecorationPrimary, position); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (TileSet == null) return; // Upstair or downstair ? int delta = Type == StairType.Up ? 0 : 13; foreach (TileDrawing tmp in DisplayCoordinates.GetStairs(position)) batch.DrawTile(TileSet, tmp.ID + delta, tmp.Location, Color.White, 0.0f, tmp.Effect, 0.0f); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="position"></param> private void ViewPositionBox_PositionChanged(object sender, ViewFieldPosition position) { if (Decoration != null) { TileIdBox.Value = Decoration.GetTileId(position); HorizontalSwapBox.Checked = Decoration.GetSwap(ViewPositionBox.Position); } else { TileIdBox.Value = -1; } }
/// <summary> /// Gets the color for distant objects /// </summary> /// <param name="position">View position</param> static public Color GetDistantColor(ViewFieldPosition position) { Color[] colors = new Color[] { Color.White, Color.White, Color.FromArgb(255, 128, 128, 128), Color.FromArgb(220, 96, 96, 96), }; return(colors[ItemScaleOffset[(int)position]]); }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <returns></returns> public bool Load(XmlNode xml) { if (xml == null || xml.Name != Tag) { return(false); } IsBlocking = bool.Parse(xml.Attributes["isblocking"].Value); ForceDisplay = bool.Parse(xml.Attributes["forcedisplay"].Value); OnHackId = int.Parse(xml.Attributes["onhack"].Value); OnBashId = int.Parse(xml.Attributes["onbash"].Value); OnClickId = int.Parse(xml.Attributes["onclick"].Value); HideItems = bool.Parse(xml.Attributes["hideitems"].Value); foreach (XmlNode node in xml) { if (node.NodeType == XmlNodeType.Comment) { continue; } if (node.Name == "item") { ItemLocation = new Point(int.Parse(node.Attributes["x"].Value), int.Parse(node.Attributes["y"].Value)); } else { try { ViewFieldPosition pos = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Name); TileId[(int)pos] = int.Parse(node.Attributes["id"].Value); if (TileId[(int)pos] != -1) { Location[(int)pos].X = int.Parse(node.Attributes["x"].Value); Location[(int)pos].Y = int.Parse(node.Attributes["y"].Value); Swap[(int)pos] = bool.Parse(node.Attributes["swap"].Value); } } catch (Exception e) { Trace.WriteLine("[Decoration]Load : Error while loading : " + e.Message); } } } return(true); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (TileSet == null) { return; } // Upstair or downstair ? int delta = Type == StairType.Up ? 0 : 13; foreach (TileDrawing tmp in DisplayCoordinates.GetStairs(position)) { batch.DrawTile(TileSet, tmp.ID + delta, tmp.Location, Color.White, 0.0f, tmp.Effect, 0.0f); } }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) { return; } TileDrawing td = DisplayCoordinates.GetFloorPlate(position); if (td == null) { return; } Decoration.Draw(batch, DecorationPrimary, position); }
/// <summary> /// Draws all alcoves according to the view point /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="field">Field of view handle</param> /// <param name="position">Position in the field of view</param> /// <param name="direction">Looking direction</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (field.Maze.Decoration == null) { return; } // For each wall side, draws the decoration foreach (CardinalPoint side in DisplayCoordinates.DrawingWallSides[(int)position]) { Alcove alcove = GetAlcove(Compass.GetDirectionFromView(direction, side)); // Get the decoration Decoration deco = field.Maze.Decoration.GetDecoration(alcove.Decoration); if (deco == null) { continue; } // Draw the decoration deco.DrawDecoration(batch, field.Maze.Decoration, position, side == CardinalPoint.South); // Hide items if (alcove.HideItems || side != CardinalPoint.South) { continue; } // Offset the item locations according to the distance Vector2 vect = DisplayCoordinates.GetMonsterScaleFactor(position); Point loc = deco.PrepareLocation(position); loc.Offset((int)(deco.ItemLocation.X * vect.X), (int)(deco.ItemLocation.Y * vect.Y)); // Draw items in the alcove in front of the team foreach (Item item in Square.GetItemsFromSide(direction, side)) { batch.DrawTile(Square.Maze.Dungeon.ItemTileSet, item.GroundTileID, loc, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), SpriteEffects.None, 0.0f); } } }
/// <summary> /// Draw the door /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="field">View field</param> /// <param name="position">Position in the view filed</param> /// <param name="view">Looking direction of the team</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (!IsVisible) { return; } TileDrawing td = DisplayCoordinates.GetTeleporter(position); if (td == null) { return; } Anim.Draw(batch, td.Location, 0.0f, SpriteEffects.None, DisplayCoordinates.GetDistantColor(position), DisplayCoordinates.GetMonsterScaleFactor(position)); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) return; TileDrawing td = DisplayCoordinates.GetPit(position); if (td == null) return; if (IsActivated) //batch.FillRectangle(new Rectangle(td.Location, new Size(50, 50)), Color.Red); Decoration.Draw(batch, field.Maze.FloorPitDeco, position); //TODO //if (td != null && !IsHidden) // batch.DrawTile(TileSet, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); }
/// <summary> /// Draws a decoration /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="id">Decoration id</param> /// <param name="position">View position</param> public void Draw(SpriteBatch batch, int id, ViewFieldPosition position) { if (batch == null || id == -1) { return; } Decoration deco = GetDecoration(id); if (deco == null) { return; } batch.DrawTile(Tileset, deco.GetTileId(position), deco.GetLocation(position), Color.White, 0.0f, deco.GetSwap(position) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0.0f); }
/// <summary> /// Draws all alcoves according to the view point /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="field">Field of view handle</param> /// <param name="position">Position in the field of view</param> /// <param name="direction">Looking direction</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (field.Maze.Decoration == null) return; // For each wall side, draws the decoration foreach (CardinalPoint side in DisplayCoordinates.DrawingWallSides[(int) position]) { Alcove alcove = GetAlcove(Compass.GetDirectionFromView(direction, side)); // Get the decoration Decoration deco = field.Maze.Decoration.GetDecoration(alcove.Decoration); if (deco == null) continue; // Draw the decoration deco.DrawDecoration(batch, field.Maze.Decoration, position, side == CardinalPoint.South); // Hide items if (alcove.HideItems || side != CardinalPoint.South) continue; // Offset the item locations according to the distance Vector2 vect = DisplayCoordinates.GetMonsterScaleFactor(position); Point loc = deco.PrepareLocation(position); loc.Offset((int) (deco.ItemLocation.X * vect.X), (int) (deco.ItemLocation.Y * vect.Y)); // Draw items in the alcove in front of the team foreach (Item item in Square.GetItemsFromSide(direction, side)) { batch.DrawTile(Square.Maze.Dungeon.ItemTileSet, item.GroundTileID, loc, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), SpriteEffects.None, 0.0f); } } }
/// <summary> /// Gets the scaling factor for distant monsters /// </summary> /// <param name="position">View position</param> static public Vector2 GetMonsterScaleFactor(ViewFieldPosition position) { return(ScaleFactor[MonsterScaleOffset[(int)position]]); }
/// <summary> /// Gets floor plate /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetFloorPlate(ViewFieldPosition view) { return FloorPlates[(int)view]; }
/// <summary> /// Get teleporter on screen coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetTeleporter(ViewFieldPosition view) { return Teleporters[(int)view]; }
/// <summary> /// Gets a ground item display coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <param name="position">Ground position</param> /// <returns>Screen location of the item</returns> static public Point GetGroundPosition(ViewFieldPosition view, SquarePosition position) { return Ground[(int)view, (int)position]; }
/// <summary> /// Get stair /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public List<TileDrawing> GetStairs(ViewFieldPosition view) { return Stairs[(int)view]; }
/// <summary> /// Gets the scaling factor for distant monsters /// </summary> /// <param name="position">View position</param> static public Vector2 GetMonsterScaleFactor(ViewFieldPosition position) { return ScaleFactor[MonsterScaleOffset[(int) position]]; }
/// <summary> /// Gets the color for distant objects /// </summary> /// <param name="position">View position</param> static public Color GetDistantColor(ViewFieldPosition position) { Color[] colors = new Color[] { Color.White, Color.White, Color.FromArgb(255, 128, 128, 128), Color.FromArgb(220, 96, 96, 96), }; return colors[ItemScaleOffset[(int) position]]; }
/// <summary> /// Draw the monster /// </summary> /// <param name="batch">SpriteBatch to use</param> /// <param name="view">View direction</param> /// <param name="pos">Position of the monster in the field of view</param> public void Draw(SpriteBatch batch, CardinalPoint view, ViewFieldPosition pos) { if (batch == null || Tileset == null || Square == null) return; // Translate subsquare position according looking point int[][] sub = new int[][] { new int[] {0,1,2,3,4}, // North new int[] {3,2,1,0,4}, // South new int[] {1,3,0,2,4}, // West new int[] {2,0,3,1,4}, // East }; // Find the good square location SquarePosition squarepos; if (Square.MonsterCount == 1) squarepos = SquarePosition.Center; else squarepos = (SquarePosition)sub[(int)view][(int)Position]; // Screen coordinate //Point position = DisplayCoordinates.GetGroundPosition(pos, squarepos); Point position = DisplayCoordinates.GetMonsterLocation(pos, squarepos); position.Offset(DisplayCoordinates.GetScaleFactor(pos, DrawOffset)); // Display color Color tint = DisplayCoordinates.GetDistantColor(pos); // Display in red if monster is hit if (LastHit + HitDisplayDuration > DateTime.Now) tint = Color.Red; // Draw batch.DrawTile(Tileset, GetTileID(view), position, tint, 0.0f, DisplayCoordinates.GetMonsterScaleFactor(pos), NeedSwapSprite(view) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0.0f); }
/// <summary> /// Gets the on screen location for a given view point /// </summary> /// <param name="position">View point position</param> /// <param name="location">Screen location</param> public void SetLocation(ViewFieldPosition position, Point location) { Location[(int)position] = location; }
/// <summary> /// Draw the actor /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="field">View field</param> /// <param name="position">Position in the view field</param> /// <param name="view">Looking direction of the team</param> public virtual void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { }
/// <summary> /// Highlight a position /// </summary> /// <param name="position">Position</param> /// <param name="state">Highlight state</param> public void HighlightPosition(ViewFieldPosition position, bool state) { ControlBoxes[(int) position].ForeColor = state ? Color.Red : Color.Black; }
/// <summary> /// Draw the door /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="field">View field</param> /// <param name="position">Position in the view filed</param> /// <param name="view">Looking direction of the team</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint view) { if (TileSet == null) return; TileDrawing td = null; TileSet wall = Square.Maze.WallTileset; // TODO: Under the door, draw sides if (field.GetBlock(ViewFieldPosition.L).IsWall && position == ViewFieldPosition.Team) { // td = DisplayCoordinates.GetDoor(ViewFieldPosition.Team); // if (td != null) // batch.DrawTile(overlay, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); if (field.Maze.Decoration != null) { field.Maze.Decoration.Draw(batch, field.Maze.DoorDeco, position); } } // Draw the door else if (((field.Maze.IsDoorNorthSouth(Square.Location) && (view == CardinalPoint.North || view == CardinalPoint.South)) || (!field.Maze.IsDoorNorthSouth(Square.Location) && (view == CardinalPoint.East || view == CardinalPoint.West))) && position != ViewFieldPosition.Team) { td = DisplayCoordinates.GetDoor(position); if (td != null) { batch.DrawTile(wall, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); //block.Door.Draw(batch, td.Location, position, view); switch (Type) { case DoorType.Grid: DrawSimpleDoor(batch, 1, td.Location, position); break; case DoorType.Forest: DrawSimpleDoor(batch, 6, td.Location, position); break; case DoorType.Iron: DrawSimpleDoor(batch, 0, td.Location, position); break; case DoorType.Monster: DrawUpDownDoor(batch, 2, td.Location, position); break; case DoorType.Azure: DrawSimpleDoor(batch, 8, td.Location, position); break; case DoorType.Crimson: DrawSimpleDoor(batch, 9, td.Location, position); break; case DoorType.Temple: DrawSimpleDoor(batch, 10, td.Location, position); break; case DoorType.Silver: DrawSimpleDoor(batch, 11, td.Location, position); break; case DoorType.Mantis: DrawSimpleDoor(batch, 12, td.Location, position); break; } } } }
/// <summary> /// /// </summary> /// <param name="location"></param> /// <param name="distance"></param> void DrawUpDownDoor(SpriteBatch batch, int tileid, Point location, ViewFieldPosition distance) { Vector2 scale = new Vector2(); Color color = Color.White; Rectangle clip = Rectangle.Empty; int[] offset = new int[2]; Point button = new Point(); switch (distance) { case ViewFieldPosition.K: case ViewFieldPosition.L: case ViewFieldPosition.M: { location.Offset(56, 14); scale = Vector2.One; clip = new Rectangle(location, new Size(144, 142)); offset[0] = VPosition * 5; offset[1] = 86 + VPosition * -2; button = new Point(252, 90); } break; case ViewFieldPosition.F: case ViewFieldPosition.G: case ViewFieldPosition.H: case ViewFieldPosition.I: case ViewFieldPosition.J: { location.Offset(28, 8); scale = new Vector2(0.66f, 0.66f); color = Color.FromArgb(130, 130, 130); clip = new Rectangle(location, new Size(104, 96)); offset[0] = VPosition * 3; offset[1] = 56 - VPosition; button = new Point(230, 86); } break; case ViewFieldPosition.A: case ViewFieldPosition.B: case ViewFieldPosition.C: case ViewFieldPosition.D: case ViewFieldPosition.E: { location.Offset(14, 4); scale = new Vector2(0.5f, 0.5f); color = Color.FromArgb(40, 40, 40); clip = new Rectangle(location, new Size(68, 60)); offset[0] = VPosition * 2; offset[1] = 36 - VPosition; button = new Point(210, 84); } break; } // Upper part InternalDraw(batch, TileSet, tileid, new Point(location.X, location.Y + offset[0]), clip, scale, color); // Lower part InternalDraw(batch, TileSet, tileid + 1, new Point(location.X, location.Y + offset[1]), clip, scale, color); // Button if (HasButton) batch.DrawTile(TileSet, 13, button, color, 0.0f, scale, SpriteEffects.None, 0.0f); }
/// <summary> /// Draws a simple sliding door /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="tileid">Tile id</param> /// <param name="location">Location on the screen</param> /// <param name="distance">Distance between the view point and the door</param> void DrawSimpleDoor(SpriteBatch batch, int tileid, Point location, ViewFieldPosition distance) { Vector2 scale = new Vector2(); Color color = Color.White; Point button = new Point(); switch (distance) { case ViewFieldPosition.K: case ViewFieldPosition.L: case ViewFieldPosition.M: { location.Offset(56, 16); scale = Vector2.One; button = new Point(252, 90); } break; case ViewFieldPosition.F: case ViewFieldPosition.G: case ViewFieldPosition.H: case ViewFieldPosition.I: case ViewFieldPosition.J: { location.Offset(32, 10); scale = new Vector2(0.66f, 0.66f); color = Color.FromArgb(130, 130, 130); button = new Point(230, 86); } break; case ViewFieldPosition.A: case ViewFieldPosition.B: case ViewFieldPosition.C: case ViewFieldPosition.D: case ViewFieldPosition.E: { location.Offset(12, 6); scale = new Vector2(0.50f, 0.50f); color = Color.FromArgb(40, 40, 40); button = new Point(210, 84); } break; } InternalDraw(batch, TileSet, tileid, new Point(location.X, location.Y + VPosition * 5), new Rectangle(location, new Size(144, 150)), scale, color); if (HasButton) batch.DrawTile(TileSet, 15, button, color, 0.0f, scale, SpriteEffects.None, 0.0f); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="position"></param> private void ViewPositionBox_PositionChanged(object sender, ViewFieldPosition position) { if (Decoration != null) { TileIdBox.Value = Decoration.GetTileId(position); HorizontalSwapBox.Checked = Decoration.GetSwap(ViewPositionBox.Position); } else TileIdBox.Value = -1; }
/// <summary> /// Gets the on screen location for a given view point /// </summary> /// <param name="position">View point position</param> /// <returns>Screen location</returns> public Point GetLocation(ViewFieldPosition position) { return(Location[(int)position]); }
/// <summary> /// Gets floor plate /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetFloorPlate(ViewFieldPosition view) { return(FloorPlates[(int)view]); }
/// <summary> /// Get the monster screen location /// </summary> /// <param name="position">ViewField position</param> /// <param name="sub">square position</param> /// <returns>Screen location</returns> static public Point GetMonsterLocation(ViewFieldPosition position, SquarePosition sub) { return MonsterLocations[(int)position][(int)sub]; }
/// <summary> /// Get teleporter on screen coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetTeleporter(ViewFieldPosition view) { return(Teleporters[(int)view]); }
/// <summary> /// Gets a draw order information /// </summary> /// <param name="position">Block position in the view field</param> /// <returns>List of drawing tiles</returns> static public TileDrawing[] GetWalls(ViewFieldPosition position) { return Walls[(int)position]; }
/// <summary> /// Gets the on screen location for a given view point /// </summary> /// <param name="position">View point position</param> /// <returns>Screen location</returns> public Point GetLocation(ViewFieldPosition position) { return Location[(int)position]; }
/// <summary> /// Gets a flying item coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <param name="ground">ground position</param> /// <returns>Screen location of the item</returns> static public Point GetFlyingItem(ViewFieldPosition view, SquarePosition ground) { return FlyingItems[(int)view, (int)ground]; }
/// <summary> /// Gets a block in the view field /// </summary> /// <param name="position">Block position</param> /// <returns>Block handle</returns> public Square GetBlock(ViewFieldPosition position) { return(Blocks[(int)position]); }
/// <summary> /// Get ceiling pit /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetCeilingPit(ViewFieldPosition view) { return CeilingPits[(int)view]; }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { // Foreach wall side foreach (TileDrawing td in DisplayCoordinates.GetWalls(position)) { // Not the good side if (Compass.GetDirectionFromView(direction, td.Side) != Side) continue; DecorationSet decoset = field.Maze.Decoration; if (decoset == null) return; Decoration deco = decoset.GetDecoration(IsActivated ? ActivatedDecoration : DeactivatedDecoration); if (deco == null) return; deco.DrawDecoration(batch, decoset, position, Compass.IsSideFacing(direction, Side)); } }
/// <summary> /// Gets door /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetDoor(ViewFieldPosition view) { return Doors[(int)view]; }
/// <summary> /// Gets a ground item display coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <param name="position">Ground position</param> /// <returns>Screen location of the item</returns> static public Point GetGroundPosition(ViewFieldPosition view, SquarePosition position) { return(Ground[(int)view, (int)position]); }
/// <summary> /// Returns a location modified by a distant scale /// </summary> /// <param name="position">View field position</param> /// <param name="point">Screen location</param> /// <returns></returns> static public Point GetScaleFactor(ViewFieldPosition position, Point point) { Vector2 vect = ScaleFactor[ItemScaleOffset[(int)position]]; return(new Point((int)(point.X * vect.X), (int)(point.Y * vect.Y))); }
/// <summary> /// Get stair /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public List <TileDrawing> GetStairs(ViewFieldPosition view) { return(Stairs[(int)view]); }
/// <summary> /// Get the monster screen location /// </summary> /// <param name="position">ViewField position</param> /// <param name="sub">square position</param> /// <returns>Screen location</returns> static public Point GetMonsterLocation(ViewFieldPosition position, SquarePosition sub) { return(MonsterLocations[(int)position][(int)sub]); }
/// <summary> /// Draws a decoration /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="id">Decoration id</param> /// <param name="position">View position</param> public void Draw(SpriteBatch batch, int id, ViewFieldPosition position) { if (batch == null || id == -1) return; Decoration deco = GetDecoration(id); if (deco == null) return; batch.DrawTile(Tileset, deco.GetTileId(position), deco.GetLocation(position), Color.White, 0.0f, deco.GetSwap(position) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0.0f); }
/// <summary> /// Gets a draw order information /// </summary> /// <param name="position">Block position in the view field</param> /// <returns>List of drawing tiles</returns> static public TileDrawing[] GetWalls(ViewFieldPosition position) { return(Walls[(int)position]); }
/// <summary> /// Draw the door /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="field">View field</param> /// <param name="position">Position in the view filed</param> /// <param name="view">Looking direction of the team</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (!IsVisible) return; TileDrawing td = DisplayCoordinates.GetTeleporter(position); if (td == null) return; Anim.Draw(batch, td.Location, 0.0f, SpriteEffects.None, DisplayCoordinates.GetDistantColor(position), DisplayCoordinates.GetMonsterScaleFactor(position)); }
/// <summary> /// Gets a flying item coordinate /// </summary> /// <param name="view">Block position in the view field</param> /// <param name="ground">ground position</param> /// <returns>Screen location of the item</returns> static public Point GetFlyingItem(ViewFieldPosition view, SquarePosition ground) { return(FlyingItems[(int)view, (int)ground]); }
/// <summary> /// Returns a location modified by a distant scale /// </summary> /// <param name="position">View field position</param> /// <param name="point">Screen location</param> /// <returns></returns> static public Point GetScaleFactor(ViewFieldPosition position, Point point) { Vector2 vect = ScaleFactor[ItemScaleOffset[(int) position]]; return new Point((int)(point.X * vect.X), (int)(point.Y * vect.Y)); }
/// <summary> /// Get ceiling pit /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetCeilingPit(ViewFieldPosition view) { return(CeilingPits[(int)view]); }
/// <summary> /// Draws a square /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="field">View field</param> /// <param name="position">Position of the square in the view field</param> /// <param name="view">Looking direction of the team</param> void DrawSquare(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint view) { if (field == null) return; Square square = field.Blocks[(int)position]; Point point; Decoration deco = null; List<Item>[] list = square.GetItems(view); #region ceiling pit if (square.IsPitTarget) { //TODO TileDrawing td = DisplayCoordinates.GetCeilingPit(position); //if (td != null) // batch.DrawTile(OverlayTileset, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); //***batch.DrawTile(ItemsTileset, td.ID, td.Location, td.SwapX, td.SwapY); } #endregion #region Items on ground before a door // If there is a deco that hide ground items, skip deco = GetDecoration(square.Location, Compass.GetOppositeDirection(view)); if (deco == null || (deco != null && !deco.HideItems)) { if (!square.IsWall || (deco != null && !deco.HideItems)) { for (int i = 0; i < 2; i++) { if (list[i].Count == 0) continue; foreach (Item item in list[i]) { point = DisplayCoordinates.GetGroundPosition(position, (SquarePosition)i); if (!point.IsEmpty) { batch.DrawTile(Dungeon.ItemTileSet, item.GroundTileID, point, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), SpriteEffects.None, 0.0f); } } } } } #endregion #region Walls if (square.IsWall) { // Walls foreach (TileDrawing tmp in DisplayCoordinates.GetWalls(position)) { Color color = Color.White; int tileid = tmp.ID; //if (swap) //{ // color = Color.Red; // tileid += 9; //} batch.DrawTile(WallTileset, tileid, tmp.Location, color, 0.0f, tmp.Effect, 0.0f); } } #endregion #region Decoration if (square.HasDecorations) { // Is there a forced decoration for (int i = 0; i < 4; i++) { deco = Decoration.GetDecoration(square.GetDecorationId((CardinalPoint)i)); if (deco != null && deco.ForceDisplay) deco.DrawDecoration(batch, Decoration, position, true); } // For each directions, draws the decoration foreach (CardinalPoint side in DisplayCoordinates.DrawingWallSides[(int)position]) { // Decoration informations deco = Decoration.GetDecoration(square.GetDecorationId(view, side)); if (deco == null) continue; deco.DrawDecoration(batch, Decoration, position, side == CardinalPoint.South); } } #endregion #region Actor if (square.Actor != null) square.Actor.Draw(batch, field, position, view); #endregion #region Items on ground after a door if (!square.IsWall) { // If there is a deco that hide ground items, skip deco = GetDecoration(square.Location, Compass.GetOppositeDirection(view)); if (deco == null || (deco != null && !deco.HideItems)) { // Both ground positions for (int i = 2; i < 4; i++) { // No items if (list[i].Count == 0) continue; // Foreach item on the ground foreach (Item item in list[i]) { // Get screen coordinate point = DisplayCoordinates.GetGroundPosition(position, (SquarePosition)i); if (!point.IsEmpty) { batch.DrawTile(Dungeon.ItemTileSet, item.GroundTileID, point, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), SpriteEffects.None, 0.0f); } } } } } #endregion #region Monsters if (square.MonsterCount > 0) { // Drawing order for monsters int[][] order = new int[][] { new int[] {0, 1, 2, 3}, // North new int[] {3, 2, 1, 0}, // South new int[] {2, 0, 3, 1}, // West new int[] {1, 3, 0, 2}, // East }; for (int i = 0; i < 4; i++) { Monster monster = square.Monsters[order[(int)view][i]]; if (monster != null) monster.Draw(batch, view, position); } } #endregion #region Flying items List<ThrownItem>[] flyings = GetFlyingItems(square.Location, view); foreach (SquarePosition pos in Enum.GetValues(typeof(SquarePosition))) { point = DisplayCoordinates.GetFlyingItem(position, pos); // if (point == Point.Empty) // continue; // Swap the tile if throwing on the right side SpriteEffects fx = SpriteEffects.None; if (pos == SquarePosition.NorthEast || pos == SquarePosition.SouthEast) fx = SpriteEffects.FlipHorizontally; foreach (ThrownItem fi in flyings[(int)pos]) batch.DrawTile(Dungeon.ItemTileSet, fi.Item.ThrowTileID, point, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), fx, 0.0f); } #endregion }
/// <summary> /// Gets door /// </summary> /// <param name="view">Block position in the view field</param> /// <returns></returns> static public TileDrawing GetDoor(ViewFieldPosition view) { return(Doors[(int)view]); }
/// <summary> /// Gets a block in the view field /// </summary> /// <param name="position">Block position</param> /// <returns>Block handle</returns> public Square GetBlock(ViewFieldPosition position) { return Blocks[(int) position]; }
/// <summary> /// Loads the maze definition /// </summary> /// <returns></returns> static public bool Load() { if (IsLoaded) { return(true); } // Load file definition using (Stream stream = ResourceManager.Load("MazeElements.xml")) { if (stream == null) { throw new FileNotFoundException("Can not find maze element coordinate file !!! Aborting."); } XmlDocument doc = new XmlDocument(); doc.Load(stream); XmlNode xml = doc.DocumentElement; if (xml.Name != "displaycoordinate") { Trace.Write("Wrong header for MazeElements file"); return(false); } foreach (XmlNode node in xml) { if (node.NodeType == XmlNodeType.Comment) { continue; } switch (node.Name.ToLower()) { case "stair": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); Stairs[(int)view].Add(GetTileDrawing(node)); } break; case "ground": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); SquarePosition ground = (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["coordinate"].Value, true); Ground[(int)view, (int)ground] = new Point(int.Parse(node.Attributes["x"].Value), int.Parse(node.Attributes["y"].Value)); } break; case "flyingitem": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); SquarePosition ground = (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["coordinate"].Value, true); FlyingItems[(int)view, (int)ground] = new Point(int.Parse(node.Attributes["x"].Value), int.Parse(node.Attributes["y"].Value)); } break; case "pit": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); Pits[(int)view] = GetTileDrawing(node); } break; case "teleporter": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); Teleporters[(int)view] = GetTileDrawing(node); } break; case "ceilingpit": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); CeilingPits[(int)view] = GetTileDrawing(node); } break; case "floorplate": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); FloorPlates[(int)view] = GetTileDrawing(node); } break; case "door": { ViewFieldPosition view = (ViewFieldPosition)Enum.Parse(typeof(ViewFieldPosition), node.Attributes["position"].Value, true); Doors[(int)view] = GetTileDrawing(node); } break; default: { Trace.WriteLine("[MazeDisplayCoordinates] Load() : Unknown element \"" + node.Name + "\"."); } break; } } } IsLoaded = true; return(true); }
/// <summary> /// Sets the tile id for a given view point /// </summary> /// <param name="position">View point position</param> /// <param name="id">Id of the tile</param> public void SetTileId(ViewFieldPosition position, int id) { TileId[(int) position] = id; }