コード例 #1
0
ファイル: Level.cs プロジェクト: AlexZavkn/LabWorks
        public void Update_level(Hero batman, GameTime gameTime, GraphicsDeviceManager graphics1, int clp, Texture2D fireText1, SoundEffect jump, SoundEffect knife, SoundEffect fight,SoundEffect run,SoundEffect enemy, SoundEffect livePlus, SoundEffect coin, int points1)
        {
            timer += gameTime.ElapsedGameTime;

             if (((batman.position.X <= (float)(scrolls[0].BackRect.X + (graphics1.PreferredBackBufferWidth * 2 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Left))) || (((batman.position.X >= (float)(scrolls[scrolls.Count - 1].BackRect.X + scrolls[scrolls.Count - 1].BackRect.X - (graphics1.PreferredBackBufferWidth * 2 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Right)))))
            {
                batman.velocity.X = 0f;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 0, plats, graphics1.PreferredBackBufferHeight);
                }
            }
            else if ((batman.position.X >= ((float)(clp + (graphics1.PreferredBackBufferWidth * 4 / 6)))) && (Keyboard.GetState().IsKeyDown(Keys.Right)))
            {
                foreach (MainScroll back in scrolls)
                {
                    back.update(true, clp);
                }

                foreach (Platform plat in plats)
                {

                    plat.Update(true);
                }

                foreach (StaticObject  bonus in BonusLives)
                {
                    bonus.Update(1,graphics1,plats);
                }

                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(1, graphics1, plats);
                }

                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 1, plats, graphics1.PreferredBackBufferHeight);
                }

                batman.velocity.X = 0;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);

            }
            else if ((batman.position.X <= (float)(clp + (graphics1.PreferredBackBufferWidth * 1 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Left)))
            {
                foreach (MainScroll back in scrolls)
                {
                    back.update(false, clp);
                }
                foreach (Platform plat in plats)
                {
                    plat.Update(false);
                }
                foreach (StaticObject bonus in BonusLives)
                {
                    bonus.Update(2, graphics1, plats);
                }
                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(2, graphics1, plats);
                }

                batman.velocity.X = 0;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, -1, plats, graphics1.PreferredBackBufferHeight);
                }
            }
            else
            {
                batman.Update(gameTime, true, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 0, plats, graphics1.PreferredBackBufferHeight);
                }

                foreach (StaticObject bonus in BonusLives)
                {
                    bonus.Update(0, graphics1, plats);
                }
                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(0, graphics1, plats);
                }

            }
             if (Keyboard.GetState().IsKeyDown(Keys.Space) && State.IsKeyUp(Keys.Space))
            {
                Shooting(batman, fireText1);
                knife.Play();
            }
             State = Keyboard.GetState();

            UpdateLaser(batman);
            Fight(gameTime, batman);
            for (int k = 0; k < enemies.Count; k++)
            {
                if (enemies[k].live < 0)
                {
                    enemies.RemoveAt(k);
                    batman.batRangs += 5;
                    enemy.Play();
                }
            }

            for (int k = 0; k < BonusLives.Count; k++)
            {
                if (batman.heroRec.Intersects(BonusLives[k].BackRect))
                {
                    livePlus.Play();
                    BonusLives.RemoveAt(k);
                    batman.live += 10;
                }
            }

            for (int k = 0; k < Coins.Count; k++)
            {
                if (batman.heroRec.Intersects(Coins[k].BackRect))
                {
                    coin.Play();
                    Coins.RemoveAt(k);
                    batman.money++;
                }
            }
        }