/// <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> public override void Update(GameTime gameTime) { Rectangle myCarRect = myCar.getBounds(); // When my car and race cars collide, foreach (RaceCar raceCar in raceCars) { Rectangle raceCarRect = raceCar.getBounds(); if (myCarRect.Intersects(raceCarRect)) { Game1.bAlive = false; } } // When my car take off the line, int nPosition = myCar.getPositionX(); if (nPosition < 90 || nPosition > 390) { Game1.bAlive = false; } base.Update(gameTime); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (!Game1.bAlive) { if (!bExplode) { bExplode = true; Game1.startSound.Stop(); Game1.bReady = false; RemoveCars(); //int nPos = myCar.getPositionX(); explode.setImgShow(myCar.getPositionX()); myCar.setPositionX(-100); // Hidden myCar } if (Game1.bReady) { newGameStart(); } } else { Game1.startSound.Play(); if (nInterval > nMaxInterval) { GenRaceCars(); // Generate race cars SetLevel(); // Setting level and Animation Speed nInterval = 0; } else { nInterval++; } } base.Update(gameTime); }