/// <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() { Globals.largeurFenetre = Window.ClientBounds.Width; Globals.hauteurFenetre = Window.ClientBounds.Height; Globals.Random = new Random(); Globals.IsAgainstIA = false; //Construction des sprites b1 = new Balle(1); b2 = new Balle(2); j1 = new Raquette(1); j2 = new Raquette(2); briques = new List <Brique>(); for (int i = 0; i < nbBriques; i++) { briques.Add(new Brique()); } //Initialisation des sprites b1.Initialize(); b2.Initialize(); j1.Initialize(); j2.Initialize(); foreach (Brique brique in briques) { brique.Initialize(); } //Initialisation du jeu base.Initialize(); }
//MàJ de la position de la raquette en fonction des entrées claviers public void Deplacements(Balle b1, Balle b2) { Globals.keyboardState = Keyboard.GetState(); switch (Joueur) { case 1: if (!Globals.IsAgainstIA) { if (Globals.keyboardState.IsKeyDown(Keys.Z) && Position.Y > 0) { Position.Y -= 7; } else if (Globals.keyboardState.IsKeyDown(Keys.S) && Position.Y + Texture.Height < Globals.hauteurFenetre) { Position.Y += 7; } } else { IA(b1); IA(b2); } break; case 2: if (Globals.keyboardState.IsKeyDown(Keys.Up) && Position.Y > 0) { Position.Y -= 7; } else if (Globals.keyboardState.IsKeyDown(Keys.Down) && Position.Y + Texture.Height < Globals.hauteurFenetre) { Position.Y += 7; } break; } }
public void IA(Balle balle) { //foreach(Balle balle in balles){ if (balle.Position.X < Globals.largeurFenetre / 2 && balle.Direction.X < 0) { Speed = 0.5f; if (balle.Position.Y < Position.Y) { Direction = new Vector2(0, -1); } else if (balle.Position.Y > Position.Y + Texture.Height) { Direction = new Vector2(0, 1); } if (Position.Y > 0 && Position.Y + Texture.Height < Globals.hauteurFenetre) { Position += Direction * Speed; } } else { Speed = 0; } // } }
public void VerifCollision(Balle balle) { if (Rectangle.Intersects(balle.Rectangle)) { if ((balle.Rectangle.Y - balle.Rectangle.Height <= Rectangle.Y || balle.Rectangle.Y >= Rectangle.Y + Rectangle.Height - 3) && (balle.Rectangle.X >= Rectangle.X && balle.Rectangle.X <= Rectangle.X + Rectangle.Width)) { balle.InverserY(); } else { balle.InverserX(); } balle.Speed += 0.05f; } }
public void VerifCollision(Balle balle) { if (isAlive && Rectangle.Intersects(balle.Rectangle)) { vie--; if ((balle.Rectangle.Y - balle.Rectangle.Height <= Rectangle.Y || balle.Rectangle.Y >= Rectangle.Y + Rectangle.Height - 3) && (balle.Rectangle.X >= Rectangle.X && balle.Rectangle.X <= Rectangle.X + Rectangle.Width)) { balle.InverserY(); } else { balle.InverserX(); } if (vie == 0) { isAlive = false; } } }
public void Update(GameTime gameTime, Balle b1, Balle b2) { Deplacements(b1, b2); base.Update(gameTime); }
public void IA(Balle balle) { //foreach(Balle balle in balles){ if (balle.Position.X < Globals.largeurFenetre / 2 && balle.Direction.X < 0) { Speed = 0.5f; if (balle.Position.Y < Position.Y) Direction = new Vector2(0, -1); else if (balle.Position.Y > Position.Y + Texture.Height) Direction = new Vector2(0, 1); if (Position.Y > 0 && Position.Y + Texture.Height < Globals.hauteurFenetre) Position += Direction * Speed; } else Speed = 0; // } }
public void VerifCollision(Balle balle) { if (Rectangle.Intersects(balle.Rectangle)) { if ((balle.Rectangle.Y - balle.Rectangle.Height <= Rectangle.Y || balle.Rectangle.Y >= Rectangle.Y + Rectangle.Height - 3) && (balle.Rectangle.X >= Rectangle.X && balle.Rectangle.X <= Rectangle.X + Rectangle.Width)) balle.InverserY(); else balle.InverserX(); balle.Speed += 0.05f; } }
public void VerifCollision(Balle balle) { if (isAlive && Rectangle.Intersects(balle.Rectangle)) { vie--; if((balle.Rectangle.Y - balle.Rectangle.Height <= Rectangle.Y || balle.Rectangle.Y >= Rectangle.Y + Rectangle.Height-3) && (balle.Rectangle.X >= Rectangle.X && balle.Rectangle.X <= Rectangle.X+Rectangle.Width)) balle.InverserY(); else balle.InverserX(); if (vie == 0) isAlive = false; } }