Пример #1
0
        /// <summary>
        /// Permite aos invasores dispararem.
        /// </summary>
        private void ReturnFire()
        {
            // Primeiro ele deve retornar se a lista de tiros dos invasores já possuir wave + 1
            // tiro. Ele também deve retornar se Random.Next(10) < 10 - wave (para que os invasores
            // não disparem o tempo todo). Se os testes falharem, ele pode usar LINQ para agrupar os
            // invasores por suas Location.X e ordenar usando descending. Uma vez que se tenham os
            // grupos, pode-se escolher um deles ao acaso e usar seu método First() para achar o
            // invasor mais abaixo da coluna. Então você pode adicionar um disparo na lista de tiros
            // dos invasores exatamente abaixo do meio desse invasor (usar a Area dos invasores para
            // determinar a posição do tiro).

            if (_invaderShots.Count >= _wave + 1 || _random.Next(10) < 10 - _wave)
            {
                return;
            }

            IOrderedEnumerable <IGrouping <int, Invader> > invadersQuery =
                from invader in _invaders
                group invader by invader.Location.X into invaderGroup
                orderby invaderGroup.Key descending
                select invaderGroup;
            IGrouping <int, Invader> selectedGroup = invadersQuery.ElementAt(_random.Next(1, invadersQuery.Count()));
            Invader selectedInvader = selectedGroup.First();

            _invaderShots.Add(new Shot(new Point(selectedInvader.Area.X + 3, selectedInvader.Area.Y + 5), Direction.Down, _boundaries));
        }
Пример #2
0
        public override void Update()
        {
            //move player bullet
            if (picEntity.Top > 0)
            {
                picEntity.Top -= Velocity;
            }
            else
            {
                Destroy();
            }

            //loop through each enemy to check if player bullet intersects with one of them
            foreach (Enemy Invader in List.Enemies)
            {
                if (Invader.picEntity.Visible && this.Bounds.IntersectsWith(Invader.Bounds))
                {
                    Destroy();
                    Invader.Destroy();
                    Sound.ChangeSound2URL("thunk.wav");
                    Sound.PlaySound2();
                    return;
                }
            }
        }
Пример #3
0
        public void GenerateInvader()
        {
            Random random  = new Random();
            int    x       = random.Next(10, 70);
            var    invader = new Invader(x, 0);

            Invaders.Add(invader);
        }
Пример #4
0
 private void RemoveOutOfBoundInvader(Invader invader)
 {
     if (invader != null)
     {
         Console.SetCursorPosition(invader.PositionX, invader.PositionY);
         Console.Write(' ');
     }
 }
Пример #5
0
        public void AttachToControl(CanvasAnimatedControl canvas)
        {
            _canvas         = canvas;
            _canvas.Draw   += _canvas_Draw;
            _canvas.Update += _canvas_Update;

            GameEntities.Add(new Player(this, GameSize));
            Invader.CreateInvaders(this, 24);
        }
Пример #6
0
 public static void CreateInvaders(Game game, int numberOfInvaders)
 {
     for (int i = 0; i < numberOfInvaders; i++)
     {
         var x       = 30 + (i % 8) * 30;
         var y       = 30 + (i % 3) * 30;
         var invader = new Invader(game.GameSize, new Vector2()
         {
             X = x, Y = y
         });
         game.NewGameEntities.Add(invader);
     }
 }
Пример #7
0
        public Invader GetLastInvader()
        {
            int     count      = Invaders.Length - 1;
            Invader TheInvader = Invaders[count];

            while ((TheInvader.BeenHit == true) && (count > 0))
            {
                count--;
                TheInvader = Invaders[count];
            }

            return(TheInvader);
        }
Пример #8
0
        public Invader GetFirstInvader()
        {
            int     count      = 0;
            Invader TheInvader = Invaders[count];

            while ((TheInvader.BeenHit == true) && (count < Invaders.Length - 1))
            {
                count++;
                TheInvader = Invaders[count];
            }

            return(TheInvader);
        }
Пример #9
0
        public override void OnUpdate()
        {
            Invader collidedInvader = (Invader)GameObjectManager.Instance.Collisions[this]
                                      .Where(obj => obj is Invader)
                                      .FirstOrDefault();

            if (collidedInvader != null)
            {
                GameObjectManager.Instance.Destroy(collidedInvader);
                GameObjectManager.Instance.Destroy(this);
            }
            Position += speed * direction;
        }
Пример #10
0
        private void tmrEnemy_Tick(object sender, EventArgs e)
        {
            //loop through each enemy to move and remove them
            foreach (Enemy Invader in List.Enemies)
            {
                if (Invader.Top + Invader.Height > ClientSize.Height)
                {
                    GameOver();
                }
                Invader.Update();
            }
            List.Enemies.RemoveAll(p => !p.picEntity.Visible);

            CheckLevel();
        }
Пример #11
0
        public InvaderRow(string gif1, string gif2, int rowNum)
        {
            //
            // TODO: Add constructor logic here
            //
            for (int i = 0; i < Invaders.Length; i++)
            {
              Invaders[i] = new Invader(gif1, gif2);
              Invaders[i].Position.X = i * Invaders[i].GetBounds().Width + 5;
              Invaders[i].Position.Y = rowNum * Invaders[i].GetBounds().Height + 10;
              Invaders[i].SetCounter(i*kBombIntervalSpacing);
            }

            LastPosition = Invaders[Invaders.Length - 1].Position;
        }
Пример #12
0
        public InvaderRow(string invadorColor, string bombSpeed, string gif1, string gif2, int rowNum)
        {
            //
            // TODO: Add constructor logic here
            //
            for (int i = 0; i < Invaders.Length; i++)
            {
                Invaders[i]            = new Invader(invadorColor, bombSpeed, gif1, gif2);
                Invaders[i].Position.X = i * Invaders[i].GetBounds().Width + 5;
                Invaders[i].Position.Y = rowNum * Invaders[i].GetBounds().Height + 10;
                Invaders[i].SetCounter(i * kBombIntervalSpacing);
            }

            LastPosition = Invaders[Invaders.Length - 1].Position;
        }
Пример #13
0
        /// <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);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 1; j < 9; j++)
                {
                    invaders[i, j - 1] = new Invader(i, j - 1, Content.Load <Texture2D>("Space Invaders " + j));
                }
            }


            sound = Content.Load <SoundEffect>("SI Homeworld");
        }
Пример #14
0
 public void DestroyEverything()
 {
     //destroy all entities that may already exists due to past instances
     foreach (Bullet bull in List.Bullets)
     {
         bull.Destroy();
     }
     List.Bullets.RemoveAll(p => true);
     foreach (InvaderBullet bull in List.InvaderBullets)
     {
         bull.Destroy();
     }
     List.InvaderBullets.RemoveAll(p => true);
     foreach (Enemy Invader in List.Enemies)
     {
         Invader.Destroy();
     }
     List.Enemies.RemoveAll(p => true);
 }
Пример #15
0
 public static void DrawInvader(this Graphics g, Invader invader)
 {
     g.DrawImage(invader.ActiveLook(), invader.Location);
 }
Пример #16
0
 public static bool IsDead(Invader b)
 {
     return !b.alive;
 }
Пример #17
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            camera.Init();
            ship.Init();

            invaderModel = Content.Load<Model>("cube");
            for (int j = 0; j < 10; j++)
            {
                for (int i = 0; i < 10; i++)
                {
                    int x = -4500 + i * 1000;
                    int y = -5000 - j * 1000;
                    Invader inv = new Invader(this);
                    inv.Initialize(invaderModel, Vector3.Forward, new Vector3(x, 0, y));
                    invaders.Add(inv);
                }
            }

            Invader.Bullets = new List<Bullet>();
            Invader.BulletModel = Content.Load<Model>("Cylinder");
            base.Initialize();
        }
Пример #18
0
 private void handleInvaderCollidedWithBarrier(Invader i_Invader, Barrier i_Barrier)
 {
     i_Barrier.ErasePixelsThatIntersectWith(i_Invader);
 }
Пример #19
0
 private void handleInvaderCollidedWithSpaceship(Invader i_Enemy, Spaceship i_Spaceship)
 {
     EnemyCollidedWithSpaceship.Invoke();
 }
Пример #20
0
        public override void Update()
        {
            //depending on which key is clicked, player will move in that direction
            //if player's movement exceeds form's dimensions, player would location would be set to specific locations
            if (L)
            {
                if (picEntity.Left < Velocity)
                {
                    picEntity.Left = 0;
                }
                else
                {
                    picEntity.Left -= Velocity;
                }
            }
            if (R)
            {
                if (picEntity.Left > 870 - Velocity)
                {
                    picEntity.Left = 870;
                }
                else
                {
                    picEntity.Left += Velocity;
                }
            }
            if (U)
            {
                if (picEntity.Top < 415 + Velocity)
                {
                    picEntity.Top = 415;
                }
                else
                {
                    picEntity.Top -= Velocity;
                }
            }
            if (D)
            {
                if (picEntity.Top > 570 - Velocity)
                {
                    picEntity.Top = 570;
                }
                else
                {
                    picEntity.Top += Velocity;
                }
            }

            //loop through each invader bullet to check if they intersect with player
            foreach (InvaderBullet bull in List.InvaderBullets)
            {
                if (bull.Bounds.IntersectsWith(this.Bounds))
                {
                    Destroy();
                    return;
                }
            }
            foreach (Enemy Invader in List.Enemies)
            {
                if (Invader.Bounds.IntersectsWith(this.Bounds))
                {
                    Destroy();
                    Invader.Destroy();
                    return;
                }
            }
        }