Пример #1
0
        public virtual void Initialize()
        {
            Gravity   = new GravityHandler(GravitationalConstant, GravityDirection.Value, AirDensity);
            Collision = new CollisionHandler(this);

            // register first event
            EventClock.AddGameEvent(new EventClock.GameEvent(Update), TimeSpan.Zero);
        }
Пример #2
0
        public virtual void Update(GameTime gameTime)
        {
            InputHandler.UpdateInputs();
            EventClock.ProcessGameEvents(gameTime);

            //for (int i = registeredGameArea.Count - 1; i >= 0; i--)
            //{
            //    registeredGameArea[i].Update();
            //}
        }
Пример #3
0
        public virtual void Update(GameTime gameTime)
        {
            // readjust objects according to viewport settings
            int pinnedOffsetX = 0;
            int pinnedOffsetY = 0;

            if (pinnedGameObjectActive &&
                pinnedGameObject != null)
            {
                int originalX = pinnedGameObject.PositionRectangle.X;
                int originalY = pinnedGameObject.PositionRectangle.Y;

                // gravity and update
                Gravity.Apply(gameTime);
                pinnedGameObject.Update(gameTime);

                // check for unpinning
                pinnedGameObjectActive = (XScroll && !((pinnedObjectAbsolutePositionX <= ViewportWidthOneHalf || pinnedObjectAbsolutePositionX + pinnedGameObject.Width >= TotalWidth - 100)));

                // calculate offset
                // put the object back to its original position
                if (XScroll)
                {
                    pinnedOffsetX = (pinnedGameObject.PositionRectangle.X - originalX) * -1;
                    if (!pinnedGameObjectActive)
                    {
                        // adjust offset
                    }

                    pinnedGameObject.X            += pinnedOffsetX;
                    pinnedObjectAbsolutePositionX -= pinnedOffsetX;
                }
                if (YScroll)
                {
                    pinnedOffsetY = (pinnedGameObject.PositionRectangle.Y - originalY) * -1;
                    if (!pinnedGameObjectActive)
                    {
                        // adjust offset
                    }

                    pinnedGameObject.Y            += pinnedOffsetY;
                    pinnedObjectAbsolutePositionY -= pinnedOffsetY;
                }
            }
            else
            {
                // gravity
                Gravity.Apply(gameTime);

                // check for pinning
                if (pinnedGameObject != null)
                {
                    // check if we need to pin or unpin the player
                    pinnedGameObjectActive = (XScroll && (pinnedGameObject.PositionRectangle.X > 100 && pinnedGameObject.PositionRectangle.X + pinnedGameObject.Width < 200));
                    if (pinnedGameObjectActive)
                    {
                        if (pinnedObjectAbsolutePositionX == 0)
                        {
                            pinnedObjectAbsolutePositionX = pinnedGameObject.PositionRectangle.X;
                        }
                        if (pinnedObjectAbsolutePositionY == 0)
                        {
                            pinnedObjectAbsolutePositionY = pinnedGameObject.PositionRectangle.Y;
                        }
                    }
                }
            }

            // move objects / user input
            for (int i = activeObjects.Count - 1; i >= 0; i--)
            {
                if (pinnedGameObject == null || !pinnedGameObjectActive)
                {
                    activeObjects[i].Update(gameTime);
                }
                else if (pinnedGameObject != activeObjects[i])
                {
                    // if an object is pinned, don't process it
                    activeObjects[i].Update(gameTime);

                    if (XScroll)
                    {
                        activeObjects[i].X += pinnedOffsetX;
                    }
                    if (YScroll)
                    {
                        activeObjects[i].Y += pinnedOffsetY;
                    }
                }

                // GameArea Edge processing
            }

            // handle collisions
            Collision.HandleCollisions();

            // background processing

            // register next update
            EventClock.AddGameEvent(new EventClock.GameEvent(Update), NextFrameTimeSpan);
        }