Ejemplo n.º 1
0
        public void Update(Player player, List <Enemy> enemyList, Bullet bullet, Gui gui, GameTime gameTime, LevelManager level)
        {
            FlipWeapon(player);
            frametimer -= gameTime.ElapsedGameTime.TotalMilliseconds;
            input.Update();
            CheckWeapon(player);
            CreateBullet(player);
            last           = current;
            current        = Keyboard.GetState();
            animationTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            weaponHitbox   = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
            if (weaponPickedUp)
            {
                shotTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            if (currentWeapon > 0)
            {
                weaponOnGround       = false;
                weaponPickedUp       = true;
                gui.WeaponIsPickedUp = true;
            }
            if (weaponOnGround == false && weaponPickedUp == true)
            {
                input.vibrate = true;
                int weaponOffsetX = 20;
                int weaponOffsetY = 30;
                position       = new Vector2(player.Position.X + weaponOffsetX, player.Position.Y + weaponOffsetY);
                dPos           = player.AimPosition - position;
                weaponRotation = (float)Math.Atan2(dPos.Y, dPos.X);
                if (currentWeapon == 1)
                {
                    uziPos = position;
                }
                if (currentWeapon == 2)
                {
                    railPos = position;
                }
                if (frametimer <= 0)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Space) && shotTimer >= shotSpeed ||
                        input.gamePadState.Triggers.Right > 0 ||
                        animationTime <= 301)
                    {
                        if (animationTime >= 300)
                        {
                            frame = 0;
                        }
                        frametimer = frameinterval;
                        frame++;
                        railSource.Y = (frame % 10) * 64;
                    }
                }
            }

            foreach (Bullet b in bullets.ToList())
            {
                b.Update(player);

                foreach (Enemy e in enemyList)
                {
                    if (e.HitBox.Intersects(b.HitBox))
                    {
                        e.damageTaken = damage;
                        e.TakeDamage();
                        shotRemoved = true;
                    }
                }
                foreach (Rectangle wall in level.hitBoxWall)
                {
                    if (b.HitBox.Intersects(wall))
                    {
                        shotRemoved = true;
                    }
                }
                if (shotRemoved == true)
                {
                    bullets.Remove(b);
                    shotRemoved = false;
                }
                if (Vector2.Distance(b.position, player.position) >= 500)
                {
                    bullets.Remove(b);
                }
            }
        }
Ejemplo n.º 2
0
        public GamePlayManager(GraphicsDeviceManager graphics, GraphicsDevice graphicsDevice, Game1 game)
        {
            screenHeight        = 32 * 24;
            screenWidth         = 32 * 32;
            input               = new InputManager();
            this.graphics       = graphics;
            this.graphicsDevice = graphicsDevice;
            this.game           = game;
            gameOverTex         = TextureManager.GameOverTexture;
            craterText          = TextureManager.DesertBackgroundTexture;
            player              = new Player(TextureManager.PlayerSpriteSheet, playerPosition, sourceRect, screenWidth, screenHeight);
            for (int i = 0; i < 3; i++)
            {
                Vector2 enemyPos = new Vector2(400, 240 + 50 * i);
                tempEnemy = new Enemy(TextureManager.EnemyTexture, enemyPos, sourceRect);
                enemyList.Add(tempEnemy);
                tempEnemyHealthBar = new Bar((int)tempEnemy.EnemyMaxHealth, 0);
                enemyHealthBarList.Add(tempEnemyHealthBar);
            }

            for (int i = 0; i < 4; i++)
            {
                Vector2 enemyPos = new Vector2(600 + (50 * i) / 2, 550);
                tempEnemy = new Enemy(TextureManager.EnemyTexture, enemyPos, sourceRect);
                enemyList.Add(tempEnemy);
                tempEnemyHealthBar = new Bar((int)tempEnemy.EnemyMaxHealth, 0);
                enemyHealthBarList.Add(tempEnemyHealthBar);
            }

            for (int i = 0; i < 3; i++)
            {
                Vector2 enemyPos = new Vector2(800 + (50 * i) / 2, 70);
                tempEnemy = new Enemy(TextureManager.EnemyTexture, enemyPos, sourceRect);
                enemyList.Add(tempEnemy);
                tempEnemyHealthBar = new Bar((int)tempEnemy.EnemyMaxHealth, 0);
                enemyHealthBarList.Add(tempEnemyHealthBar);
            }

            for (int i = 0; i < 4; i++)
            {
                Vector2 enemyPos = new Vector2(850 + (50 * i) / 2, 150);
                tempEnemy = new Enemy(TextureManager.EnemyTexture, enemyPos, sourceRect);
                enemyList.Add(tempEnemy);
                tempEnemyHealthBar = new Bar((int)tempEnemy.EnemyMaxHealth, 0);
                enemyHealthBarList.Add(tempEnemyHealthBar);
            }

            weapon       = new Weapon(TextureManager.Weapon01Texture, weaponPos, sourceRect);
            bullet       = new Bullet(TextureManager.Bullet01Texture);
            bossOne      = new BossOne(TextureManager.BossOneTexture, bossOnePos, sourceRect, screenWidth, screenHeight);
            gui          = new Gui(1, 1);
            overWorldTex = TextureManager.OverWorldtexture;
            overWorld    = new OverWorld(game);
            collision    = new CollisionDetection();
            Viewport view = graphicsDevice.Viewport;

            camera       = new Camera(view);
            cameraOffset = new Vector2(35, 65);
            graphics.PreferredBackBufferHeight = screenHeight;
            graphics.PreferredBackBufferWidth  = screenWidth;
            camera.Rotation = 0f;
            gameOver        = new GameOver(gameOverTex);
            gameWon         = new GameWon(TextureManager.GameWonTexture);
            killAllEnemies  = new HelpTextManager(player.position);
            exitMap         = new HelpTextManager(player.position);
        }