1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
| using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
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 MSC_2010_BREIDENSTEIN;
namespace CogMR
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class CogMR : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Function Funct;
SingleClick FunctClick;
MouseState MStat;
//-----------------------------------------------------Déclarations-----------------------------------------------//
//Rectangle de sélection dans le fichier du sprite (où est l'image à afficher)
Rectangle srcImg, srcImgLvl, srcSeparateur, srcFleche, srcSym, srcFond, srcChrono;
// FR : Bouttons pour les transformations
Button btnFlecheD, btnFlecheG, btnSymH, btnSymV;
//Objet texture qui sera chargé
Texture2D sprite, spriteModif, separateur, fond, chrono;
SpriteFont ChronoTxt;
//Rectangle de destination : où l'image sera affichée sur l'écran et sa taille
Rectangle dstOrigine, dstSeparateur, dstModif, dstFond, dstChrono;
//Si on veut faire tourner le sprite
float rotation = 0;
//Symétries
SpriteEffects Transformation = SpriteEffects.None;
//Résolution d'écran
public static int SCREEN_WIDTH = 800;
public static int SCREEN_HEIGHT = 600;
//Etat du Jeu (switch, voir Update())
int iEtat = 1, iText;
//Etat du clavier
KeyboardState KState;
//Compteurs de transformations
public int iRotatRight, iRotatLeft, iSymVer, iSymHor;
//Déclaration du stream
Stream sImg; //sSave;
Stream sImgLvl;
msc_data ConfigMR, Level;
//Extension des images
string stExtension = ".png";
//Nom de l'image à charger
string stLoadImg = ".\\Images\\";
string stLoadLevel = ".\\Images\\Level\\";
float fTime = 0;
public int iLvl = 1;
//----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------Fonctions--------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------//
public CogMR()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//Résolutaion d'écran
graphics.PreferredBackBufferWidth = SCREEN_WIDTH;
graphics.PreferredBackBufferHeight = SCREEN_HEIGHT;
//Afficher la souris
IsMouseVisible = true;
Window.Title = "Jeu des rotations";
//CogMR_Login CogMR_Login = new CogMR_Login();
//CogMR_Login.ShowDialog();
}
/// <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
//Ouverture fichier *.csv
ConfigMR = new msc_data(@".\Fichiers CSV\", "ConfigMR.csv");
Level = new msc_data(@".\Fichiers CSV\", "Level.csv");
//Rectangle dans lequel sera l'image
srcImg = new Rectangle(0, 0, 150, 150); //Rectangle pour le cactus
srcImgLvl = new Rectangle(0, 0, 50,50);
srcSeparateur = new Rectangle(0, 0, 2, 600); //Rectangle pour le séparateur
srcFleche = new Rectangle(0, 0, 50, 50); //Rectangle pour les flêches
srcSym = new Rectangle(0, 0, 50, 50); //Rectangle pour les symétries
srcFond = new Rectangle(0, 0, 800, 600);
srcChrono = new Rectangle(0, 0, 90, 100);
// FR : Placement de l'image à modifier
Point MilieuR = new Point((SCREEN_WIDTH * 3 / 4), (SCREEN_HEIGHT / 2));
Point CoinR = new Point(MilieuR.X - (srcImg.Width / 2), MilieuR.Y - (srcImg.Height / 2));
// FR : Placement de l'image d'origine
Point MilieuL = new Point((SCREEN_WIDTH * 3 / 8), (SCREEN_HEIGHT / 2));
Point CoinL = new Point(MilieuL.X - (srcImg.Width / 2), MilieuL.Y - (srcImg.Height / 2));
//Lieu d'aparition de l'image
dstSeparateur = new Rectangle(399, 0, 2, 600);
dstOrigine = new Rectangle(CoinL.X, CoinL.Y, srcImgLvl.Width, srcImgLvl.Height);
dstModif = new Rectangle(CoinR.X, CoinR.Y, srcImg.Width, srcImg.Height);
dstFond = new Rectangle(0, 0, srcFond.Width, srcFond.Height);
dstChrono = new Rectangle(55, 10, srcChrono.Width, srcChrono.Height);
btnFlecheD = new Button(new Vector2(40, 240));
btnFlecheG = new Button(new Vector2(110, 240));
btnSymH = new Button(new Vector2(40, 310));
btnSymV = new Button(new Vector2(110, 310));
Funct = new Function();
FunctClick = new SingleClick();
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);
// TODO: use this.Content to load your game content here
//Chargement de l'image de jeu : Effectuer une recherche du nom de l'image dans un fichier *.csv pour la charger dynamiquement
stLoadImg += String.Concat(Funct.LoadLvl(Level, iLvl), stExtension);
sImg = File.OpenRead(@stLoadImg);
spriteModif = Texture2D.FromStream(GraphicsDevice, sImg);
stLoadLevel += String.Concat(Funct.LoadLvl(Level, iLvl), stExtension);
sImgLvl = File.OpenRead(@stLoadLevel);
sprite = Texture2D.FromStream(GraphicsDevice, sImgLvl);
fond = Content.Load<Texture2D>("fond");
separateur = Content.Load<Texture2D>("separateur");
/*Stream sImg2;
sImg2 = File.OpenRead(@".\Images\flecheD.png");
flecheD.Texture = Texture2D.FromStream(GraphicsDevice, sImg2);*/
btnFlecheD.Texture = Content.Load<Texture2D>("flecheD");
btnFlecheG.Texture = Content.Load<Texture2D>("flecheG");
btnSymH.Texture = Content.Load<Texture2D>("SymH");
btnSymV.Texture = Content.Load<Texture2D>("SymV");
ChronoTxt = Content.Load<SpriteFont>("SpriteFont");
chrono = Content.Load<Texture2D>("chrono");
}
/// <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
if (File.Exists(@"Images\Temp\1.jpg") == true)
{
File.Delete(@"Images\Temp\1.jpg");
}
Funct.SaveRLeft(ConfigMR, Convert.ToString(iRotatLeft));
Funct.SaveRRight(ConfigMR, Convert.ToString(iRotatRight));
Funct.SaveSHorizontally(ConfigMR, Convert.ToString(iSymHor));
Funct.SaveSVertically(ConfigMR, Convert.ToString(iSymVer));
Funct.SaveTime(ConfigMR, Convert.ToString(fTime));
}
/// <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
KState = Keyboard.GetState();
MStat = Mouse.GetState();
if (KState.IsKeyDown(Keys.Escape)) this.Exit();
//Funct.SaveSprite(sprite, 0, SpriteEffects.None, spriteBatch, GraphicsDevice);
int i;
i = Funct.SolvRotaL(Level, iLvl);
// TODO: Add your update logic here
switch (iEtat)
{
case 1:
if (FunctClick.Click(MStat, btnFlecheD))
{
iEtat = 2;
}
if (FunctClick.Click(MStat, btnFlecheG))
{
iEtat = 3;
}
if (FunctClick.Click(MStat, btnSymH))
{
iEtat = 4;
}
if (FunctClick.Click(MStat, btnSymV))
{
iEtat = 5;
}
break;
case 2: //Rotation vers la droite
rotation += (float)((Math.PI) / 2);
iRotatRight++;
iEtat = 1;
break;
case 3: //Rotation vers la gauche
rotation += (float)-((Math.PI) / 2);
iRotatLeft++;
iEtat = 1;
break;
case 4: //Sym Horizontally
Transformation = SpriteEffects.FlipVertically;
iSymVer++;
//spriteModif = Funct.SaveSprite(spriteModif, 0, Transformation, spriteBatch, ConfigMR, GraphicsDevice);
iEtat = 1;
break;
case 5: //Sym Vertically
Transformation = SpriteEffects.FlipHorizontally;
iSymHor++;
//spriteModif = Funct.SaveSprite(spriteModif, 0, Transformation, spriteBatch, ConfigMR, GraphicsDevice);
iEtat = 1;
break;
}
iText++;
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);
//fTime += gameTime.ElapsedGameTime.Seconds;
fTime += gameTime.TotalGameTime.Seconds;
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(fond, dstFond, srcFond, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
spriteBatch.Draw(chrono, dstChrono, srcChrono, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
Funct.DrawChrono(ChronoTxt, Convert.ToString(iText), spriteBatch);
spriteBatch.Draw(separateur, dstSeparateur, srcSeparateur, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
btnFlecheD.Draw(spriteBatch);
btnFlecheG.Draw(spriteBatch);
btnSymH.Draw(spriteBatch);
btnSymV.Draw(spriteBatch);
spriteBatch.Draw(sprite, dstOrigine, srcImgLvl, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
spriteBatch.Draw(spriteModif, dstModif, srcImg, Color.White, rotation, Vector2.Zero, Transformation, 1.0f);
spriteBatch.End();
base.Draw(gameTime);
}
}
} |
Partager