Ejemplo n.º 1
0
            /// <summary>
            /// Ensures that the inputPrimitive is kept within bounds of the world. If inputPrimitive position is outside
            /// of the world bound, This function will determine the distances to the closes bound and force the inputPrimitive to
            /// be insde that world bound.
            /// </summary>
            /// <param name="inputPrimitive">The primtive to be tested</param>
            /// <returns>Which of the world bound that the inputPrimitive has moved out of.</returns>
            public static BoundCollideStatus ClampAtWorldBound(XNACS1Primitive inputPrimitive)
            {
                BoundCollideStatus status = CollideWorldBound(inputPrimitive);

                if (status != BoundCollideStatus.InsideBound)
                {
                    Vector2 size = (inputPrimitive.MaxBound - inputPrimitive.MinBound) * 0.5f;
                    Vector2 max  = new Vector2(WorldMax.X - size.X, WorldMax.Y - size.Y);
                    Vector2 min  = new Vector2(WorldMin.X + size.X, WorldMin.Y + size.Y);
                    Vector2 pos  = new Vector2(inputPrimitive.Center.X, inputPrimitive.Center.Y);
                    if (pos.X > max.X)
                    {
                        pos.X = max.X;
                    }
                    if (pos.Y > max.Y)
                    {
                        pos.Y = max.Y;
                    }
                    if (pos.X < min.X)
                    {
                        pos.X = min.X;
                    }
                    if (pos.Y < min.Y)
                    {
                        pos.Y = min.Y;
                    }
                    inputPrimitive.Center = pos;
                }
                return(status);
            }
Ejemplo n.º 2
0
        public Vector2 Update(Enemy[] enemy)
        {
            Vector2 s = new Vector2(-1f, -1f);

            for (int i = 0; i < list.Count; i++)
            {
                shot temp = list[i];
                if (list[i].shotLife == 0)
                {
                    list[i].bullet.RemoveFromAutoDrawSet();
                    list[i].emitter.RemoveFromAutoDrawSet();
                    list.Remove(list[i]);
                }
                else
                {
                    temp.shotLife--;
                    for (int j = 0; j < enemy.Length; j++)
                    {
                        list[i] = temp;
                        if (list[i].bullet.Collided(enemy[j]) && !list[i].hit)
                        {
                            s        = enemy[j].TurnEnemyToBunny();
                            temp.hit = true;
                            list[i]  = temp;
                        }
                        list[i].emitter.Center = list[i].bullet.Center;
                    }

                    BoundCollideStatus status = XNACS1Base.World.CollideWorldBound(temp.bullet);
                    switch (status)
                    {
                    case BoundCollideStatus.CollideBottom:
                    case BoundCollideStatus.CollideLeft:
                    case BoundCollideStatus.CollideRight:
                    case BoundCollideStatus.CollideTop:
                        temp.bullet.RemoveFromAutoDrawSet();
                        temp.emitter.RemoveFromAutoDrawSet();
                        list.Remove(list[i]);
                        break;
                    }
                }
            }

            return(s);
        }
Ejemplo n.º 3
0
        public void Update()
        {
            if (IsInAutoDrawSet())
            {
                BoundCollideStatus status = XNACS1Base.World.ClampAtWorldBound(this);
                switch (status)
                {
                case BoundCollideStatus.CollideBottom:
                case BoundCollideStatus.CollideTop:
                    VelocityY *= -1;
                    break;

                case BoundCollideStatus.CollideLeft:
                case BoundCollideStatus.CollideRight:
                    VelocityX *= -1;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public void Shoot(XNACS1Rectangle hero)
        {
            shot s = new shot(hero.Center, false);

            s.bullet.ShouldTravel = true;
            s.bullet.Velocity     = (XNACS1Base.GamePad.ThumbSticks.Right.X == 0 && XNACS1Base.GamePad.ThumbSticks.Right.Y == 0) ? new Vector2(hero.Texture == "heroRight" ? 1 : -1, 0) : XNACS1Base.GamePad.ThumbSticks.Right;
            list.Add(s);

            BoundCollideStatus status = XNACS1Base.World.CollideWorldBound(s.bullet);

            switch (status)
            {
            case BoundCollideStatus.CollideBottom:
            case BoundCollideStatus.CollideLeft:
            case BoundCollideStatus.CollideRight:
            case BoundCollideStatus.CollideTop:
                s.bullet.RemoveFromAutoDrawSet();
                list.Remove(s);
                s.bullet = null;
                break;
            }
        }
Ejemplo n.º 5
0
        protected override void UpdateWorld()
        {
            if (GamePad.Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (GamePad.ButtonAClicked() && mMyBall == null)
            {
                PlayACue("powerup");
                mMyBall = new Ball((World.WorldMax + World.WorldMin) / 2f, RandomFloat(0.5f, 2f));
            }

            if (mMyPaddle != null)
            {
                mMyPaddle.updatePaddle(
                    GamePad.ButtonXClicked(),
                    GamePad.ButtonBClicked(),
                    GamePad.ThumbSticks.Right);
                World.ClampAtWorldBound(mMyPaddle.mPaddle);
            }

            if (mMyBall != null)
            {
                mMyBall.updateBall(
                    GamePad.Buttons.LeftShoulder,
                    GamePad.Buttons.RightShoulder);
                bool collided = mMyBall.mBall.Collided(mMyPaddle.mPaddle);
                if (collided)
                {
                    Score++;
                    mMyBall.PaddleCollide(mMyPaddle);
                }

                BoundCollideStatus collideStatus = World.CollideWorldBound(mMyBall.mBall);

                switch (collideStatus)
                {
                case BoundCollideStatus.CollideBottom:
                    Score = 0;
                    mMyBall.DestroyBall();
                    mMyBall = null;
                    break;

                case BoundCollideStatus.CollideTop:
                    World.ClampAtWorldBound(mMyBall.mBall);
                    mMyBall.WallCollide(true);
                    EchoToTopStatus(collideStatus.ToString());
                    break;

                case BoundCollideStatus.CollideLeft:
                case BoundCollideStatus.CollideRight:
                    World.ClampAtWorldBound(mMyBall.mBall);
                    mMyBall.WallCollide(false);
                    EchoToTopStatus(collideStatus.ToString());
                    break;
                }
            }

            EchoToBottomStatus("Score: " + Score.ToString());
        }