00001
00002
00003
00004
00005
00006 namespace AvatarChooser
00007 {
00008 using System;
00009 using System.Collections.Generic;
00010 using System.Linq;
00011 using Microsoft.Xna.Framework;
00012 using Microsoft.Xna.Framework.Audio;
00013 using Microsoft.Xna.Framework.Content;
00014 using Microsoft.Xna.Framework.GamerServices;
00015 using Microsoft.Xna.Framework.Graphics;
00016 using Microsoft.Xna.Framework.Input;
00017 using Microsoft.Xna.Framework.Media;
00018 using Microsoft.Xna.Framework.Net;
00019 using Microsoft.Xna.Framework.Storage;
00020
00021 using NewGamePhysics.GraphicalElements;
00022 using NewGamePhysics.Utilities;
00023
00027 public class AvatarChooser : Microsoft.Xna.Framework.Game
00028 {
00029 GraphicsDeviceManager graphics;
00030 SpriteBatch spriteBatch;
00031 Effect invertEffect;
00032 Screenshot screenshot;
00033
00034 const int numFractals = 9;
00035 const int gridstep = 3;
00036 const int gridsize = 300;
00037 GumowskiMiraFractal[] fractals = new GumowskiMiraFractal[numFractals];
00038 private int mouseScroll = 0;
00039 private int currentIndex = -1;
00040 private Boolean released = false;
00041 private Boolean iterated = false;
00042
00043
00044 double[] parameters = new double[]
00045 {
00046 0.008, -0.7, 0, 0.5, 0.03, 3000000,
00047 0.008, -0.8, 0, 0.5, 0.024, 3000000,
00048 0.008, -0.9, 0, 0.5, 0.019, 3000000,
00049
00050 0, -0.15, 0, 0.5, 0.03, 10000000,
00051 0, -0.2, 0.5, 0.0, 0.03, 10000000,
00052 0, -0.22, 0, 0.5, 0.016, 10000000,
00053
00054 0, -0.31, 0, 0.5, 0.008, 5000000,
00055 0, -0.55, 0, 0.5, 0.02, 5000000,
00056 0, -0.23, 0, 0.5, 0.02, 4000000,
00057 };
00058
00059 public AvatarChooser()
00060 {
00061 graphics = new GraphicsDeviceManager(this);
00062 Content.RootDirectory = "Content";
00063 graphics.PreferredBackBufferWidth = gridsize * gridstep;
00064 graphics.PreferredBackBufferHeight = gridsize * gridstep;
00065 this.IsMouseVisible = true;
00066 }
00067
00074 protected override void Initialize()
00075 {
00076 base.Initialize();
00077 this.screenshot = new Screenshot();
00078 }
00079
00084 protected override void LoadContent()
00085 {
00086
00087 this.spriteBatch = new SpriteBatch(GraphicsDevice);
00088 invertEffect = Content.Load<Effect>(@"Effects\Invert");
00089
00090 for (int i = 0; i < numFractals; i++)
00091 {
00092 fractals[i] = new GumowskiMiraFractal(GraphicsDevice, gridsize, gridsize,
00093 parameters[0 + 6 * i],
00094 parameters[1 + 6 * i],
00095 parameters[2 + 6 * i],
00096 parameters[3 + 6 * i]);
00097 fractals[i].Scale = (float)parameters[4 + 6 * i];
00098 }
00099 }
00100
00105 protected override void UnloadContent()
00106 {
00107
00108 }
00109
00115 protected override void Update(GameTime gameTime)
00116 {
00117
00118 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
00119 this.Exit();
00120
00121
00122 KeyboardState keyboardState = Keyboard.GetState();
00123 MouseState mouseState = Mouse.GetState();
00124 int mouseX = mouseState.X;
00125 int mouseY = mouseState.Y;
00126 double relX = (2.0 * (double)((mouseX % gridsize) - gridsize / 2)) / gridsize;
00127 double relY = (2.0 * (double)((mouseY % gridsize) - gridsize / 2)) / gridsize;
00128 int index = (mouseX / gridsize) + (mouseY / gridsize) * gridstep;
00129 this.currentIndex = -1;
00130 if ((index >= 0) && (index < numFractals))
00131 {
00132 this.currentIndex = index;
00133 if (this.released)
00134 {
00135 if ((mouseState.LeftButton == ButtonState.Pressed) ||
00136 (mouseState.RightButton == ButtonState.Pressed))
00137 {
00138 if (mouseState.LeftButton == ButtonState.Pressed)
00139 {
00140 fractals[index].Mu = fractals[index].Mu + 0.001;
00141 }
00142 else
00143 {
00144 fractals[index].Mu = fractals[index].Mu - 0.001;
00145 }
00146 fractals[index].Reset(relX, relY);
00147 this.iterated = false;
00148 this.released = false;
00149 }
00150
00151
00152 if (this.mouseScroll != mouseState.ScrollWheelValue)
00153 {
00154 fractals[index].Scale = fractals[index].Scale + 0.00001f * (this.mouseScroll - mouseState.ScrollWheelValue);
00155 this.mouseScroll = mouseState.ScrollWheelValue;
00156 fractals[index].Reset(relX, relY);
00157 this.iterated = false;
00158 this.released = false;
00159 }
00160
00161
00162
00163 if (keyboardState.IsKeyDown(Keys.PrintScreen))
00164 {
00165 screenshot.TakeScreenshot(GraphicsDevice);
00166 this.released = false;
00167 }
00168 }
00169 else
00170 {
00171 if ((mouseState.LeftButton == ButtonState.Released) &&
00172 (mouseState.RightButton == ButtonState.Released) &&
00173 (keyboardState.GetPressedKeys().Length == 0))
00174 {
00175 this.released = true;
00176 this.mouseScroll = mouseState.ScrollWheelValue;
00177 }
00178 }
00179 }
00180
00181
00182
00183 if (!this.iterated)
00184 {
00185 this.iterated = true;
00186 for (int i = 0; i < numFractals; i++)
00187 {
00188 int toIterate = (int)parameters[5 + 6 * i];
00189 if (fractals[i].Iterations < toIterate)
00190 {
00191 this.iterated = false;
00192 fractals[i].Iterate(10000);
00193 }
00194 }
00195 }
00196
00197 base.Update(gameTime);
00198 }
00199
00204 protected override void Draw(GameTime gameTime)
00205 {
00206 GraphicsDevice.Clear(Color.CornflowerBlue);
00207
00208 this.spriteBatch.Begin();
00209 for (int i = 0; i < numFractals; i++)
00210 {
00211 Color currentColor = Color.White;
00212 this.spriteBatch.Draw(fractals[i].ImageTexture, new Vector2(gridsize * (i % gridstep), gridsize * (i / gridstep)), currentColor);
00213 }
00214 this.spriteBatch.End();
00215
00216 base.Draw(gameTime);
00217 }
00218 }
00219 }