/// <summary> /// Checks the map projectiles. Remove the cubes in map which was shooted /// </summary> /// <param name="tank">Tank.</param> public void CheckMapProjectiles( Tank tank) { //this nested loop maybe decrease the efficiency for (int i=map1.Cubes.Count-1; i>=0; i--) { for (int j=tank.Projectiles.Count-1; j>=0; j--) { if (map1.Cubes [i].CollisionRectangle.Intersects (tank.Projectiles[j].CollisionRectangle)) { //wall cubes gone if (map1.Cubes [i].GetType () == typeof(WallCube)) { map1.Cubes.RemoveAt (i); tank.Projectiles [j].Active = false; //when projectile do not active tank update will remove it automatically } //iron still there if (map1.Cubes [i].GetType () == typeof(IronCube)) { tank.Projectiles [j].Active = false; } //check whether the home is conquered if (map1.Cubes [i].GetType () == typeof(EagleCube)) { map1.Cubes.RemoveAt (i); // add a ruin area tank.Projectiles [j].Active = false; } } } } }
/// <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); //load back backSprite = Content.Load<Texture2D> ("back"); //font load font = Content.Load<SpriteFont> ("Arial"); score = 0; scoresString = "Scores: "; //load map map1 = new Map (Content); //Creat new objects; player1 = new Tank (Content, "Tanks4", GameConstants.PLAYER1_X, winHeight,GameConstants.PLAYER1,map1); //create explosion spriteExp = Content.Load<Texture2D> ("explosion"); //tanks.Add (new AI(Content,"MediumTanks4",GameConstants.LEFT_BOARDER,0,map1)); mediumTanks.Add(new MediumTank(Content,"MediumTanks4",GameConstants.LEFT_BOARDER,0,map1)); mediumTanks.Add(new MediumTank(Content,"MediumTanks4",GameConstants.CENTER_V,0,map1)); armoredCars.Add(new ArmoredCar(Content,"MediumTanks4",GameConstants.RIGHT_BOARDER,0,map1)); //add all in tanks tanks.AddRange (mediumTanks); tanks.AddRange (armoredCars); }