Exemple #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// 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
            base.Initialize();

            spawnShieldTimer = 5;
            spawnShield      = 0;
            //shieldPos = new Vector2(rnd.Next(0, 500), rnd.Next(0, 900));
            shield = new Shield(TextureLibrary.GetTexture("shield"), Vector2.One, 5, new Vector2(1, 1));
            Reload();
        }
Exemple #2
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);

            // TODO: use this.Content to load your game content here
            //textures.Add("player", Content.Load<Texture2D>("player"));
            //textures.Add("enemy", Content.Load<Texture2D>("bad"));
            TextureLibrary.LoadTexture(Content, "player");
            TextureLibrary.LoadTexture(Content, "bad");
            TextureLibrary.LoadTexture(Content, "Button");
            scoreFont = Content.Load <SpriteFont>("Score");
            UserInterface.LoadSpriteFont(Content, "Score");
            TextureLibrary.LoadTexture(Content, "bg");
            TextureLibrary.LoadTexture(Content, "white");
            TextureLibrary.LoadTexture(Content, "shield");
            //UserInterface.AddButton(TextureLibrary.GetTexture("Button"), "Try Again", new Vector2(.5f, .5f), Vector2.One, Window.ClientBounds.Size.ToVector2(), 2);
        }
Exemple #3
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.CornflowerBlue);

            // TODO: Add your drawing code here

            spriteBatch.Begin();
            spriteBatch.Draw(TextureLibrary.GetTexture("bg"), bgPos, mainFrame, Color.White);
            spriteBatch.Draw(TextureLibrary.GetTexture("bg"), bgPos2, mainFrame, Color.White);
            if (show)
            {
                player.Draw(spriteBatch);
            }
            for (int i = 0; i < enemies.Count; i++)
            {
                enemies[i].Draw(spriteBatch);
            }
            spriteBatch.DrawString(scoreFont, "Score: " + scoreSting, new Vector2(10, 10), Color.White);
            BulletManager.Draw(spriteBatch);
            UserInterface.Draw(spriteBatch, player);

            if (spawnShieldTimer <= spawnEnemy)
            {
                shield.Draw(spriteBatch);
            }

            if (powerAttack == true)
            {
                spriteBatch.DrawString(scoreFont, "Power = active", new Vector2(180, 10), Color.White);
            }
            else if (powerAttack == false)
            {
                spriteBatch.DrawString(scoreFont, "Power = down", new Vector2(180, 10), Color.White);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
Exemple #4
0
        private void Reload()
        {
            IsMouseVisible = true;

            once  = false;
            score = 0;
            //health = 1;
            show = true;

            enemies    = new List <Enemy>();
            numEnemies = 3;

            spawnEnemy      = 3f;
            spawnEnemyTimer = 0;

            bgPos2 = new Vector2(0, -1080);
            bgPos  = new Vector2(0, 0);

            //mainFrame = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            mainFrame = new Rectangle(0, 0, 1920, 1080);


            playerPos = new Vector2(230, 900);

            for (int i = 0; i < numEnemies; i++)
            {
                startPos = new Vector2(rnd.Next(0, 500), 0);
                //enemies.Add(new Enemy(TextureLibrary.GetTexture("bad"), new Vector2(5f, 5f), 0f, 100f, startPos));
                enemies.Add(new Enemy(TextureLibrary.GetTexture("bad"), new Vector2(.4f, .4f), 0, 50, startPos, 500, 1));
            }

            player = new Player(TextureLibrary.GetTexture("player"), playerPos, 200, new Vector2(.5f, .5f), 0, Color.White, 1000, 1);

            UserInterface.AddButton(TextureLibrary.GetTexture("Button"), "Continue", new Vector2(.5f, .5f), Vector2.One, Window.ClientBounds.Size.ToVector2(), 1);
            UserInterface.AddButton(TextureLibrary.GetTexture("Button"), "Exit", new Vector2(.5f, .5f), Vector2.One, Window.ClientBounds.Size.ToVector2(), 1);
        }
Exemple #5
0
        public void Update(GameTime gameTime, float deltaTime, Player player, int windowHeight)
        {
            if (!UserInterface.GetPause())
            {
                if (player.GetAlive())
                {
                    if (alive)
                    {
                        attackTimer += deltaTime;
                        if (attackTimer <= attackSpeed)
                        {
                            attackTimer += deltaTime;
                        }



                        if (Vector2.Distance(position, player.GetPosition()) <= attackRange && attackTimer >= attackSpeed)
                        {
                            BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, player.GetPosition() - position, 400, new Vector2(.2f, .2f), Bullet.Owner.Enemy, Color.Red);
                            attackTimer = 0;
                        }
                        //attackTimer += deltaTime;
                        //if (attackTimer >= attackSpeed)
                        //{
                        //    bullets.Add(new Bullet(500, TextureLibrary.GetTexture("player"), 10, new Vector2(0, 1), position));
                        //    attackTimer = 0;
                        //}

                        rectangle = new Rectangle(position.ToPoint(), (texture.Bounds.Size.ToVector2() * scale).ToPoint());

                        //for (int i = 0; i < bullets.Count; i++)
                        //{
                        //    bullets[i].Update(deltaTime);
                        //}

                        //timer.Update(gameTime, 2f);
                        if (started == false)
                        {
                            position = startPos;
                            started  = true;
                        }

                        if (position.Y >= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - texture.Bounds.Size.Y)
                        {
                            started = false;
                        }
                        if (time <= 0)
                        {
                            time    = timeTurn;
                            turney *= -1;
                            if (turney == 1)
                            {
                                turn = true;
                            }
                            else if (turney == -1)
                            {
                                turn = false;
                            }
                        }
                        else if (time > 0)
                        {
                            time -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                        }

                        if (turn == true)
                        {
                            position.X += 1;
                            position.Y += 1;
                        }
                        else if (turn == false)
                        {
                            position.X += -1;
                            position.Y += 1;
                        }
                    }
                    else
                    {
                        color = Color.Blue;
                    }
                }
            }
        }
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.P))
            {
                Exit();
            }

            // TODO: Add your update logic here
            float         deltaTime     = (float)gameTime.ElapsedGameTime.TotalSeconds;
            MouseState    mouseState    = Mouse.GetState();
            KeyboardState keyboardState = Keyboard.GetState();

            playerPos = mouseState.Position.ToVector2();

            player.Update(deltaTime, Keyboard.GetState(), Mouse.GetState(), Window.ClientBounds.Size);

            if (!player.GetAlive() && once == false)
            {
                once = true;
                UserInterface.AddButton(TextureLibrary.GetTexture("Button"), "Retry", new Vector2(.5f, .5f), Vector2.One, Window.ClientBounds.Size.ToVector2(), 1);
            }

            powerAttack = player.GetPower();

            shieldPos = new Vector2(rnd.Next(0, 500), rnd.Next(0, 900));

            if (!UserInterface.GetPause())
            {
                bgPos2.Y += 1;
                bgPos.Y  += 1;

                if (bgPos.Y >= 1080)
                {
                    bgPos.Y = -1080;
                }
                if (bgPos2.Y >= 1080)
                {
                    bgPos2.Y = -1080;
                }
            }
            UserInterface.GameState exit = UserInterface.Update(keyboardState, mouseState, player);
            switch (exit)
            {
            case UserInterface.GameState.play:
                break;

            case UserInterface.GameState.exit:
                Exit();
                break;

            case UserInterface.GameState.restart:
                Reload();
                break;

            case UserInterface.GameState.dead:
                break;

            default:
                break;
            }

            if (!UserInterface.GetPause())
            {
                player.Update(deltaTime, keyboardState, mouseState, Window.ClientBounds.Size);
            }

            if (player.GetAlive())
            {
                spawnEnemyTimer += deltaTime;
                if (spawnEnemyTimer <= spawnEnemy)
                {
                    spawnEnemyTimer += deltaTime;
                }
                if (spawnEnemyTimer >= spawnEnemy)
                {
                    startPos = new Vector2(rnd.Next(0, 500), 0);

                    enemies.Add(new Enemy(TextureLibrary.GetTexture("bad"), new Vector2(.4f, .4f), 0, 50, startPos, 500, 1));

                    spawnEnemyTimer = 0;
                }

                //shield.Update(deltaTime, player);

                //spawnShieldTimer -= deltaTime;
                //if (spawnShieldTimer >= spawnShield)
                //{
                //    spawnShieldTimer -= deltaTime;
                //}
                //if (spawnShieldTimer <= spawnShield)
                //{
                //    shield.SetPosition(shieldPos);

                //    spawnShieldTimer = 5;
                //}
            }

            if (!UserInterface.GetPause() && player.GetAlive() == true)
            {
                score += deltaTime * 2.3f;
            }

            scoreInt = Convert.ToInt32(score);

            scoreSting = scoreInt.ToString();

            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].GetAlive())
                {
                    enemies[i].Update(gameTime, deltaTime, player, Window.ClientBounds.Height);
                }
                //player.DetectCollision(enemies);
                else
                {
                    enemies.RemoveAt(i);
                }
            }

            BulletManager.Update(deltaTime, player, enemies);

            base.Update(gameTime);
        }
Exemple #7
0
        public void Update(float deltaTime, KeyboardState keyboardState, MouseState mouseState, Point windowSize)
        {
            if (!UserInterface.GetPause())
            {
                if (alive)
                {
                    if (Shield.GetActive() == true)
                    {
                        invu = true;
                    }
                    else
                    {
                        invu = false;
                    }

                    //float pixelToMove = speed * deltaTime;

                    rectangle = new Rectangle(position.ToPoint(), (texture.Bounds.Size.ToVector2() * scale).ToPoint());

                    if (Keyboard.GetState().IsKeyDown(Keys.W) && position.Y >= 0)
                    {
                        position.Y -= 5;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.S) && position.Y <= 940)
                    {
                        position.Y += 5;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.D) && position.X <= 580)
                    {
                        position.X += 5;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.A) && position.X >= 0)
                    {
                        position.X -= 5;
                    }

                    attackTimer += deltaTime;
                    if (attackTimer <= attackSpeed)
                    {
                        attackTimer += deltaTime;
                    }

                    powerAttackTimer += deltaTime;
                    if (powerAttackTimer <= powerAttackSpeed)
                    {
                        powerAttackTimer += deltaTime;
                        powerAttack       = false;
                    }
                    else
                    {
                        powerAttack = true;
                    }

                    if (mouseState.LeftButton == ButtonState.Pressed && attackTimer >= attackSpeed && alive)
                    {
                        Vector2 bulletDir = mouseState.Position.ToVector2() - position;
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, bulletDir, 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        attackTimer = 0;
                    }

                    if (mouseState.RightButton == ButtonState.Pressed && alive && powerAttackTimer >= powerAttackSpeed)
                    {
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(0, 1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(0, -1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(1, 0), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(-1, 0), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(1, 1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(1, -1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(-1, -1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        BulletManager.AddBullet(TextureLibrary.GetTexture("white"), position, new Vector2(-1, 1), 400, new Vector2(.2f, .2f), Bullet.Owner.Player, Color.Blue);
                        powerAttackTimer = 0;
                    }

                    #region ye
                    //moveDir = mousePos - position;
                    //moveDir.Normalize();

                    //rotation = (float)Math.Atan2(moveDir.Y, moveDir.X);

                    //if (Vector2.Distance(mousePos, position) < pixelToMove)
                    //{
                    //    position = mousePos;
                    //}
                    //else
                    //{
                    //    position += moveDir * pixelToMove;
                    //}

                    //position = mousePos;

                    //position = new Vector2(10000, 10000);
                    #endregion
                    rectangle.Location = (position - offset * scale).ToPoint();
                }
                else
                {
                    color = Color.Black;
                }
            }
        }