public int Shot(ref Sight sight, ref UFOList ufoList) { int shotedUFO = 0; var sightCentreVector2 = new Vector2(sight.rectangle.X + sight.rectangle.Width/2, sight.rectangle.Y + sight.rectangle.Height/2); if (Mouse.GetState().LeftButton == ButtonState.Pressed) { foreach (var ufo in ufoList) { if (ufo.rectangle.Contains(Convert.ToInt32(sightCentreVector2.X), Convert.ToInt32(sightCentreVector2.Y))) { if (ufo.state != UFOState.Fall) { ufo.state = UFOState.Fall; shotedUFO++; } } } } return shotedUFO; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); sight = new Sight(Content.Load<Texture2D>("sight"), new Rectangle(0, 0, 50, 50)); textureForUFO = Content.Load<Texture2D>("ufo"); var currentLevel = levels.currentLevel; ufoList = new UFOList(currentLevel.ufoCount, currentLevel.minSpeed, currentLevel.maxSpeed, textureForUFO, screenWidth, screenHeight); backgroundTexture2D = Content.Load<Texture2D>("background"); backgroundForWinnerTexture2D = Content.Load<Texture2D>("forWinner"); backgroundForLoserTexture2D = Content.Load<Texture2D>("forLoser"); shotSongEffect = Content.Load<SoundEffect>("shot"); shotSongInstance = shotSongEffect.CreateInstance(); flyAwaySound = Content.Load<SoundEffect>("homer"); flyAwaySoundInstance = flyAwaySound.CreateInstance(); mainSong = Content.Load<Song>("mainSong"); spriteFont = Content.Load<SpriteFont>("font1"); menu.Load(Content.Load<Texture2D>("logo"), Content.Load<Texture2D>("menuBackground"), Content.Load<Texture2D>("newGame"), Content.Load<Texture2D>("exit"), Content.Load<Song>("x-files")); }