示例#1
0
 public void Draw(SpriteBatch spriteBatch, Coord offset, Dictionary <string, Texture2D> textureDict, MapDataPack dataPack)
 {
     if (isVisible)
     {
         if (isVertical)
         {
             Coord     ScreenPos  = offset + position;
             Rectangle rectangleA = new Rectangle((ScreenPos - new Coord(8, gap - 8)).ToPoint(), new Point(16, 64 - gap));
             Rectangle rectangle1 = new Rectangle(0, 0, 32, 64 - gap);
             int       doorText1  = SpruceContentManager.newTexture2D(textureDict[textureKey].Crop(rectangle1));
             Rectangle rectangleB = new Rectangle((ScreenPos - new Coord(8, 8 - gap)).ToPoint(), new Point(16, 64 - gap));
             Rectangle rectangle2 = new Rectangle(0, 0, 32, 64 - gap);
             int       doorText2  = SpruceContentManager.newTexture2D(textureDict[textureKey].Crop(rectangle2));
             spriteBatch.Draw(SpruceContentManager.get(doorText1), rectangleA, null, Color.White, MathHelper.Pi, new Coord(32, 0).ToVector2(), SpriteEffects.None, 0);
             spriteBatch.Draw(SpruceContentManager.get(doorText2), rectangleB, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
         }
         else
         {
             Coord     ScreenPos  = offset + position;
             Rectangle rectangleA = new Rectangle((ScreenPos - new Coord(8 - gap, 8)).ToPoint(), new Point(16, 64 - gap));
             Rectangle rectangle1 = new Rectangle(0, 0, 32, 64 - gap);
             int       doorText1  = SpruceContentManager.newTexture2D(textureDict[textureKey].Crop(rectangle1));
             Rectangle rectangleB = new Rectangle((ScreenPos - new Coord(gap - 8, 8)).ToPoint(), new Point(16, 64 - gap));
             Rectangle rectangle2 = new Rectangle(0, 0, 32, 64 - gap);
             int       doorText2  = SpruceContentManager.newTexture2D(textureDict[textureKey].Crop(rectangle2));;
             spriteBatch.Draw(SpruceContentManager.get(doorText1), rectangleA, null, Color.White, MathHelper.Pi + MathHelper.PiOver2, new Coord(32, 0).ToVector2(), SpriteEffects.None, 0);
             spriteBatch.Draw(SpruceContentManager.get(doorText2), rectangleB, null, Color.White, MathHelper.PiOver2, Vector2.Zero, SpriteEffects.None, 0);
         }
     }
 }
示例#2
0
        public void DrawHitboxes(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            List <Hitbox> hitboxes = new List <Hitbox>();

            hitboxes.Add(player.hitbox.Adjust(new Coord(960, 540)));
            for (int y = 0; y < loadedLevel.height; y++)
            {
                for (int x = 0; x < loadedLevel.width; x++)
                {
                    Room thisRoom = loadedLevel.getRoom(x, y);
                    if (thisRoom != null)
                    {
                        for (int tiley = 0; tiley < thisRoom.tiles.GetLength(1); tiley++)
                        {
                            for (int tilex = 0; tilex < thisRoom.tiles.GetLength(0); tilex++)
                            {
                                Hitbox tileHitbox = thisRoom.tiles[tilex, tiley].hitbox == null ? null : thisRoom.tiles[tilex, tiley].hitbox.Adjust(new Coord(x * 512 + (tilex * 32), y * 512 + (tiley * 32)));
                                if (tileHitbox != null && (tileHitbox.rectangles[0].rectangle.Location.ToVector2() - player.pos.ToVector2()).Length() < 400)
                                {
                                    hitboxes.Add(tileHitbox.Adjust(player.pos * -1 + new Coord(960, 540)));
                                }
                            }
                        }
                    }
                }
            }
            foreach (Door door in loadedLevel.doors)
            {
                hitboxes.Add(door.hitbox.Adjust(player.pos * -1 + new Coord(960, 540)));
            }
            foreach (Hitbox hitbox in hitboxes)
            {
                foreach (SerializableRectangle serializableRectangle in hitbox.rectangles)
                {
                    Rectangle rectangleToDraw   = serializableRectangle.rectangle;
                    int       thicknessOfBorder = 2;
                    Color     borderColor       = Color.White;
                    int       pixel             = SpruceContentManager.newTexture2D(new Texture2D(graphicsDevice, 1, 1));
                    SpruceContentManager.get(pixel).SetData(new Color[] { Color.White });
                    spriteBatch.Draw(SpruceContentManager.get(pixel), new Rectangle(rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Width, thicknessOfBorder), borderColor);

                    // Draw left line
                    spriteBatch.Draw(SpruceContentManager.get(pixel), new Rectangle(rectangleToDraw.X, rectangleToDraw.Y, thicknessOfBorder, rectangleToDraw.Height), borderColor);

                    // Draw right line
                    spriteBatch.Draw(SpruceContentManager.get(pixel), new Rectangle((rectangleToDraw.X + rectangleToDraw.Width - thicknessOfBorder),
                                                                                    rectangleToDraw.Y,
                                                                                    thicknessOfBorder,
                                                                                    rectangleToDraw.Height), borderColor);
                    // Draw bottom line
                    spriteBatch.Draw(SpruceContentManager.get(pixel), new Rectangle(rectangleToDraw.X,
                                                                                    rectangleToDraw.Y + rectangleToDraw.Height - thicknessOfBorder,
                                                                                    rectangleToDraw.Width,
                                                                                    thicknessOfBorder), borderColor);
                }
            }
        }
示例#3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            SpruceContentManager.Dispose();
            GraphicsDevice.Clear(Color.Black); //MB: Clears the frame with black
            spriteBatch.Begin();               //MB: Allows drawing
            switch (gameState)                 //MB: This is where State-Dependent screen updating goes
            {
            case GameState.MainMenu:
                spriteBatch.Draw(textures["Background"], new Vector2(0, 0));                                                                                 //MB: Draws the background
                foreach (string ButtonName in new string[] { "MainMenuContinue", "MainMenuNewGame", "MainMenuLoadGame", "MainMenuOptions", "MainMenuExit" }) //MB: Draws the buttons
                {
                    menuButtons[ButtonName].Draw(spriteBatch, Mouse.GetState());
                }
                Window.Title = (gameTime.TotalGameTime.ToString() + " - " + 1 / (gameTime.ElapsedGameTime.TotalSeconds) + "FPS"); //MB: for debugging; shows game duration and fps in the title
                break;                                                                                                            //MB: This stops the thread running into the next case. Came with the switch.

            case GameState.NewGame:
                spriteBatch.Draw(textures["Background"], new Vector2(0, 0));                                   //MB: Draws the background
                foreach (string ButtonName in new string[] { "NewGameStart", "NewGameBack", "NewGameRandom" }) //MB: Draws the buttons
                {
                    menuButtons[ButtonName].Draw(spriteBatch, Mouse.GetState());
                }
                seedBox.Draw(spriteBatch);    //MB: Draws the seed textbox
                break;

            case GameState.LevelSelect:
                spriteBatch.Draw(textures["Background"], new Vector2(0, 0));    //MB: Draws the background
                foreach (UIButton button in levelSelectButtons)
                {
                    button.Draw(spriteBatch, Mouse.GetState());
                }
                break;

            case GameState.InGame:
                spriteBatch.End();
                spriteBatch.Begin(transformMatrix: screenTransform);
                loadedGame.Draw(spriteBatch, GraphicsDevice, textures, mapDataPacks); //MB: Draws the game to the screen
                spriteBatch.End();
                spriteBatch.Begin();
                break;

            case GameState.PausedInGame:
                spriteBatch.End();
                spriteBatch.Begin(transformMatrix: screenTransform);
                loadedGame.Draw(spriteBatch, GraphicsDevice, textures, mapDataPacks);    //MB: Draws the game to the screen
                spriteBatch.End();
                spriteBatch.Begin();
                spriteBatch.Draw(textures["PauseMenu"], new Vector2(PercentToX(124f / 3f), PercentToY(1933 / 54f))); //MB: Draws the background to the pause menu
                foreach (string ButtonName in new string[] { "PausedContinue", "PausedSave", "PausedExit" })         //MB: Draws the buttons
                {
                    menuButtons[ButtonName].Draw(spriteBatch, Mouse.GetState());
                }
                break;

            case GameState.LoadGame:
                break;

            case GameState.Options:
                break;

            default:
                throw new System.NotImplementedException("Invalid GameState");    //MB: This should never run, which is why it'd throw an error
            }

            spriteBatch.Draw(textures["Cursor"], new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y)); //MB: Draws the cursor at the mouse position

            spriteBatch.End();                                                                                           //MB: Drawing not allowed after this
            base.Draw(gameTime);                                                                                         //Monogame
        }