Beispiel #1
0
    protected void OnCollisionEnter2D(Collision2D coll)
    {
        if (!collider.IsTouchingLayers(groundLayers.value))
        {
            return;
        }

        foreach (ContactPoint2D cp in coll.contacts)
        {
            if (cp.normal == Vector2.down)
            {
                collisions |= CollisionDirections.Up;
            }
            else if (cp.normal == Vector2.up)
            {
                collisions |= CollisionDirections.Down;
                animator.SetTrigger("didLand");
                animator.SetBool("isJumping", false);
                animator.SetBool("isGrounded", true);
            }
            else if (cp.normal == Vector2.right)
            {
                collisions |= CollisionDirections.Left;
                wallTouchAt = Time.time;
            }
            else if (cp.normal == Vector2.left)
            {
                collisions |= CollisionDirections.Right;
                wallTouchAt = Time.time;
            }
        }
    }
Beispiel #2
0
 public override void Handle(PlayerCharacter p, Block b, CollisionDirections directions)
 {
     if (directions.Bottom)
     {
         round.Add(new BlockBump(b.Position));
     }
 }
Beispiel #3
0
 public override void Handle(PlayerCharacter character, Monster monster, CollisionDirections directions)
 {
     if (monster.IsStunned)
     {
         monster.Kill();
     }
     else
     {
         character.Kill();
     }
 }
    protected void OnCollisionExit2D(Collision2D coll)
    {
        Debug.LogFormat ("OnCollisionExit: {0}", coll);

        foreach (ContactPoint2D cp in coll.contacts) {
            if (cp.normal == Vector2.down) {
                collisions &= ~CollisionDirections.Up;
            } else if (cp.normal == Vector2.up) {
                collisions &= ~CollisionDirections.Down;
            } else if (cp.normal == Vector2.right) {
                collisions &= ~CollisionDirections.Left;
            } else if (cp.normal == Vector2.left) {
                collisions &= ~CollisionDirections.Right;
            }
        }
    }
Beispiel #5
0
        public void RegisterDamage(CollisionDirections direction)
        {
            health--;

            if (health == 0)
            {
                SimpleEvent.AddEvent(EventTypes.RESET, null);
            }
            else
            {
                switch (direction)
                {
                case CollisionDirections.UP:
                    if (velocity.Y < COLLISION_LAUNCH_SPEED_VERTICAL)
                    {
                        velocity.Y = COLLISION_LAUNCH_SPEED_VERTICAL;
                    }

                    break;

                case CollisionDirections.DOWN:
                    if (velocity.Y > -COLLISION_LAUNCH_SPEED_VERTICAL)
                    {
                        velocity.Y = -COLLISION_LAUNCH_SPEED_VERTICAL;
                    }

                    break;

                case CollisionDirections.LEFT:
                    velocity.X = COLLISION_LAUNCH_SPEED_HORIZONTAL;

                    break;

                case CollisionDirections.RIGHT:
                    velocity.X = -COLLISION_LAUNCH_SPEED_HORIZONTAL;

                    break;
                }

                if (doubleJumpActive)
                {
                    doubleJumpEnabled = true;
                    doubleJumpActive  = false;
                }
            }
        }
Beispiel #6
0
    void Awake()
    {
        side = GetComponent <BoxCollider2D> ();
        CircleCollider2D[] circles = GetComponents <CircleCollider2D> ();
        if (circles [0].offset.y > 0)
        {
            top    = circles [0];
            bottom = circles [1];
        }
        else
        {
            top    = circles [1];
            bottom = circles [0];
        }

        slippery = Resources.Load("Materials/Physics/SlipperyPlayer") as PhysicsMaterial2D;
        friction = Resources.Load("Materials/Physics/FrictionPlayer") as PhysicsMaterial2D;

        height = Mathf.Abs(bottom.bounds.min.y - side.bounds.max.y);
        width  = Mathf.Abs(side.bounds.min.x - side.bounds.max.x);

        //get player bounds
        boundingbox = boundingObject.GetComponent <SpriteRenderer>().bounds;

        //new stuff
        velocity     = Vector2.zero;
        gravity      = -1;
        maxMovespeed = 4f;
        jumpSpeed    = 2;

        adjustedRadius        = bottom.radius * transform.localScale.y;
        sideCircleRayLength   = adjustedRadius * 1.41f;       //sqrt(2) * x
        bottomCircleRayLength = adjustedRadius * 1.1f;

        adjustedWidth  = side.bounds.extents.x * transform.localScale.y;
        sideRayLength  = adjustedWidth * 0.8f;
        sideRaySpacing = side.bounds.size.y / 3f;

        Collisions = new CollisionDirections();
    }
    protected void OnCollisionEnter2D(Collision2D coll)
    {
        Debug.LogFormat ("OnCollisionEnter: {0}", coll);

        if (!collider.IsTouchingLayers (groundLayers.value)) {
            return;
        }

        foreach (ContactPoint2D cp in coll.contacts) {
            if (cp.normal == Vector2.down) {
                collisions |= CollisionDirections.Up;
            } else if (cp.normal == Vector2.up) {
                collisions |= CollisionDirections.Down;
            } else if (cp.normal == Vector2.right) {
                collisions |= CollisionDirections.Left;
                wallTouchAt = Time.time;
            } else if (cp.normal == Vector2.left) {
                collisions |= CollisionDirections.Right;
                wallTouchAt = Time.time;
            }
        }
    }
Beispiel #8
0
 protected void OnCollisionExit2D(Collision2D coll)
 {
     foreach (ContactPoint2D cp in coll.contacts)
     {
         if (cp.normal == Vector2.down)
         {
             collisions &= ~CollisionDirections.Up;
         }
         else if (cp.normal == Vector2.up)
         {
             collisions &= ~CollisionDirections.Down;
             animator.SetBool("isGrounded", false);
         }
         else if (cp.normal == Vector2.right)
         {
             collisions &= ~CollisionDirections.Left;
         }
         else if (cp.normal == Vector2.left)
         {
             collisions &= ~CollisionDirections.Right;
         }
     }
 }
Beispiel #9
0
 public bool IsTouching(CollisionDirections direction)
 {
     return((collisions & direction) == direction);
 }
Beispiel #10
0
 public Collision(GameObject a, GameObject b, CollisionDirections directions)
 {
     A = a; B = b; Directions = directions;
 }
Beispiel #11
0
 public abstract void Handle(TA a, TB b, CollisionDirections directions);
Beispiel #12
0
 public void Handle(GameObject a, GameObject b, CollisionDirections directions) => Handle((TA)a, (TB)b, directions);
Beispiel #13
0
 public override void Handle(PlayerCharacter a, Coin b, CollisionDirections directions)
 {
     b.Collect();
 }