/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControl_Resize(object sender, EventArgs e) { if (DesignMode) { return; } GlControlBox.MakeCurrent(); Display.ViewPort = new Rectangle(new Point(), GlControlBox.Size); }
/// <summary> /// Form loading /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControlBox_Load(object sender, EventArgs e) { if (DesignMode) { return; } GlControlBox.MakeCurrent(); Display.Init(); // Spritebatch Batch = new SpriteBatch(); // Preload background texture resource CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png")); CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat; CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat; // Preload texture resources Icons = new TileSet(); Icons.Texture = new Texture2D(ResourceManager.GetInternalResource("DungeonEye.Forms.data.editor.png")); int id = 0; for (int y = 0; y < Icons.Texture.Size.Height - 50; y += 25) { for (int x = 0; x < Icons.Texture.Size.Width; x += 25) { Tile tile = Icons.AddTile(id++); tile.Rectangle = new Rectangle(x, y, 25, 25); } } Icons.AddTile(100).Rectangle = new Rectangle(0, 245, 6, 11); // alcoves Icons.AddTile(101).Rectangle = new Rectangle(6, 248, 11, 6); // alcoves ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); DrawTimer.Start(); }
/// <summary> /// Draws the maze /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControl_Paint(object sender, PaintEventArgs e) { if (DesignMode) { return; } GlControlBox.MakeCurrent(); Display.ClearBuffers(); Batch.Begin(); // Background texture Rectangle dst = new Rectangle(Point.Empty, GlControlBox.Size); Batch.Draw(CheckerBoard, dst, dst, Color.White); if (Maze != null) { // Blocks for (int y = 0; y < Maze.Size.Height; y++) { for (int x = 0; x < Maze.Size.Width; x++) { Square block = Maze.GetSquare(new Point(x, y)); Point location = new Point(x, y); Color color = Color.White; if (block.Type == SquareType.Illusion) { color = Color.LightGreen; } Batch.DrawTile(Icons, block.Type == SquareType.Ground ? 1 : 0, new Point(Offset.X + x * 25, Offset.Y + y * 25)); if (block.ItemCount > 0) { Batch.DrawTile(Icons, 19, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor != null) { // Doors if (block.Actor is Door) { Door door = block.Actor as Door; int tileid = 0; if (Maze.IsDoorNorthSouth(location)) { tileid = 3; } else { tileid = 2; } // Door opened or closed if (door.State == DoorState.Broken || door.State == DoorState.Opened || door.State == DoorState.Opening) { tileid += 2; } Batch.DrawTile(Icons, tileid, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor is PressurePlate) { Batch.DrawTile(Icons, 18, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor is Pit) { Batch.DrawTile(Icons, 19, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor is Teleporter) { Batch.DrawTile(Icons, 11, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor is ForceField) { ForceField field = block.Actor as ForceField; int id; if (field.Type == ForceFieldType.Spin) { id = 12; } else if (field.Type == ForceFieldType.Move) { id = 13 + (int)field.Direction; } else { id = 17; } Batch.DrawTile(Icons, id, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } if (block.Actor is Stair) { Stair stair = block.Actor as Stair; Batch.DrawTile(Icons, stair.Type == StairType.Up ? 6 : 7, new Point(Offset.X + x * 25, Offset.Y + y * 25)); } /* * // Alcoves * if (block.HasAlcoves) * { * // Alcoves coords * Point[] alcoves = new Point[] * { * new Point(7, 0), * new Point(7, 19), * new Point(0, 7), * new Point(19, 7), * }; * * * foreach (CardinalPoint side in Enum.GetValues(typeof(CardinalPoint))) * { * if (block.HasAlcove(side)) * { * Batch.DrawTile(Icons, 100 + ((int) side > 1 ? 0 : 1), * new Point(Offset.X + x * 25 + alcoves[(int) side].X, * Offset.Y + y * 25 + alcoves[(int) side].Y)); * * } * } * } */ } // Draw monsters if (block.HasMonster) { Batch.DrawTile(Icons, 8, new Point(Offset.X + location.X * 25, Offset.Y + location.Y * 25)); } } } // Target if (Target.Maze == Maze.Name) { Batch.DrawRectangle(new Rectangle(Offset.X + Target.Coordinate.X * 25, Offset.Y + Target.Coordinate.Y * 25, 25, 25), Color.White); } } Batch.End(); GlControlBox.SwapBuffers(); }