Exemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();

            player = new Player(canvas);
            invaders = new Invaders(canvas);

            dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += Game;
            dispatcherTimer.Interval = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60);
            dispatcherTimer.Start();
        }
        //game method that fires in dispatch timer
        private void Game(object sender, object e)
        {
            //check to see if player has died
            if (!invaders.playerAlive())
            {
                //get the player score
                playerGameScore = player.getScore();

                //handle how many lives player has left
                switch (playerLives)
                {
                    case 3:
                        life3.Visibility = Visibility.Collapsed;
                        invaders.setPlayerAlive(true);
                        break;
                    case 2:

                        life2.Visibility = Visibility.Collapsed;
                        invaders.setPlayerAlive(true);
                        break;
                    case 1:
                        dispatcherTimer.Stop();
                        life1.Visibility = Visibility.Collapsed;
                        finalScoreBlock.Text = playerGameScore.ToString();
                        gameOverPanel.Visibility = Visibility.Visible;
                        sounds.playGameOverSound();
                        return;
                }

                //loss of a life and reset player and alien grid
                playerLives--;
                canvas.Children.Clear();
                invaders.rebuildInvaders(canvas);
                player = new Player(canvas, playerGameScore);
            }

            //new level upon killing of all aliens
            if (!invaders.invadersAreAlive())
            {
                level++;
                invaders = new Invaders(canvas, level);
            }

            //call the draw methods of each player and alien classes passing in requirements
            invaders.Draw(canvas, player.getPlayer(), sounds);
            player.Draw(canvas, invaders.getInvaderGrid(), sounds);

            //update score textblock
            scoreBlock.Text = player.getScore().ToString();
        }
        public GamePage()
        {
            this.InitializeComponent();

            //set preffered window size
            ApplicationView.PreferredLaunchViewSize = new Size(700, 500);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            //initialize variable for gameplay
            playerLives = 3;
            playerGameScore = 0;
            level = 1;
            
            //initiate classes
            player = new Player(canvas, playerGameScore);
            invaders = new Invaders(canvas, level);
            sounds = new Sounds(grid);

            //start the game dispatch timer
            dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += Game;
            dispatcherTimer.Interval = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 30);
            dispatcherTimer.Start();
        }
Exemplo n.º 4
0
        //Reset everything for a new round of Space Invaders.
        public void Reset()
        {
            Main.currentScore = 0;
            overallDifficulty = 0;
            levelDifficulty = 0;

            invaders = new List<Enemy>();
            invaderPosition = new List<EnemyPosition>();
            lasers = new List<Laser>();
            invaderDestroyed = new List<GraphicalObject>();
            blockFormations = new List<BlockFormation>();
            lifeMarkers = new List<GraphicalObject>();

            player = new Player("Player", new Vector2(width / 2, height - 40));
            player.GetLifeTexture();

            EnemyPosition.overallPosition = new Vector2(0, 0);

            pointText = new TextLine("Font", Main.currentScore.ToString(), Color.White, new Vector2(10, 10));

            shootNext = rand.Next(800, 2000);
            lifeMarkers.Add(new GraphicalObject("Player", new Vector2(width, 0)));
            lifeMarkers.Add(new GraphicalObject("Player", new Vector2(width, 0)));

            int blockPoint = width / 5;

            for (int i = 0; i < 4; i++)
            {
                blockFormations.Add(new BlockFormation());
                blockFormations[i].LoadContent(content, blockPoint + blockPoint * i, height);
            }

            UFO.Reset();

            NewWave(content);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.f
        /// 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
            IsMouseVisible = true;

            base.Initialize();

            // Pass often referenced variables to Global
            Global.GraphicsDevice = GraphicsDevice;
            Global.content = Content;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Global.spriteBatch = spriteBatch;

            // Aliens x amount of object on y amount of roads
            aliens = new Aliens(8, 4);
            // Player
            player = new Player(1, 1);
        }