Guest User

Untitled

a guest
Jul 16th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Color;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Audio;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Input;
  12. using Microsoft.Xna.Framework.Media;
  13.  
  14. namespace Collision
  15. {
  16.     /// <summary>
  17.     /// This is the main type for your game
  18.     /// </summary>
  19.     public class Game1 : Microsoft.Xna.Framework.Game
  20.     {
  21.         GraphicsDeviceManager graphics;
  22.         SpriteBatch spriteBatch;
  23.         Texture2D texture;
  24.         Texture2D textureTransparent;
  25.         Texture2D piecealive;
  26.         Texture2D piecedead;
  27.         Texture2D whatever;
  28.  
  29.         SpriteFont testFont;
  30.  
  31.         Microsoft.Xna.Framework.Color colour;
  32.  
  33.         Array KnownColor;
  34.         string value;
  35.         List<string> colors = new List<string>();
  36.         Vector2 pos;
  37.  
  38.         public Game1()
  39.         {
  40.             graphics = new GraphicsDeviceManager(this);
  41.             Content.RootDirectory = "Content";
  42.         }
  43.  
  44.         protected override void Initialize()
  45.         {  
  46.             base.Initialize();
  47.         }
  48.  
  49.         protected override void LoadContent()
  50.         {
  51.             // Create a new SpriteBatch, which can be used to draw textures.
  52.             spriteBatch = new SpriteBatch(GraphicsDevice);
  53.  
  54.             texture = Content.Load<Texture2D>(@"Images/logo");
  55.             textureTransparent = Content.Load<Texture2D>(@"Images/logo_trans");
  56.             piecealive = Content.Load<Texture2D>(@"Images/piece_alive");
  57.             piecedead = Content.Load<Texture2D>(@"Images/piece_dead");
  58.             testFont = Content.Load<SpriteFont>(@"Fonts/Test");
  59.             whatever = Content.Load<Texture2D>(@"Images/Bitmap1");
  60.  
  61.             GetColors();
  62.  
  63.         }
  64.  
  65.         protected override void UnloadContent()
  66.         {
  67.         }
  68.  
  69.         protected override void Update(GameTime gameTime)
  70.         {
  71.             // Allows the game to exit
  72.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  73.                 this.Exit();
  74.  
  75.             Random rand = new Random();
  76.  
  77.             CreateRandomColour();
  78.  
  79.             base.Update(gameTime);
  80.         }
  81.  
  82.         protected override void Draw(GameTime gameTime)
  83.         {
  84.  
  85.             GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White);
  86.  
  87.             spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
  88.             for (int i = 0; i < 256; i++)
  89.             {
  90.                 pos.Y = i * 2;
  91.                 for (int j = 0; j < 256; j++)
  92.                 {
  93.                    
  94.                     System.Drawing.Color SColor = System.Drawing.Color.FromName(value);
  95.                     colour = new Microsoft.Xna.Framework.Color(SColor.R, SColor.G, SColor.B, SColor.A);
  96.                    
  97.                     pos.X = j * 2;
  98.                    
  99.                     Microsoft.Xna.Framework.Graphics.SpriteBatch.Draw(whatever,
  100.                     pos,
  101.                     colour);
  102.  
  103.                 }
  104.             }
  105.             spriteBatch.End();
  106.  
  107.             base.Draw(gameTime);
  108.         }
  109.  
  110.         private String CreateRandomColour()
  111.         {
  112.             Random random = new Random();
  113.             int index = random.Next(0, colors.Count); // list.Count for List<T>
  114.             value = colors[index]; // where array is string[]
  115.  
  116.             return value;
  117.         }
  118.  
  119.         private List<string> GetColors()
  120.         {
  121.             string[] colorNames = Enum.GetNames(typeof(KnownColor));
  122.             foreach (string colorName in colorNames)
  123.             {
  124.                 KnownColor knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), colorName);
  125.                 colors.Add(colorName);
  126.             }
  127.             return colors;
  128.         }
  129.     }
  130. }
Add Comment
Please, Sign In to add comment