C# - Minimap Tut (part 1) - #xna

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
 
namespace Minimap_Tut
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D MinimapTex;
 
        Color MinimapBGCol = new Color(150, 150, 150, 150);
        Rectangle MinimapBGRect = new Rectangle(10, 10, 110, 110);
 
        Rectangle NextMinimapItem = new Rectangle(0, 0, 3, 3);
 
        List<Vector2> Enemies = new List<Vector2>();
        List<Vector2> Allies = new List<Vector2>();
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
 
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
 
            base.Initialize();
        }
 
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
 
 
            MinimapTex = new Texture2D(graphics.GraphicsDevice, 1, 1);
            Color[] texcol = new Color[1];
            MinimapTex.GetData(texcol);
            texcol[0] = Color.White;
            MinimapTex.SetData(texcol);
 
            Random rand = new Random();
            for (int i = 0; i < 5; i++)
            {
                Enemies.Add(new Vector2(rand.Next(1, 100), rand.Next(1, 100)));
                Allies.Add(new Vector2(rand.Next(1, 100), rand.Next(1, 100)));
            }
            // TODO: use this.Content to load your game content here
        }
 
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
 
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
 
            // TODO: Add your update logic here
 
            base.Update(gameTime);
        }
 
        /// <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);
 
            // TODO: Add your drawing code here
            spriteBatch.Begin();
 
            spriteBatch.Draw(MinimapTex, MinimapBGRect, MinimapBGCol);
 
            foreach (Vector2 tmp in Allies)
            {
                NextMinimapItem.X = (int)tmp.X + 9;
                NextMinimapItem.Y = (int)tmp.Y + 9;
                spriteBatch.Draw(MinimapTex, NextMinimapItem, Color.Blue);
            }
            foreach (Vector2 tmp in Enemies)
            {
                NextMinimapItem.X = (int)tmp.X + 9;
                NextMinimapItem.Y = (int)tmp.Y + 9;
                spriteBatch.Draw(MinimapTex, NextMinimapItem, Color.Red);
            }
 
 
            spriteBatch.End();
 
            base.Draw(gameTime);
        }
    }
}

User login

Powered by Drupal, an open source content management system

Random image

Worm Hole 3