示例#1
0
        public void Render(SpriteBatch spriteBatch, Citysim game, GameTime gameTime)
        {
            World world = game.city.world;

            int cameraX = (int)game.camera.position.X;
            int cameraY = (int)game.camera.position.Y;

            // Loop through tiles.
            for (int z = 0; z < World.depth; z++)
            {
                for (int y = 0; y < world.height; y++)
                {
                    for (int x = 0; x < world.width; x++)
                    {
                        ITile tile = game.tileRegistry.GetTile(world.tiles[x, y, z]);
                        if (tile == null)
                        {
                            continue; // unknown tile
                        }
                        Rectangle tileRect = new Rectangle(cameraX + x * tileSize, cameraY + y * tileSize, tileSize * tile.GetTileSize().X, tileSize * tile.GetTileSize().Y);

                        spriteBatch.Draw(tile.GetTexture(gameTime), tileRect, Color.White);
                    }
                }
            }

            if (world.InBounds(game.camera.hovering))
            {
                // Draw hitbox
                int hitX = (int)(game.camera.hovering.X * tileSize + game.camera.position.X);
                int hitY = (int)(game.camera.hovering.Y * tileSize + game.camera.position.Y);
                spriteBatch.Draw(hitbox, new Rectangle(hitX, hitY, tileSize, tileSize), Color.White);
            }
        }
示例#2
0
        public void Render(SpriteBatch spriteBatch, Citysim game, GameTime gameTime)
        {
            int   width  = game.GraphicsDevice.Viewport.Width;
            int   height = game.GraphicsDevice.Viewport.Height;
            float scale  = 1.0F;

            int fontHeight = (int)(game.gameFont.MeasureString("Aap123#").Y);

            AddStat("Cash", "$" + game.city.world.cash.ToString() + "k");

            // Draw stats
            foreach (string[] stat in stats)
            {
                string label = stat[0];
                string value = stat[1];

                int     stringFullSize = (int)(game.gameFont.MeasureString(label + ": " + value).X *scale);
                int     labelSize      = (int)(game.gameFont.MeasureString(label + ": ").X *scale);
                Vector2 labelDrawPos   = new Vector2(width - stringFullSize - 10, 10);
                Vector2 valueDrawPos   = new Vector2(width - (stringFullSize - labelSize) - 10, 10);

                spriteBatch.DrawString(game.gameFont, label + ": ", labelDrawPos, Color.Black);
                spriteBatch.DrawString(game.gameFont, value, valueDrawPos, Color.Yellow);
            }
        }
示例#3
0
 public void Update(Citysim game, GameTime gameTime)
 {
     // F3 toggles debug mode
     if (KeyboardHelper.IsKeyPressed(Keys.F3))
     {
         game.debug = !game.debug;
     }
 }
示例#4
0
 /// <summary>
 /// Update views.
 /// Should be run every update loop.
 /// </summary>
 /// <param name="game">Game instance</param>
 /// <param name="gameTime">Game time</param>
 public void Update(Citysim game, GameTime gameTime)
 {
     foreach (IView view in views)
     {
         if (view != null)
         {
             view.Update(game, gameTime);
         }
     }
 }
示例#5
0
 /// <summary>
 /// Render views.
 /// This should be run every draw loop.
 /// </summary>
 /// <param name="game">Game instance</param>
 /// <param name="spriteBatch">Spritebatch to draw to</param>
 /// <param name="gameTime">Game time</param>
 public void Render(Citysim game, SpriteBatch spriteBatch, GameTime gameTime)
 {
     foreach (IView view in views)
     {
         if (view != null)
         {
             view.Render(spriteBatch, game, gameTime);
         }
     }
 }
示例#6
0
        public void Render(SpriteBatch spriteBatch, Citysim game, GameTime gameTime)
        {
            if (!game.debug)
            {
                return; // Debug mode disabled
            }
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Citysim " + Citysim.VERSION);
            sb.AppendLine("Map size " + game.city.world.height + "x" + game.city.world.width);
            sb.AppendLine("Camera: " + game.camera.position.X + "," + game.camera.position.Y + " [" + game.camera.speed + "]");
            sb.AppendLine("Absolute Mouse Position: " + game.camera.hoveringExact.X + "," + game.camera.hoveringExact.Y);
            sb.AppendLine("Selected Tile: " + game.camera.hovering.X + "," + game.camera.hovering.Y);

            spriteBatch.DrawString(game.font, sb, new Vector2(10, 10), Color.Black, 0F, new Vector2(0, 0), 0.5F, SpriteEffects.None, 1.0F);
        }
示例#7
0
 public void Update(Citysim game, GameTime gameTime)
 {
     if (game.city.world.InBounds(game.camera.hovering.X, game.camera.hovering.Y) && game.debug)
     {
         MouseState mouseState = Mouse.GetState();
         if (mouseState.LeftButton == ButtonState.Pressed)
         {
             //game.city.world.tiles[(int)game.camera.hovering.X, (int)game.camera.hovering.Y, 9] = Tile.tileLargeTest.id;
             game.city.world.PlaceTile(Tile.tileNuclearReactor.id, new Vector3(game.camera.hovering.X, game.camera.hovering.Y, 9));
         }
         else if (mouseState.RightButton == ButtonState.Pressed)
         {
             //game.city.world.tiles[(int)game.camera.hovering.X, (int)game.camera.hovering.Y, 9] = 0;
             game.city.world.RemoveTile(new Vector3(game.camera.hovering.X, game.camera.hovering.Y, 9));
         }
     }
 }
示例#8
0
 public void Update(Citysim game, GameTime gameTime)
 {
 }