public override void Update(GameTime theTime) { if (Keyboard.GetState().IsKeyDown(Keys.P) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { ScreenEvent.Invoke(this, new EventArgs()); return; } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { if (isGameOver == true) { StartGame(); } } if (!isGameOver) { foreach (Heli heli in textureAtlases.helis) { if (heli.isLive) { heli.Update(theTime); if (plane.Location.Intersects(heli.Location)) { isGameOver = true; } } } foreach (Ship ship in textureAtlases.ships) { if (ship.isLive) { ship.Update(theTime); if (plane.Location.Intersects(ship.Location)) { isGameOver = true; } } } foreach (Fuel fuel in textureAtlases.fuels) { if (fuel.isLive) { fuel.Update(theTime); if (plane.Location.Intersects(fuel.Location)) { fuel.isLive = false; if (plane.Fuel + 20 >= 100) { plane.Fuel = 100; } else { plane.Fuel += 20; } } } } foreach (Bullet bullet in plane.bullets) { bullet.Update(theTime); foreach (Heli heli in textureAtlases.helis) { if (heli.isLive && !bullet.isRemoved && bullet.Location.Intersects(heli.Location)) { heli.isLive = false; bullet.isRemoved = true; } } foreach (Ship ship in textureAtlases.ships) { if (ship.isLive && !bullet.isRemoved && bullet.Location.Intersects(ship.Location)) { ship.isLive = false; bullet.isRemoved = true; } } foreach (Fuel fuel in textureAtlases.fuels) { if (fuel.isLive && !bullet.isRemoved && bullet.Location.Intersects(fuel.Location)) { fuel.isLive = false; bullet.isRemoved = true; } } } plane.Update(theTime); foreach (Map map in textureAtlases.Maps) { map.Update(); //Console.WriteLine(textureAtlases.Maps[0,0].Location); //Console.WriteLine(plane.Location); if (map.Location.Y <= 720 - map.Location.Height && map.Location.Y >= 720 - 2 * map.Location.Height) { if (IntersectsPixel(plane.Location, plane.TextureData, map.Location, map.TextureData)) { isGameOver = true; } } } } }
public override void Update(GameTime theTime) { if (Keyboard.GetState().IsKeyDown(Keys.P) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { ScreenEvent.Invoke(this, new EventArgs()); return; } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { if (isGameOver == true) { StartGame(); } } if (!isGameOver) { //foreach (Heli heli in textureAtlases.helis) //{ // if (heli.isLive) // { // heli.Update(theTime); // if (plane.Location.Intersects(heli.Location)) // isGameOver = true; // } //} //foreach (Ship ship in textureAtlases.ships) //{ // if (ship.isLive) // { // ship.Update(theTime); // if (plane.Location.Intersects(ship.Location)) // isGameOver = true; // } //} //foreach (Fuel fuel in textureAtlases.fuels) //{ // if (fuel.isLive) // { // fuel.Update(theTime); // if (plane.Location.Intersects(fuel.Location)) // { // fuel.isLive = false; // if (plane.Fuel + 20 >= 100) // plane.Fuel = 100; // else // plane.Fuel += 20; // } // } //} //foreach (Bullet bullet in plane.bullets) //{ // bullet.Update(theTime); // foreach (Heli heli in textureAtlases.helis) // { // if (heli.isLive && !bullet.isRemoved && bullet.Location.Intersects(heli.Location)) // { // heli.isLive = false; // bullet.isRemoved = true; // } // } // foreach (Ship ship in textureAtlases.ships) // { // if (ship.isLive && !bullet.isRemoved && bullet.Location.Intersects(ship.Location)) // { // ship.isLive = false; // bullet.isRemoved = true; // } // } // foreach (Fuel fuel in textureAtlases.fuels) // { // if (fuel.isLive && !bullet.isRemoved && bullet.Location.Intersects(fuel.Location)) // { // fuel.isLive = false; // bullet.isRemoved = true; // } // } //} plane.Update(theTime); foreach (Map map in textureAtlases.Maps) { map.Update(); } } }