示例#1
0
 public int TileFrom(Point position, int type)
 {
     if (position.X < 0 || position.Y < 0 || position.X >= ChunkWidth || position.Y >= ChunkHeight)
     {
         return(0);
     }
     try
     {
         return(Tiles[position.X, position.Y, type]);
     }
     catch (Exception e)
     {
         Debug.WriteLine(position.ToString());
         return(0);
     }
 }
示例#2
0
        public override void Draw(SpriteBatch sb)
        {
            GraphicsDevice.Clear(Color.Gray);
            base.Draw(sb);

            Viewport vp = GraphicsDevice.Viewport;

            Point tl = new Point(vp.X, vp.Y);
            Point tr = new Point(vp.X+vp.Width, vp.Y);
            Point bl = new Point(vp.X, vp.Y+vp.Height);
            Point br = new Point(vp.X+vp.Width, vp.Y+vp.Height);

            bool coords = displayMode != 0;
            string tlString = coords ? tl.ToString() : "Top Left";
            Vector2 tlOrigin = Vector2.Zero;
            string trString = coords ? tr.ToString() : "Top Right";
            Vector2 trOrigin = new Vector2(UIFont.MeasureString(trString).X.Floor(), 0);
            string blString = coords ? bl.ToString() : "Bottom Left";
            Vector2 blOrigin = new Vector2(0, UIFont.MeasureString(blString).Y.Floor());
            string brString = coords ? br.ToString() : "Bottom Right";
            Vector2 brOrigin = UIFont.MeasureString(brString).Floor();

            sb.Begin();

            Color cornerColor = displayMode == 2 ? Color.White : Color.White * 0.5f;
            sb.Draw(corner, tl.AsVector2(), null, cornerColor, 0, Vector2.Zero, 1f, SpriteEffects.None, 0);
            sb.Draw(corner, tr.AsVector2(), null, cornerColor, 0, new Vector2(corner.Width, 0), 1f, SpriteEffects.FlipHorizontally, 0);
            sb.Draw(corner, bl.AsVector2(), null, cornerColor, 0, new Vector2(0, corner.Height), 1f, SpriteEffects.FlipVertically, 0);
            sb.Draw(corner, br.AsVector2(), null, cornerColor, 0, corner.Size(), 1f, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically, 0);

            if(displayMode != 2)
            {
                Color textColor = Color.Yellow;
                sb.DrawString(UIFont, tlString, tl.AsVector2(), textColor, 0, tlOrigin, 1, SpriteEffects.None, 0);
                sb.DrawString(UIFont, trString, tr.AsVector2(), textColor, 0, trOrigin, 1, SpriteEffects.None, 0);
                sb.DrawString(UIFont, blString, bl.AsVector2(), textColor, 0, blOrigin, 1, SpriteEffects.None, 0);
                sb.DrawString(UIFont, brString, br.AsVector2(), textColor, 0, brOrigin, 1, SpriteEffects.None, 0);

                sb.DrawString(UIFont, GraphicsDevice.PresentationParameters.DisplayOrientation.ToString(),
                        vp.Bounds.Center.AsVector2(), Color.Yellow);
            }
            sb.End();
        }
示例#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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            foreach (Block b in worldElements)
            {
                b.Draw(spriteBatch);
            }

            foreach (Entity e in liveEntities)
            {
                e.Draw(spriteBatch);
            }

            foreach (IUserInterfaceElement uiElement in uiElementList)
            {
                uiElement.Draw(spriteBatch);
            }

            // Draw Mouse Position
            Point mousePos = new Point(lastMouseState.X, lastMouseState.Y);

            #if WINDOWS || XBOX
            spriteBatch.DrawString(sliderFont, "Mouse Pos:" + mousePos.ToString(), Vector2.Zero, Color.White);
            spriteBatch.DrawString(sliderFont, "Player Energy: " + Player.Energy.ToString(), new Vector2(0, 16), Color.White);
            spriteBatch.DrawString(sliderFont, "Entity Count: " + liveEntities.Count.ToString(), new Vector2(0, 32), Color.White);
            #endif // WINDOWS || XBOX

            if (IsPaused)
            {
            #if WINDOWS || XBOX
                if (Player.isAlive)
                {
                    spriteBatch.DrawString(sliderFont, "Paused", new Vector2(380, 280), Color.Blue);
                }
                else
                {
                    spriteBatch.DrawString(sliderFont, "GAME OVER", new Vector2(380, 280), Color.Red);
                }
            #endif // WINDOWS || XBOX
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }