Beispiel #1
1
        /// <summary>
        /// Create a new game screen. Should be done every time there is a new game.
        /// </summary>
        /// <param name="theScreenEvent"></param>
        /// <param name="contentManager"></param>
        public GameScreen(EventHandler theScreenEvent,ContentManager contentManager)
            : base(theScreenEvent)
        {
            bScoreWasAdded = false;

            this.contentManager = contentManager;
            dlDoubleJumpTimer = new DanLabel(1150, 20, 100, 50);

            //Init our intrepid hero
            csHero = new ControlledSprite();

            bg = new LayeredBackground();

            djeJumpEffect = new DoubleJumpEffect();

            altimeter = new Altimeter(); // Make a camera for the screen with an altimeter
            cCamera = new Camera(50, 100, 600, 520, altimeter);

            blocks = new List<Sprite>();
            Sprite sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);

            // REVIST Set up the Arcing Block Manager with the difficulty
            arcingBlockManager = new ArcingBlockManager(cCamera, blocks, contentManager, 500, 300, 150, "Sprites/block2");
        }
Beispiel #2
0
        /// <summary>
        /// Update the Camera
        /// </summary>
        /// <param name="theGameTime">The Game Time</param>
        /// <param name="blocks">The list of blocks that are affected by the camera.</param>
        /// <param name="csHero">The hero object.</param>
        /// <param name="bg">The current background</param>
        public void Update(GameTime theGameTime, List<Sprite> blocks, ControlledSprite csHero, LayeredBackground bg)
        {
            // Whether or not the hero is outside the camera bounds
            if ((csHero.Position.Y < rectCamera.Y && (csHero.mSpeed.Y < 0 || csHero.spLinkBlock.Velocity.Y < 0))
                || (csHero.Position.Y + csHero.Size.Height > rectCamera.Y + rectCamera.Height && (csHero.mSpeed.Y > 0 || csHero.spLinkBlock.Velocity.Y > 0)))
            {
                float goalDiffShift = 0;//how much it wants to compensate
                if (csHero.Position.Y <= rectCamera.Y && (csHero.mSpeed.Y < 0 || csHero.spLinkBlock.Velocity.Y < 0))//pushing cam up
                {
                    goalDiffShift = (csHero.Position.Y - rectCamera.Y);//should be neg
                    fallenAmount = 0;
                }
                else if (csHero.Position.Y + csHero.Size.Height > rectCamera.Y + rectCamera.Height && (csHero.mSpeed.Y > 0 || csHero.spLinkBlock.Velocity.Y > 0))//dragging cam down
                {
                    goalDiffShift = ((csHero.Position.Y + csHero.Size.Height) - (rectCamera.Y + rectCamera.Height));//should be pos
                    fallenAmount += goalDiffShift; // Add up how much the hero has fallen.
                }

                // Check to see if the game is over
                if (fallenAmount > 1000)
                {
                    csHero.IsDead = true;
                }

                float fShiftAmount = 0; // The amount of the hero's motion hidden by the camera movement

                // If the hero is surfing a block we must also factor in the blocks speed to know how much to move
                if (csHero.bLinked)
                    fShiftAmount = (csHero.spLinkBlock.Velocity.Y * (float)theGameTime.ElapsedGameTime.TotalSeconds)
                        + (csHero.mSpeed.Y * (float)theGameTime.ElapsedGameTime.TotalSeconds);

                else // Otherwise just use the hero's speed
                    fShiftAmount = csHero.mSpeed.Y * (float)theGameTime.ElapsedGameTime.TotalSeconds;

                if (fShiftAmount > 0)
                    fShiftAmount = Math.Min(fShiftAmount, goalDiffShift);
                else
                    fShiftAmount = Math.Max(fShiftAmount, goalDiffShift);

                csHero.Position.Y -= fShiftAmount; // Slide hero back so he doesn't move

                // Update altimeter based on camera
                altimeter.UpdateShift(fShiftAmount);

                foreach (Sprite block in blocks) // Move everyone relative to the hero.
                        block.Position.Y -= fShiftAmount;

                // Shift Backgrounds
                // Divided by i so ones in back move slower
                for (int i = 0; i < bg.layers.Count; i++)
                {
                        foreach (Sprite sp in bg.layers[i].Grid)
                            sp.Position.Y -= fShiftAmount / (i + 3);

                    bg.UpdateVertical(theGameTime);
                }
            }
        }
Beispiel #3
0
        public GameScreenOld(EventHandler theScreenEvent)
            : base(theScreenEvent)
        {
            //Init our intrepid hero
            csHero = new ControlledSprite();

            bg = new Background();

            blocks = new List<Sprite>();
            Sprite sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
            sp = new Sprite();
            blocks.Add(sp);
        }