コード例 #1
0
        private void EnemyEvolvingAnimation(object type) //moves enemy out of the screen, and insert the evolved enemy back
        {
            battleInstance.Pause();
            teleportInstance.Play(); //play teleport sound effect
            int       dt          = 0;
            bool      outOfScreen = false;
            float     originalY   = enemy.Position.Y;
            Stopwatch stopWatch   = new Stopwatch();

            while (!outOfScreen)
            {
                stopWatch.Start();
                Thread.Sleep(50); //sleep here because we don't what this while loop to blow up
                stopWatch.Stop();
                //TimeSpan ts = stopWatch.Elapsed;
                dt += stopWatch.Elapsed.Milliseconds;
                //System.Diagnostics.Debug.WriteLine(stopWatch.Elapsed.Milliseconds.ToString());
                //System.Diagnostics.Debug.WriteLine(dt.ToString());

                if (dt > 140)
                {
                    dt             = 0;
                    enemy.Position = new Vector2(enemy.Position.X, enemy.Position.Y - 10.0f);
                }
                if (enemy.Position.Y < -50.00f)
                {
                    outOfScreen = true;
                }
            }
            bool onPosition = false;

            enemy        = EnemyFactory.CreateEnemy((EnemyType)type, enemy.Position);
            enemyTexture = this.Content.Load <Texture2D>(enemy.Name); //enemy.Name corresponds to the image's name

            while (!onPosition)
            {
                stopWatch.Start();
                Thread.Sleep(50); //sleep here because we don't what this while loop to blow up
                stopWatch.Stop();
                //TimeSpan ts = stopWatch.Elapsed;
                dt += stopWatch.Elapsed.Milliseconds;
                //System.Diagnostics.Debug.WriteLine(stopWatch.Elapsed.Milliseconds.ToString());
                //System.Diagnostics.Debug.WriteLine(dt.ToString());

                if (dt > 140)
                {
                    dt             = 0;
                    enemy.Position = new Vector2(enemy.Position.X, enemy.Position.Y + 10.0f);
                }
                if (enemy.Position.Y > originalY - 0.1f)
                {
                    onPosition = true;
                }
            }
            enemy.Level = inheritedLevel + 24;
            pause       = false;
            teleportInstance.Stop();
            battleInstance.Resume();
        }
コード例 #2
0
        public Game1() //set up stuff
        {
            //needless to say...
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            //////////////////////////////////////
            Window.Title                       = "Pikachu's Adventure"; // our title
            graphics.IsFullScreen              = false;
            graphics.PreferredBackBufferWidth  = 800;                   // set this value to the desired width of your window
            graphics.PreferredBackBufferHeight = 600;                   // set this value to the desired height of your window
            graphics.ApplyChanges();                                    //apply
            IsMouseVisible = true;                                      //see the cursor
            pause          = false;
            //Allocate the game objects
            pikachu   = new Pikachu(50.0f, -50.0f);
            enemy     = EnemyFactory.CreateEnemy(EnemyType.Gastly, new Vector2(700.00f, -50.00f)); //We use the factory design pattern to create a enemy
            rareCandy = new RareCandy();

            //allocate the soundEffect objects
            soundEffects = new List <SoundEffect>();
        }