Exemple #1
0
 Vector2 RandomSet(bool firstGen = false)
 {
     if (firstGen)
     {
         return(new Vector2(Asteroids.GetIntRnd(0, Asteroids.screenWidth), Asteroids.GetIntRnd(0, Asteroids.screenHeight)));
     }
     else
     {
         return(new Vector2(Asteroids.GetIntRnd(Asteroids.screenWidth, Asteroids.screenWidth + 300), Asteroids.GetIntRnd(0, Asteroids.screenHeight)));
     }
 }
Exemple #2
0
 public void StarShipCollide(Vector2 StarShipDir)
 {
     //Pos.X += 10;
     //Dir.X = -Dir.X;
     //Dir.Y = Asteroids.GetIntRnd(1, 5);
     if (StarShipDir.X == 0)
     {
         Dir.X = -Dir.X;
     }
     else
     {
         Dir.X = StarShipDir.X / 2;
     }
     if (StarShipDir.Y == 0)
     {
         Dir.Y = Asteroids.GetIntRnd(-3, 3);
     }
     else
     {
         Dir.Y = StarShipDir.Y / 2;
     }
 }
Exemple #3
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);

            SplashScreen.Background = Content.Load <Texture2D>("img/SplashScreenImg2");    // картинка для заставки
            SplashScreen.HeaderFont = Content.Load <SpriteFont>("fonts/SplashScreenFont"); // шрифт для главных надписей
            SplashScreen.TextFont   = Content.Load <SpriteFont>("fonts/TextFont");         // шрифт для остальных надписей
            GameOver.Background     = Content.Load <Texture2D>("img/GameOver");            // картинка для заставки
            GameOver.HeaderFont     = Content.Load <SpriteFont>("fonts/TextFont");         // шрифт для главных надписей
            GameOver.TextFont       = Content.Load <SpriteFont>("fonts/LittleFont");       // шрифт для остальных надписей

            Asteroids.Init(spriteBatch, screenWidth, screenHeight);
            Background.Texture2D = Content.Load <Texture2D>("spriteMaps/Backgrounds");
            Star.Texture2D       = Content.Load <Texture2D>("spriteMaps/SpriteMapStars");
            StarShip.Texture2D   = Content.Load <Texture2D>("spriteMaps/spaceship");
            Engine.Texture2D     = Content.Load <Texture2D>("spriteMaps/JetStreamSprite");
            BigFire.Texture2D    = Content.Load <Texture2D>("spriteMaps/PlazmaBullet");
            Asteroid.Texture2D   = Content.Load <Texture2D>("spriteMaps/Asteroids");
            Blast.Texture2D      = Content.Load <Texture2D>("spriteMaps/blast");
            // TODO: use this.Content to load your game content here
        }
Exemple #4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            switch (stat)
            {
            case States.SplashScreen:
                SplashScreen.Draw(spriteBatch);
                break;

            case States.Game:
                Asteroids.Draw();
                break;

            case States.GameOver:
                GameOver.Draw(spriteBatch);
                Asteroids.Reset();
                break;
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemple #5
0
 Vector2 RandomSet()
 {
     return(new Vector2(Asteroids.GetIntRnd(Asteroids.screenWidth, Asteroids.screenWidth + 300), Asteroids.GetIntRnd(frameWidth, Asteroids.screenHeight - frameWidth)));
 }
Exemple #6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            switch (stat)
            {
            case States.Game:
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    stat = States.SplashScreen;
                }
                Asteroids.Update();
                if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W))
                {
                    Asteroids.StarShip1.Up();
                }
                if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S))
                {
                    Asteroids.StarShip1.Down();
                }
                if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A))
                {
                    Asteroids.StarShip1.Left();
                }
                if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D))
                {
                    Asteroids.StarShip1.Right();
                }
                if ((keyboardState.IsKeyDown(Keys.Space)) || (mouseState.LeftButton == ButtonState.Pressed))
                {
                    Asteroids.Shoot();
                }
                if ((keyboardState.IsKeyUp(Keys.Space)) && (mouseState.LeftButton == ButtonState.Released))
                {
                    Asteroids.fireTimerCounter = 0;
                }

                if (Asteroids.StarShip1.Strength < 1)
                {
                    stat = States.GameOver;
                }
                break;

            case States.SplashScreen:
                SplashScreen.Update();
                if (keyboardState.IsKeyDown(Keys.Space) || (mouseState.LeftButton == ButtonState.Pressed))
                {
                    stat = States.Game;
                }
                break;

            case States.GameOver:
                GameOver.Update();
                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    Asteroids.StarShip1.Strength = 100;
                    stat = States.Game;
                }
                break;
            }

            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            base.Update(gameTime);
            currentGameTime = gameTime;
        }