Ejemplo n.º 1
0
 public void AddParasites(ParasiteStatus status)
 {
     StatusBarHolder.ParasiteDamage = status.Power;
 }
        public void doCollisionCheck()
        {
            List <PhysicsObject> neighbours;
            PhysicsObject        neighbourObject;
            int neighbourCount;

            int particleCount = 0;

            neighbours     = SpatialGrid.GetInstance().GetPNeighbours(this);
            neighbourCount = neighbours.Count;

            for (int j = 0; j < neighbourCount; j++)
            {
                neighbourObject = neighbours[j];
                // IF STATIC BODY
                Vector2 result;
                if (neighbourObject.type == PhysicsObjectType.potStaticBody)
                {
                    if ((result = ((StaticBody)neighbourObject).Collides(this)) != Vector2.Zero)
                    {
                        // ATTEMPTED NEW COLLISION CODE
                        float kr       = 0f;
                        float friction = 1f;

                        Vector2 tempVel = this.velocity;
                        //Vector2 tempVel = this.velocity;
                        Vector2 velocityN = Vector2.Dot(tempVel, result) * result;
                        Vector2 velocityT = tempVel - velocityN;

                        // Check if object is moving towards wall.
                        //if (Vector2.Dot(tempVel, result) < 0)
                        //{
                        SpatialGrid.GetInstance().RemoveObject(this);
                        // No Friction
                        //Vector2 newVel = velocityT - kr * velocityN;

                        // Fake Friction
                        Vector2 newVTan = Vector2.Max(Vector2.Zero, velocityT - velocityT * friction);
                        Vector2 newVel  = newVTan + kr * velocityN;

                        this.velocity = newVel;
                        this.Position = this.oldPosition;

                        //if (Vector2.Dot(tempVel, result) < 1)
                        //{
                        Vector2 contactForce = -(Vector2.Dot(result, Position - oldPosition) * result);
                        //this.velocity = contactForce;
                        this.ApplyForce(contactForce);
                        //}
                        this.Position += this.velocity;
                        SpatialGrid.GetInstance().AddObject(this);
                        //}
                        //status = ParasiteStatus.crawling;
                    }
                }
                else if (neighbourObject.type == PhysicsObjectType.potBlobParticle)
                {
                    // IF COLLIDING : DISABLE GRAVITY
                    relativeGravity = new Vector2(0, 1.5f);
                    particleCount++;
                }
                else
                {
                    // relativeGravity = new Vector2(0, 0.9f);
                }
            }

            if (particleCount == 0)
            {
                relativeGravity = new Vector2(0, 0.9f);
                status          = ParasiteStatus.crawling;
            }
            else
            {
                this.velocity *= 0.93f;
                status         = ParasiteStatus.swimming;
            }
        }