Exemplo n.º 1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            StartScreen open = new StartScreen();

            open.Show();
            this.Close();
        }
Exemplo n.º 2
0
        private void Windows_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Left: shipState = state.movingleft; break;

            case Key.Right: shipState = state.movingright; break;

            case Key.Space: shipState = state.shooting; break;

            case Key.P:
                theTimer.IsEnabled   = !theTimer.IsEnabled;
                AliensMove.IsEnabled = !AliensMove.IsEnabled;
                break;

            case Key.Escape: StartScreen open = new StartScreen(); open.Show(); this.Close(); break;
            }
        }
Exemplo n.º 3
0
        public void checkCollisions()
        {
            if (aliens.Count == 0)
            {
                lvl++;

                if (lvl < 11)
                {
                    addAliens(lvl);
                }
            }

            foreach (Bullet b in bullets)
            {
                foreach (Alien a in aliens)
                {
                    if (b.PosX >= a.PosX && (b.PosX + b.width) <= (a.width + a.PosX) && b.PosY <= a.PosY + a.height)
                    {
                        b.delete(b.identity);
                        a.delete(a.identity);
                        score       += 100;
                        textBox.Text = $"{score}";
                        aliens.Remove(a);
                        bullets.Remove(b);
                        playSound("explode");
                        break;
                    }
                }
                break;
            }

            foreach (Bullet b in alienBullets)
            {
                /* so basically it should be:
                 * left of bullet >= left of ship &&
                 * left of bullet + it's width <= left of ship + it's width &&
                 * top of bullet + height >= top of ship &&
                 * top of bullet + height <= top of ship + it's height
                 */
                double leftBull        = b.PosX;
                double rightBull       = b.PosX + b.width;
                double leftofShip      = player.PosX;
                double rightOfShip     = player.PosX + 65;
                double shipTopfromTop  = space.ActualHeight - player.PosY - 30;
                double shipBotfromTop  = space.ActualHeight - player.PosY;
                double TopofBulfromTop = b.YfromTop;
                double botofBulFromTop = b.YfromTop + 15;
                //if (b.PosX >= player.actualX - 27.5 && (b.PosX + b.width) <= player.actualX && b.PosY >= (space.ActualHeight - player.PosY) && b.PosY <= (space.ActualHeight - player.PosY + 30)) {
                if (leftBull >= leftofShip && rightBull <= rightOfShip && TopofBulfromTop >= shipTopfromTop && botofBulFromTop <= shipBotfromTop)
                {
                    b.delete(b.identity);
                    bullets.Remove(b);

                    theTimer.IsEnabled   = !theTimer.IsEnabled;
                    AliensMove.IsEnabled = !AliensMove.IsEnabled;
                    shipState            = state.GameOver;
                    MessageBox.Show("GAME OVER");
                    //highscore();
                    StartScreen open = new StartScreen(); open.Show(); this.Close();

                    break;
                }
            }
        }