Beispiel #1
0
 public static Height getHeight(HeightEnum height)
 {
     if (height == HeightEnum.HIGH)
     {
         return new Height(false, true);
     }
     return new Height(true, false);
 }
 public virtual Vector2 checkCollisionWith(CollisionObjectInterface obj, CollisionDetectorInterface detector, HeightEnum height, float radDistance, Vector2 velocity)
 {
     if (detector.checkCollision(obj.getBounds(height), getBounds(height), radDistance, velocity) != Vector2.Zero)
     {
         handleCollision(obj);
     }
     return Vector2.Zero;
 }
 public virtual Vector2 checkCollisionWith(CollisionObjectInterface obj, CollisionDetectorInterface detector, HeightEnum height, float radDistance, Vector2 velocity)
 {
     if (!hasBeenPickedUp_ && detector.checkCollision(obj.getBounds(height), getBounds(height), radDistance, velocity) != Vector2.Zero
         && (obj is PlayableCharacterAbstract))
     {
         handleCollision(obj);
     }
     return Vector2.Zero;
 }
    public Vector2 GetRandomHeight(HeightEnum height)
    {
        switch (height)
        {
        case HeightEnum.TALL: return(new Vector2(1, 1.1f + Random.Range(-heightDiff, heightDiff)));

        case HeightEnum.NORMAL: return(new Vector2(1, 1 + Random.Range(-heightDiff, heightDiff)));

        case HeightEnum.SHORT: return(new Vector2(1, 0.9f + Random.Range(-heightDiff, heightDiff)));

        default: return(Vector2.one);
        }
    }
Beispiel #5
0
 public static BoxObject createBox(int x1, int y1, int x2, int y2, HeightEnum height)
 {
     float x1f = (float)x1 * 15f;
     float x2f = (float)(x2 + 1) * 15f;
     float y1f = (float)y1 * 15f;
     float y2f = (float)(y2 + 1) * 15f;
     Vector2 center = new Vector2((x1f + x2f) / 2f, (y1f + y2f) / 2f);
     List<Vector2> points = new List<Vector2>();
     points.Add(new Vector2(center.X - x1f, center.Y - y1f));
     points.Add(new Vector2(center.X - x2f, center.Y - y1f));
     points.Add(new Vector2(center.X - x2f, center.Y - y2f));
     points.Add(new Vector2(center.X - x1f, center.Y - y2f));
     BoxObject temp = new BoxObject(points, center, Height.getHeight(height));
     temp.getBounds(height).rotate(new Vector2(1.0f, 0.0f), center);
     return temp;
 }
Beispiel #6
0
        public override void WriteJson(JsonWriter writer,
                                       object untypedValue,
                                       JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer,
                                     null);

                return;
            }

            HeightEnum value = (HeightEnum)untypedValue;

            if (value == HeightEnum.Container)
            {
                serializer.Serialize(writer,
                                     "container");

                return;
            }

            throw new Exception("Cannot marshal type HeightEnum");
        }
 public override ConvexPolygonInterface getBounds(HeightEnum height)
 {
     return actuator_.getBounds(height);
     /*
     if (height == HeightEnum.HIGH)
     {
         return boundsPolygonHigh_;
     }
     if (height_.blocksHigh_)
     {
         return boundsPolygonLow_;
     }
     else
     {
         return boundsPolygonLowCrouch_;
     }
      */
 }
 public abstract ConvexPolygonInterface getBounds(HeightEnum height);
 public ConvexPolygonInterface getBounds(HeightEnum height)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
        public virtual Vector2 checkCollisionWith(CollisionObjectInterface obj, CollisionDetectorInterface detector, HeightEnum height, float radDistance, Vector2 velocity)
        {
            Vector2 translate = detector.checkCollision(obj.getBounds(height), getBounds(height), radDistance, velocity);
            if (translate != Vector2.Zero)
            {
                obj.collidedInto(this);
                collidedWith(obj);

                if (objectChangesHeight(obj))
                {
                    if (height == HeightEnum.HIGH)
                    {
                        height_.blocksHigh_ = false;
                    }
                    else
                    {
                        height_.blocksLow_ = false;
                    }
                }
                if (obj is CharacterAbstract)
                {
                    height_ = new Height(false, false);
                }
            }
            return Vector2.Zero;
        }
 public virtual Vector2 checkCollisionWith(CollisionObjectInterface obj, CollisionDetectorInterface detector, HeightEnum height, float radDistance, Vector2 velocity)
 {
     return detector.checkCollision(obj.getBounds(height), getBounds(height), radDistance, velocity);
 }
Beispiel #12
0
 public Vector2 checkCollisionWith(CollisionObjectInterface obj, CollisionDetectorInterface detector, HeightEnum height, float radDistance, Vector2 velocity)
 {
     if (detector.checkCollision(obj.getBounds(height), getBounds(height), radDistance, velocity) != Vector2.Zero)
     {
         collidedWith(obj);
         obj.collidedInto(this);
     }
     return Vector2.Zero;
 }
Beispiel #13
0
 public ConvexPolygonInterface getBounds(HeightEnum height)
 {
     return boundsPolygon_;
 }
Beispiel #14
0
 public override ConvexPolygonInterface getBounds(HeightEnum height)
 {
     if (height == HeightEnum.HIGH)
     {
         return boundsPolygonHigh_;
     }
     else
     {
         return boundsPolygonLow_;
     }
 }
 public ConvexPolygonInterface getBounds(HeightEnum height)
 {
     return animation_.getBounds();
 }
Beispiel #16
0
 public override ConvexPolygonInterface getBounds(HeightEnum height)
 {
     return actuator_.getBounds(height);
 }
        protected Vector2 checkTranslationalCollisionsSingleHeight(CollisionObjectInterface obj, Vector2 velocity, HeightEnum height)
        {
            float radius = obj.getRadius() + velocity.Length();
            Vector2 position = obj.getPosition();
            ConvexPolygonInterface movingObjectPolygon = obj.getBounds(height);
            Height objectHeight = obj.getHeight();

            Vector2 translate, tempVelocity = velocity;
            float dist;
            List<Vector2> collisions = new List<Vector2>();
            foreach (CollisionObjectInterface cObj in objects_)
            {
                dist = distanceBetweenPoints(position, cObj.getPosition());
                if (cObj != obj && objectHeight.collides(cObj.getHeight()) && dist < radius + cObj.getRadius())
                {
                    dist = radius + cObj.getRadius() - dist;
                    //translate = checkCollision(movingObjectPolygon, cObj.getBounds(tileHeight), dist, velocity);
                    translate = cObj.checkCollisionWith(obj, this, height, dist, tempVelocity);
                    if (translate != Vector2.Zero)
                    {
                        obj.collidedInto(cObj);
                        cObj.collidedWith(obj);
                        //velocity += translate;
                        //movingObjectPolygon.rotate(direction, newPosition);
                        position = movingObjectPolygon.getCenter();
                        translate = obj.checkCollisionInto(cObj, this, Height.getHeight(height), dist, translate);
                        if (translate != Vector2.Zero)
                        {
                            collisions.Add(translate);
                            tempVelocity += translate;
                        }
                    }
                }
            }
            if (collisions.Count == 0)
            {
                movingObjectPolygon.translate(velocity);
                return velocity;
            }
            if (collisions.Count == 1)
            {
                movingObjectPolygon.translate(velocity + collisions[0]);
                return (velocity + collisions[0]);
            }
            velocity += correctMultipleCollisions(velocity, collisions);
            movingObjectPolygon.translate(velocity);
            return velocity;
        }
 protected static void set(int x, int y, HeightEnum height)
 {
     if (height == HeightEnum.HIGH)
     {
         setHigh(x, y);
     }
     else
     {
         setLow(x, y);
     }
 }
 protected static float get(int x, int y, HeightEnum height)
 {
     if (x >= 0 && x < newTiles_.GetLength(1)
         && y >= 0 && y < newTiles_.GetLength(0))
     {
         if (height == HeightEnum.HIGH)
         {
             return newTiles_[y, x].highDistance_;
         }
         return newTiles_[y, x].lowDistance_;
     }
     return 0f;
 }
 public ConvexPolygonInterface getBounds(HeightEnum height)
 {
     if (height == HeightEnum.HIGH)
     {
         return currentActions_[highActionLevel_].getBounds(height);
     }
     return currentActions_[lowActionLevel_].getBounds(height);
 }
 public Commando.collisiondetection.ConvexPolygonInterface getBounds(HeightEnum height)
 {
     return animation_.getBounds();
 }
        protected Vector2 checkRotationalCollisionsSingleHeight(CollisionObjectInterface obj, ref Vector2 newDirection, HeightEnum height)
        {
            float radius = obj.getRadius();
            Vector2 position = obj.getPosition();
            ConvexPolygonInterface movingObjectPolygon = obj.getBounds(height);
            Vector2 oldDirection = obj.getDirection();
            movingObjectPolygon.rotate(newDirection, position);
            Height objectHeight = obj.getHeight();

            Vector2 translate = Vector2.Zero;
            float dist;
            List<Vector2> collisions = new List<Vector2>();
            foreach (CollisionObjectInterface cObj in objects_)
            {
                dist = distanceBetweenPoints(position, cObj.getPosition());
                if (cObj != obj && objectHeight.collides(cObj.getHeight()) && dist < radius + cObj.getRadius())
                {
                    dist = radius + cObj.getRadius() - dist;
                    //translate = checkCollision(movingObjectPolygon, cObj.getBounds(tileHeight), dist, Vector2.Zero);
                    translate = cObj.checkCollisionWith(obj, this, height, dist, Vector2.Zero);
                    if (translate != Vector2.Zero)
                    {
                        obj.collidedInto(cObj);
                        cObj.collidedWith(obj);
                        //velocity += translate;
                        //movingObjectPolygon.rotate(direction, newPosition);
                        translate = obj.checkCollisionInto(cObj, this, Height.getHeight(height), dist, translate);
                        if (translate != Vector2.Zero)
                        {
                            collisions.Add(translate);
                        }
                    }
                }
            }
            if (collisions.Count == 1)
            {
                return collisions[0];
            }
            if (collisions.Count > 1)
            {
                translate = Vector2.Zero;
                for (int i = 0; i < collisions.Count; i++)
                {
                    Vector2 colVector = collisions[i];
                    for (int j = i; j < collisions.Count; j++)
                    {
                        if (ConvexPolygon.dotProduct(colVector, collisions[j]) / (colVector.Length() * collisions[j].Length()) < 0)
                        {
                            newDirection = oldDirection;
                            movingObjectPolygon.rotate(oldDirection, position);
                            return Vector2.Zero;
                        }
                    }
                    translate += colVector;
                }
                return translate;
            }
            return Vector2.Zero;
        }
Beispiel #23
0
 public override ConvexPolygonInterface getBounds(HeightEnum height)
 {
     if (Height.getHeight(height).collides(height_))
     {
         return boundsPolygon_;
     }
     return null;
 }
 public Commando.collisiondetection.ConvexPolygonInterface getBounds(HeightEnum height)
 {
     if (animation_.GetLength(0) > 1)
     {
         int animSet = character_.getActuator().getCurrentAnimationSet();
         return animation_[animSet].getBounds();
     }
     return animation_[0].getBounds();
 }