예제 #1
0
        /// <summary>
        /// Starts a new game session, setting all game states to initial values.
        /// </summary>
        public virtual void Start()
        {
            Ball b = ballManager.CreateDefaultBall(new Vector2(240, 400), new Vector2(200, 200));

            bottomPaddle.Texture  = defaultBottomPaddleTexture;
            bottomPaddle.Position = new Vector2(((screenRightBound - screenLeftBound) / 2) - bottomPaddle.Width / 2, screenBottomBound - (bottomPaddle.Height + paddleTouchBufferSize));
            bottomPaddle.UpdateShape();

            topPaddle.Texture  = defaultTopPaddleTexture;
            topPaddle.Position = new Vector2(((screenRightBound - screenLeftBound) / 2) - topPaddle.Width / 2, 0);
            topPaddle.UpdateShape();

            DefaultWall w1 = new DefaultWall();
            DefaultWall w2 = new DefaultWall();

            w1.shape = new PongClasses.PongShapes.Rectangle(
                new PongClasses.PongShapes.Coordinate(screenLeftBound, screenTopBound), 1, screenBottomBound - screenTopBound, Math.PI);
            w2.shape = new PongClasses.PongShapes.Rectangle(
                new PongClasses.PongShapes.Coordinate(screenRightBound, screenTopBound), 1, screenBottomBound - screenTopBound, 0);
            CollisionManager.AddObject("Wall", w1);
            CollisionManager.AddObject("Wall", w2);
            CollisionManager.AddObject("Paddle", bottomPaddle);
            CollisionManager.AddObject("Paddle", topPaddle);
            RegisterCallbackFunctions();
        }
예제 #2
0
        public void Update(float elapsed)
        {
            if (!IsActive)
            {
                if (IsTracked)
                {
                    CollisionManager.RemoveObject("Ball", this);
                    IsTracked = false;
                }
                return;
            }

            if (!IsTracked)
            {
                CollisionManager.AddObject("Ball", this);
                IsTracked = true;
            }

            Rotation += Spin * elapsed;

            //Adjust Velocity to match the MaxSpeed magnitude
            Velocity *= (MaxSpeed * Settings.BallSpeedMultiplier / Velocity.Length());

            Position += Velocity * elapsed;
            UpdateShape();
        }
예제 #3
0
        /// <summary>
        /// Update all active bubbles and powerups
        /// </summary>
        /// <param name="elapsed">The amount of time elapsed since last Update.</param>
        public void Update(float elapsed)
        {
            foreach (Powerup p in activePowerups)
            {
                p.LifeTime -= elapsed;
                if (p.LifeTime <= 0.0f)
                {
                    p.Deactivate(); //Hopefully this won't screw things up with multiple powerups running
                    break;          //It did, so for now we just fix one at a time
                }
            }

            int numActive = 0;

            foreach (PowerupBubble b in bubbles)
            {
                if (b.IsActive)
                {
                    b.Update(elapsed, random);
                    if (!b.IsActive)
                    {
                        if (b.IsTracked)
                        {
                            CollisionManager.RemoveObject("Bubble", b);
                            b.IsTracked = false;
                        }
                        continue;
                    }
                    if (!b.IsTracked)
                    {
                        CollisionManager.AddObject("Bubble", b);
                        b.IsTracked = true;
                    }
                    ++numActive;

                    if (b.Position.X < screen.screenLeftBound)
                    {
                        b.Position.X  = screen.screenLeftBound;
                        b.Velocity.X *= -1;
                    }
                    else if (b.Position.Y + b.Diameter > screen.screenRightBound)
                    {
                        b.Position.X  = screen.screenRightBound - b.Diameter;
                        b.Velocity.X *= -1;
                    }
                    //TODO: handle hitting top and bottom
                }
            }

            if (0 == numActive)
            {
                CreatePowerupFastball();
            }
        }