コード例 #1
0
ファイル: Game1.cs プロジェクト: AdrianPaiva/Space-Blasters
 public void gameOver(Score score)
 {
     gameoverScreen = new GameoverScreen(this, score);
     currentScreen = Screen.GameoverScreen;
     gameScreen = null;
     scoreboardScreen = null;
     startScreen = null;
     controlsScreen = null;
 }
コード例 #2
0
        public GameoverScreen(Game1 game, Score score)
        {
            font = game.Content.Load<SpriteFont>("myFont");

            //saveScore(score);

            this.score = score;
            this.game = game;
            screenWidth = game.GraphicsDevice.Viewport.Width;
            screenHeight = game.GraphicsDevice.Viewport.Height;
            backgroundTexture = game.Content.Load<Texture2D>("spaceBackground");

            scoreButton = game.Content.Load<Texture2D>("scoreboard");
            scoreButtonPosition = new Vector2(1000, 550);
            scoreButtonRectangle = new Rectangle((int)scoreButtonPosition.X, (int)scoreButtonPosition.Y, scoreButton.Width, scoreButton.Height);
        }
コード例 #3
0
        public void Update(GameTime gameTime)
        {
            if (runTimer)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            playerShip.Update(gameTime);

            UpdateInput();

            if (playerShip.Lives == 0) // game over
            {
                runTimer = false;
                Score playerScore = new Score(timer);
                game.gameOver(playerScore);
                saveScore(playerScore);

            }

            for (int i = 0; i < playerAttackBallList.Count; i++)
            {
                playerAttackBallList[i].Update(gameTime);
                if (playerAttackBallList[i].Position.Y < -100.0f)
                    playerAttackBallList.RemoveAt(i);
            }

            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            buttonFireDelay -= elapsed;
            enemyDelay -= elapsed;

            for (int i = 0; i < enemyShipList.Count; i++)
            {
                enemyShipList[i].Update(gameTime);

                if (enemyShipList[i].Firing)
                {
                    AttackBall attackBall = new AttackBall(enemyAttackBallTexture, new Vector2(enemyShipList[i].Position.X + 10.0f, enemyShipList[i].Position.Y + 30.0f), -300.0f);
                    enemyAttackBallList.Add(attackBall);
                    enemyShipList[i].Firing = false;
                }

                int collide = enemyShipList[i].CollisionBall(playerAttackBallList);

                if (collide != -1)
                {

                    enemyShipList.RemoveAt(i);

                    playerAttackBallList.RemoveAt(collide);
                }
                else
                    if (playerShip.CollisionTest(enemyShipList[i].Position,enemyShipList[i].Radius))
                    {
                        enemyShipList.RemoveAt(i);
                    }
                    else if (enemyShipList[i].Position.Y > 2000.0f)
                    {
                        enemyShipList.RemoveAt(i);
                    }

             }

            for (int i = 0; i < enemyAttackBallList.Count; i++)
            {
                enemyAttackBallList[i].Update(gameTime);

                if (enemyAttackBallList[i].Position.Y > 900)
                {
                    enemyAttackBallList.RemoveAt(i);
                }
                else if (playerShip.CollisionTest(enemyAttackBallList[i].Position, 20.0f))
                {
                    enemyAttackBallList.RemoveAt(i);
                }

            }

            if (enemyDelay <= 0.0f)
            {
                CreateEnemy();
                enemyDelay = enemySpawnRate;
                buttonFireDelay = 0.25f;

            }

            mouseState = Mouse.GetState();

            ButtonState currState = mouseState.LeftButton;
            if (currState == ButtonState.Pressed && currState != prevState)
            {
                mousePosition = new Point(mouseState.X, mouseState.Y);
                if (quitButtonRectangle.Contains(mousePosition))
                {
                    game.quitGame();
                }

                prevState = currState;

            } if (currState == ButtonState.Released)
            {
                prevState = currState;
            }
        }
コード例 #4
0
        public void saveScore(Score s)
        {
            List<Score> scores = loadScores();
            scores.Add(s);

            //String path = System.IO.Path.GetTempPath() + @"\scoreboard.xml";
            //String path = @"C:\score.xml";
            String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\scoreboard.xml";

            FileStream stream = File.Open(path, FileMode.Create);
            try
            {
                // Convert the object to XML data and put it in the stream
                XmlSerializer serializer = new XmlSerializer(typeof(List<Score>));
                serializer.Serialize(stream, scores);

            }
            /*
            catch (IOException e)
            {

            }*/
            finally
            {

                stream.Close();
            }
        }