//----------------------------------------------------------------------------- // Overriden methods //----------------------------------------------------------------------------- protected override void Draw() { Graphics2D g = new Graphics2D(spriteBatch); //g.SetRenderTarget(GameData.RenderTargetGame); g.Begin(GameSettings.DRAW_MODE_DEFAULT); g.Clear(Color.White); g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value)); g.Translate(-Tileset.SpriteSheet.Offset); g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero); Point2I tilePoint = SelectedTile * (Tileset.SpriteSheet.CellSize + Tileset.SpriteSheet.Spacing); g.ResetTranslation(); g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value)); g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.SpriteSheet.CellSize + 1), 1, Color.White); g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.SpriteSheet.CellSize - 1), 1, Color.Black); g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.SpriteSheet.CellSize + 3), 1, Color.Black); g.ResetTranslation(); g.End(); }
// Draw an entire level. public void DrawLevel(Graphics2D g) { g.Clear(new Color(175, 175, 180)); // Gray background. // Draw the level if it is open. if (editorControl.IsLevelOpen) { // Draw the rooms. for (int x = 0; x < Level.Width; x++) { for (int y = 0; y < Level.Height; y++) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); g.Translate((Vector2F)(new Point2I(x, y) * ((Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing))); DrawRoom(g, Level.GetRoomAt(x, y)); g.ResetTranslation(); } } // Draw the highlight box. if (editorControl.HighlightMouseTile && cursorTileLocation >= Point2I.Zero) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); Rectangle2I box = new Rectangle2I(GetLevelTileCoordDrawPosition(cursorTileLocation), new Point2I(16, 16)); g.DrawRectangle(box.Inflated(1, 1), 1, Color.White); g.ResetTranslation(); } // Draw selection grid. if (selectionGridLevel == Level && !selectionGridArea.IsEmpty) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); if (selectionGrid != null) { for (int i = 0; i < selectionGrid.LayerCount; i++) { for (int y = 0; y < selectionGrid.Height; y++) { for (int x = 0; x < selectionGrid.Width; x++) { Point2I position = GetLevelTileCoordDrawPosition(selectionGridArea.Point + new Point2I(x, y)); TileDataInstance tile = selectionGrid.GetTileIfAtLocation(x, y, i); // Draw tile. if (tile != null) DrawTile(g, tile, position, Color.White); } } } // Draw event tiles. if (editorControl.ShowEvents || editorControl.ShouldDrawEvents) { for (int i = 0; i < selectionGrid.EventTiles.Count; i++) { Point2I position = GetLevelTileCoordDrawPosition(selectionGridArea.Point) + selectionGrid.EventTiles[i].Position; DrawEventTile(g, selectionGrid.EventTiles[i], position, Color.White); } } } // Draw the selection box. if (!selectionBox.IsEmpty) { Point2I start = GetLevelPixelDrawPosition(selectionBox.TopLeft); Point2I end = GetLevelPixelDrawPosition(selectionBox.BottomRight); Rectangle2I box = new Rectangle2I(start, end - start); g.DrawRectangle(box, 1, Color.White); g.DrawRectangle(box.Inflated(1, 1), 1, Color.Black); g.DrawRectangle(box.Inflated(-1, -1), 1, Color.Black); } g.ResetTranslation(); } // Draw selected tiles. foreach (BaseTileDataInstance tile in selectedTiles) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); Rectangle2I bounds = tile.GetBounds(); bounds.Point += GetRoomDrawPosition(tile.Room); g.DrawRectangle(bounds, 1, Color.White); g.DrawRectangle(bounds.Inflated(1, 1), 1, Color.Black); g.DrawRectangle(bounds.Inflated(-1, -1), 1, Color.Black); g.ResetTranslation(); } // Draw player sprite for 'Test At Position' Point2I roomSize = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing; Point2I tilePoint = highlightedRoom * roomSize + highlightedTile * GameSettings.TILE_SIZE; if (editorControl.PlayerPlaceMode && highlightedTile >= Point2I.Zero) { g.DrawSprite(GameData.SPR_PLAYER_FORWARD, (Vector2F) tilePoint + new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); } } }
//----------------------------------------------------------------------------- // Overriden methods //----------------------------------------------------------------------------- protected override void Draw() { Graphics2D g = new Graphics2D(spriteBatch); //g.SetRenderTarget(GameData.RenderTargetGame); g.Begin(GameSettings.DRAW_MODE_DEFAULT); Point2I selectedTileLocation = GetSelectedTileLocation(); // Draw the tileset. g.Clear(Color.White); g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value); if (Tileset.SpriteSheet == null) { // Draw each tile's sprite seperately. for (int y = 0; y < Tileset.Height; y++) { for (int x = 0; x < Tileset.Width; x++) { BaseTileData tileData = Tileset.GetTileData(x, y); if (tileData != null) { int spacing = 1; Vector2F drawPos = new Vector2F(x, y) * (Tileset.CellSize + spacing); SpriteAnimation spr = tileData.Sprite; int imageVariantID = tileData.Properties.GetInteger("image_variant", Zone.ImageVariantID); if (imageVariantID < 0) imageVariantID = Zone.ImageVariantID; if (spr.IsAnimation) { int substripIndex = tileData.Properties.GetInteger("substrip_index", 0); spr.Animation = spr.Animation.GetSubstrip(substripIndex); } g.DrawAnimation(tileData.Sprite, imageVariantID, 0.0f, drawPos, Color.White); } } } } else { // Draw the spritesheet's image. g.Translate(-Tileset.SpriteSheet.Offset); g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero); g.ResetTranslation(); } // Draw the selection box. if (selectedTileLocation >= Point2I.Zero) { Point2I tilePoint = selectedTileLocation * (Tileset.CellSize + Tileset.Spacing); g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value); g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.CellSize + 1), 1, Color.White); g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.CellSize - 1), 1, Color.Black); g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.CellSize + 3), 1, Color.Black); g.ResetTranslation(); } g.End(); }
// Draw an entire level. public void DrawLevel(Graphics2D g) { g.Clear(new Color(175, 175, 180)); // Draw the level if it is open. if (editorControl.IsLevelOpen) { // Draw the rooms. for (int x = 0; x < Level.Width; x++) { for (int y = 0; y < Level.Height; y++) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); g.Translate((Vector2F)(new Point2I(x, y) * ((Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing))); DrawRoom(g, Level.GetRoomAt(x, y)); g.ResetTranslation(); } } // Draw the highlight box. if (editorControl.HighlightMouseTile && cursorTileLocation >= Point2I.Zero) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); Rectangle2I box = new Rectangle2I(GetLevelTileCoordDrawPosition(cursorTileLocation), new Point2I(16, 16)); g.DrawRectangle(box.Inflated(1, 1), 1, Color.White); g.ResetTranslation(); } // Draw the selection box. if (!selectionBox.IsEmpty) { g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value)); Point2I start = GetLevelTileCoordDrawPosition(selectionBox.TopLeft); Point2I end = GetLevelTileCoordDrawPosition(selectionBox.BottomRight); Rectangle2I box = new Rectangle2I(start, end - start); g.DrawRectangle(box, 1, Color.White); g.DrawRectangle(box.Inflated(1, 1), 1, Color.Black); g.DrawRectangle(box.Inflated(-1, -1), 1, Color.Black); g.ResetTranslation(); } // Draw player sprite for 'Test At Position' Point2I roomSize = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing; Point2I tilePoint = highlightedRoom * roomSize + highlightedTile * GameSettings.TILE_SIZE; if (editorControl.PlayerPlaceMode && highlightedTile >= Point2I.Zero) { g.DrawSprite(GameData.SPR_PLAYER_FORWARD, tilePoint); } } }
//----------------------------------------------------------------------------- // Drawing //----------------------------------------------------------------------------- // Called every step to draw the game. public void Draw(Graphics2D g) { g.UseIntegerPrecision = true; // Render the game-state stack to a buffer. g.SetRenderTarget(GameData.RenderTargetGame); g.Begin(GameSettings.DRAW_MODE_DEFAULT); g.Clear(Color.Black); gameStateStack.Draw(g); g.End(); // Draw the buffer to the screen scaled. g.SetRenderTarget(null); g.ResetTranslation(); g.Begin(GameSettings.DRAW_MODE_DEFAULT); g.DrawImage(GameData.RenderTargetGame, Vector2F.Zero, Vector2F.Zero, (Vector2F) gameScale, 0.0); g.End(); }