示例#1
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);
            background  = new Sprite(Content.Load <Texture2D>("images/background"), new Vector2(0, 0), Vector2.Zero, false, 0.0f, 1f, SpriteEffects.None, null);
            startScreen = new Sprite(Content.Load <Texture2D>("images/StartScreen"), new Vector2(0, 0), Vector2.Zero, false, 0.0f, 1f, SpriteEffects.None, null);
            endScreen   = new Sprite(Content.Load <Texture2D>("images/WinScreen"), new Vector2(0, 0), Vector2.Zero, false, 0.0f, 1f, SpriteEffects.None, null);
            loseScreen  = new Sprite(Content.Load <Texture2D>("images/EndScreen"), new Vector2(0, 0), Vector2.Zero, false, 0.0f, 1f, SpriteEffects.None, null);
            Mage        = new Mage(Content, "images/MageRed", new Vector2(250, FLOOR - 31));
            Mage2       = new Player2(Content, new Vector2(350, FLOOR - 31));
            ShadowBat.Add(new ShadowBat(Content, random, GraphicsDevice));

            backSong          = Content.Load <SoundEffect>("Audio/HeroicAge");
            BackSong          = backSong.CreateInstance();
            BackSong.IsLooped = true;
            BackSong.Play();

            arial = Content.Load <SpriteFont>("Fonts/Arial");
        }
示例#2
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            switch (gameState)
            {
            case GameState.Start:
                updateSplash();
                break;

            case GameState.GameOver:
                updateSplash();
                break;

            case GameState.Lose:
                updateSplash();
                break;

            case GameState.Play:
                Mage.Update(gameTime, GraphicsDevice);
                Mage2.Update(gameTime, GraphicsDevice);
                foreach (Sprite enemy in ShadowBat)
                {
                    for (int j = 0; j < magic.Count; j++)
                    {
                        if (enemy.CollisionSprite(magic[j]))
                        {
                            enemy.Alive = false;
                            magic.RemoveAt(j);
                            totalScore += SCORE;
                            if (totalScore >= 100)
                            {
                                gameState = GameState.GameOver;
                            }
                        }
                    }
                }
                foreach (Sprite enemy in ShadowWalker)
                {
                    if (enemy.CollisionSprite(Mage))
                    {
                        enemy.Alive = false;
                        Mage.Alive  = false;
                        gameState   = GameState.Lose;
                    }
                    for (int j = 0; j < magic.Count; j++)
                    {
                        if (enemy.CollisionSprite(magic[j]))
                        {
                            enemy.Alive = false;
                            magic.RemoveAt(j);
                            totalScore += SCORE;
                            if (totalScore >= 100)
                            {
                                gameState = GameState.GameOver;
                            }
                        }
                    }
                }
                for (int i = 0; i < ShadowBat.Count; i++)
                {
                    if (ShadowBat[i].Velocity.X > 0)
                    {
                        ShadowBat[i].SpriteEffect = SpriteEffects.FlipHorizontally;
                    }
                    else
                    {
                        ShadowBat[i].SpriteEffect = SpriteEffects.None;
                    }
                    ShadowBat[i].Update(gameTime, GraphicsDevice);
                }
                float elapsed = (float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                timeSince += elapsed;
                if (timeSince >= SPAWN_TIME)
                {
                    ShadowBat.Add(new ShadowBat(Content, random, GraphicsDevice));
                    timeSince = 0;
                }
                for (int i = 0; i < ShadowWalker.Count; i++)
                {
                    if (ShadowWalker[i].Velocity.X > 0)
                    {
                        ShadowWalker[i].SpriteEffect = SpriteEffects.None;
                    }
                    else
                    {
                        ShadowWalker[i].SpriteEffect = SpriteEffects.FlipHorizontally;
                    }
                    ShadowWalker[i].Update(gameTime, GraphicsDevice);
                }
                timeSince2 += elapsed;
                if (timeSince2 >= SPAWN_TIME2)
                {
                    int temp = random.Next(0, 2);
                    if (temp == 0)
                    {
                        ShadowWalker.Add(new ShadowWalker(Content, GraphicsDevice, new Vector2(0, 422), new Vector2(50, 0)));
                    }
                    else if (temp == 1)
                    {
                        ShadowWalker.Add(new ShadowWalker(Content, GraphicsDevice, new Vector2(GraphicsDevice.Viewport.Width, 422), new Vector2(-50, 0)));
                    }
                    timeSince2 = 0;
                }
                for (int i = 0; i < magic.Count; i++)
                {
                    magic[i].Update(gameTime);
                    float time = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                    if (magic[i].SpriteEffect == SpriteEffects.FlipVertically)
                    {
                        //the force of gravity acting on the ball
                        magic[i].Force = gravityForce;
                        // sets the acceleration of the ball
                        magic[i].acceleration = magic[i].Force / 1;
                        //sets the velocity of th ball
                        magic[i].Velocity = magic[i].InitialVelocity + magic[i].acceleration * time;
                        //changes the balls position
                        magic[i].Position += (magic[i].InitialVelocity * time) + (0.5f * magic[i].acceleration * time * time);
                        if (magic[i].Position.Y >= 438)
                        {
                            //sets the y velocity of the ball to change direction each time the ball hits the above mentiones height
                            magic[i].Velocity = new Vector2(magic[i].InitialVelocity.X, magic[i].InitialVelocity.Y * -1);
                        }
                        magic[i].InitialVelocity = magic[i].Velocity;
                    }
                    if (magic[i].SpriteEffect == SpriteEffects.FlipHorizontally)
                    {
                        for (int j = 0; j < ShadowBat.Count; j++)
                        {
                            if ((ShadowBat[j].Position.X - magic[i].Position.X) <= 90f && (ShadowBat[j].Position.X - magic[i].Position.X) >= -90 && ShadowBat[j].Velocity.X > 0f)
                            {
                                if ((magic[i].Position.Y - ShadowBat[j].Position.Y) <= 90f && (magic[i].Position.Y - ShadowBat[j].Position.Y) >= 0)
                                {
                                    ShadowBat[j].Velocity = new Vector2(-200, 0);
                                }
                            }
                            else if ((ShadowBat[j].Position.X - magic[i].Position.X) <= 90f && (ShadowBat[j].Position.X - magic[i].Position.X) >= -90 && ShadowBat[j].Velocity.X < 0f)
                            {
                                if ((magic[i].Position.Y - ShadowBat[j].Position.Y) <= 90f && (magic[i].Position.Y - ShadowBat[j].Position.Y) >= 0)
                                {
                                    ShadowBat[j].Velocity = new Vector2(200, 0);
                                }
                            }
                        }
                    }
                    if (magic[i].isOffScreen(magic[i], GraphicsDevice))
                    {
                        missed += 1;
                        magic.RemoveAt(i);
                    }
                }
                for (int i = 0; i < ShadowBat.Count; i++)
                {
                    if (ShadowBat[i].Alive == false)
                    {
                        ShadowBat.RemoveAt(i);
                    }
                }
                for (int i = 0; i < ShadowWalker.Count; i++)
                {
                    if (ShadowWalker[i].Alive == false)
                    {
                        ShadowWalker.RemoveAt(i);
                    }
                }
                UpdateInput(elapsed);
                break;
                base.Update(gameTime);
            }
        }