コード例 #1
0
        public void MovePlayer(BallCharacter player, GameTime gameTime)
        {
            float timeDelta = (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000;

            player.velocity += gravityVec * timeDelta;

            //test for collision
            Vector3 pushAway       = Vector3.Zero;
            Vector3 movingPlaneVel = Vector3.Zero;

            if (planes.Count != 0)
            {
                foreach (CollisionLevelPiece p in planes)
                {
                    Vector3 result = p.testCollision(player);
                    pushAway += result;
                    if (result != Vector3.Zero && p is MovingLevelPiece)
                    {
                        movingPlaneVel += ((MovingLevelPiece)p).MoveVelocity / 20;
                    }
                }
            }

            if (pushAway != Vector3.Zero)
            {
                pushAway.Normalize();
                player.CollidedWithStage = true;
                respondToCollision(pushAway, movingPlaneVel, timeDelta, player);
            }
            else
            {
                player.CollidedWithStage = false;
            }
        }
コード例 #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Wall"))
        {
            audioManager.Play("WallSlash");
            return;
        }

        // When objects have the same tags
        if (collision.gameObject.CompareTag(tag))
        {
            return;
        }

        if (!GetComponent <BallAttack>().CanMove())
        {
            return;
        }

        BallCharacter character = collision.gameObject.GetComponent <BallCharacter>();

        if (character != null)
        {
            audioManager.Play("Slash");
            Vector3    contactPoint = new Vector3(collision.GetContact(0).point.x, collision.GetContact(0).point.y, 0f);
            DamageIcon icon         = Instantiate(damageIcon, contactPoint, Quaternion.identity);
            icon.SetDamageText(damage);
            //collision.gameObject.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
            character.TakeDamage(damage);
        }
    }
コード例 #3
0
 public Boolean IsCollidingWithGoal(BallCharacter player)
 {
     if (goal != null)
     {
         if (goal.WorldBoundSphere.Intersects(player.WorldBoundSphere))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
        public Boolean IsCollidingWithCollectable(BallCharacter player, Game game)
        {
            Collectable holder = null;

            foreach (Collectable collect in collectables)
            {
                if (!collect.CollectedYet && collect.WorldBoundSphere.Intersects(player.WorldBoundSphere))
                {
                    holder = collect;
                    break;
                }
            }
            if (null != holder)
            {
                holder.CollectedYet = true;
                game.Components.Remove(holder);
                return(true);
            }
            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Collision resolution. Kind of a hack.
        /// Called from the Update function
        /// Tweak numbers until the feel is "right"
        /// </summary>
        /// <param name="pushAway">The normalized vector that the ball should be pushed away</param>
        /// <param name="timeDelta"></param>
        private void respondToCollision(Vector3 pushAway, Vector3 movingPlaneVel, float timeDelta, BallCharacter player)
        {
            //Vector3 v3 = m_kPlane.getPlaneNormal();
            Vector3 vDiff = player.velocity;

            vDiff   += movingPlaneVel;
            vDiff.X += pushAway.X * 20;
            vDiff.Z += pushAway.Z * 20;
            if (vDiff.Y < -50)
            {
                vDiff.Y /= 1.5f;
            }
            vDiff.Y        += pushAway.Y;
            vDiff.Y        -= (gravityVec.Y * timeDelta) * 2;
            player.velocity = vDiff;
        }