예제 #1
0
        // 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));
                }
            }
        }
예제 #2
0
        // 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);
                }
            }
        }