source: 2014/30/MikkoI/frakt/frakt/frakt/Game1.cs @ 5558

Revision 5558, 4.0 KB checked in by mijoilmo, 6 years ago (diff)

a

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Microsoft.Xna.Framework;
5using Microsoft.Xna.Framework.Audio;
6using Microsoft.Xna.Framework.Content;
7using Microsoft.Xna.Framework.GamerServices;
8using Microsoft.Xna.Framework.Graphics;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Media;
11
12namespace frakt
13{
14    /// <summary>
15    /// This is the main type for your game
16    /// </summary>
17    public class WooooFract : Microsoft.Xna.Framework.Game
18    {
19        GraphicsDeviceManager graphics;
20        SpriteBatch spriteBatch;
21        Vector2 viewportSize;
22
23        Texture2D pixel;
24
25        public WooooFract()
26        {
27            graphics = new GraphicsDeviceManager(this);
28            Content.RootDirectory = "Content";
29        }
30
31        /// <summary>
32        /// Allows the game to perform any initialization it needs to before starting to run.
33        /// This is where it can query for any required services and load any non-graphic
34        /// related content.  Calling base.Initialize will enumerate through any components
35        /// and initialize them as well.
36        /// </summary>
37        protected override void Initialize()
38        {
39            // TODO: Add your initialization logic here
40            pixel = new Texture2D(GraphicsDevice, 1, 1);
41            pixel.SetData(new UInt32[] { UInt32.MaxValue });
42            base.Initialize();
43
44            startRender();
45        }
46
47        /// <summary>
48        /// LoadContent will be called once per game and is the place to load
49        /// all of your content.
50        /// </summary>
51        protected override void LoadContent()
52        {
53            // Create a new SpriteBatch, which can be used to draw textures.
54            spriteBatch = new SpriteBatch(GraphicsDevice);
55
56            // TODO: use this.Content to load your game content here
57        }
58
59        /// <summary>
60        /// UnloadContent will be called once per game and is the place to unload
61        /// all content.
62        /// </summary>
63        protected override void UnloadContent()
64        {
65            // TODO: Unload any non ContentManager content here
66        }
67
68        /// <summary>
69        /// Allows the game to run logic such as updating the world,
70        /// checking for collisions, gathering input, and playing audio.
71        /// </summary>
72        /// <param name="gameTime">Provides a snapshot of timing values.</param>
73        protected override void Update(GameTime gameTime)
74        {
75            // Allows the game to exit
76            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
77                this.Exit();
78
79            // TODO: Add your update logic here
80
81            base.Update(gameTime);
82        }
83
84        void startRender()
85        {
86            viewportSize.X = Window.ClientBounds.Width;
87            viewportSize.Y = Window.ClientBounds.Height;
88        }
89
90        /// <summary>
91        /// This is called when the game should draw itself.
92        /// </summary>
93        /// <param name="gameTime">Provides a snapshot of timing values.</param>
94        Color getColor(int index, int size)
95        {
96            Color[] palette = { new Color(0, 0, 0), new Color(255, 0, 0), new Color(255, 255, 0), new Color(0, 255, 0), new Color(0, 255, 255), new Color(0, 0, 255), new Color(0, 0, 0) };
97            index = index % size;
98            size--;
99            float realIndex = (index / size) * (palette.Length - 1);
100            Color col1 = palette[(int)Math.Floor(realIndex)];
101            Color col2 = palette[(int)Math.Ceiling(realIndex)];
102            float rel = realIndex - (float)Math.Floor(realIndex);
103            return Color.Lerp(col1, col2, rel);
104        }
105        protected override void Draw(GameTime gameTime)
106        {
107            GraphicsDevice.Clear(Color.White);
108            // TODO: Add your drawing code here
109
110            spriteBatch.Begin();
111
112            spriteBatch.Draw(pixel, new Vector2(0, 0), Color.Black);
113            spriteBatch.End();
114
115            base.Draw(gameTime);
116        }
117    }
118}
Note: See TracBrowser for help on using the repository browser.