protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); background = Content.Load <Texture2D>("tlo"); blueCar = Content.Load <Texture2D>("bluecar"); greyCar = Content.Load <Texture2D>("greycar"); orangeCar = Content.Load <Texture2D>("orangecar"); greenCar = Content.Load <Texture2D>("greencar"); yellowCar = Content.Load <Texture2D>("yellowcar"); redCar = Content.Load <Texture2D>("redcar"); menu = Content.Load <Texture2D>("menu"); font = Content.Load <SpriteFont>("ArialFont"); gameOver = Content.Load <Texture2D>("gameover"); TextureList = new Dictionary <string, CarImage>(); Blue = new CarImage(blueCar, 14, 3, 11, 13); TextureList.Add("Blue", Blue); Grey = new CarImage(greyCar, 12, 3, 13, 13); TextureList.Add("Grey", Grey); Orange = new CarImage(orangeCar, 10, 6, 19, 13); TextureList.Add("Orange", Orange); Green = new CarImage(greenCar, 12, 4, 11, 9); TextureList.Add("Green", Green); Yellow = new CarImage(yellowCar, 9, 2, 16, 11); TextureList.Add("Yellow", Yellow); Red = new CarImage(redCar, 11, 5, 16, 12); TextureList.Add("Red", Red); myCar = new MyCar(new Vector2(centerOfScreen, y), TextureList); trapCar1 = new Car(new Vector2(x[0], -140), TextureList); trapCar2 = new Car(new Vector2(x[2], -280), TextureList); trapCar3 = new Car(new Vector2(x[4], -420), TextureList); }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.F2)) { stop = true; } if (Keyboard.GetState().IsKeyDown(Keys.F3)) { stop = false; } if (Keyboard.GetState().IsKeyDown(Keys.F1)) { gameover = false; level = 1; speed = 5; score = 0; myCar = new MyCar(new Vector2(centerOfScreen, y), TextureList); trapCar1 = new Car(new Vector2(x[0], -140), TextureList); trapCar2 = new Car(new Vector2(x[2], -280), TextureList); trapCar3 = new Car(new Vector2(x[4], -420), TextureList); toNextLevel = 30; stop = false; } try { myCar.CheckCollision(trapCar1); myCar.CheckCollision(trapCar2); myCar.CheckCollision(trapCar3); } catch { gameover = true; stop = true; } if (!stop) { trapCar1.ChangePosition(x, speed); trapCar2.ChangePosition(x, speed); trapCar3.ChangePosition(x, speed); if (Keyboard.GetState().IsKeyDown(Keys.Left)) { myCar.ChangePosition(0); } else if (Keyboard.GetState().IsKeyDown(Keys.Right)) { myCar.ChangePosition(1); } } if (score > toNextLevel) { level++; speed++; toNextLevel = toNextLevel * 3 / 2; } base.Update(gameTime); }