Beispiel #1
0
 protected bool wereColliding(GameObject o1, GameObject o2)
 {
     return collidingObjects.Contains(new KeyValuePair<GameObject, GameObject>(o1, o2)) ||
            collidingObjects.Contains(new KeyValuePair<GameObject, GameObject>(o2, o1));
 }
Beispiel #2
0
 public void removeCallback(GameObject.Type typeA, GameObject.Type typeB, CallbackType callbackType)
 {
     switch (callbackType)
     {
         case CallbackType.BEGIN:
             callbacksBegin.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB));
             callbacksBegin.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA));
             break;
         case CallbackType.DURING:
             callbacksDuring.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB));
             callbacksDuring.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA));
             break;
         case CallbackType.END:
             callbacksEnd.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB));
             callbacksEnd.Remove(new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA));
             break;
     }
 }
Beispiel #3
0
 public void removeObject(GameObject gameObject)
 {
     objects.Remove(gameObject);
 }
Beispiel #4
0
 public void addCallback(GameObject.Type typeA, GameObject.Type typeB, CollisionCallback callback, CallbackType callbackType)
 {
     switch (callbackType)
     {
         case CallbackType.BEGIN:
             callbacksBegin[new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB)] = callback;
             callbacksBegin[new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA)] = callback;
             break;
         case CallbackType.DURING:
             callbacksDuring[new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB)] = callback;
             callbacksDuring[new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA)] = callback;
             break;
         case CallbackType.END:
             callbacksEnd[new KeyValuePair<GameObject.Type, GameObject.Type>(typeA, typeB)] = callback;
             callbacksEnd[new KeyValuePair<GameObject.Type, GameObject.Type>(typeB, typeA)] = callback;
             break;
     }
 }
Beispiel #5
0
 public void addObject(GameObject gameObject)
 {
     objects.Add(gameObject);
 }
Beispiel #6
0
 public static bool getCollision(GameObject o1, GameObject o2)
 {
     if (o1.shape == null || o2.shape == null)
     {
         //Log.log(Log.Type.WARNING, "Trying to check collision between objects with no shape");
         return false;
     }
     else
     {
         return Shape.getCollision(o1.shape, o2.shape);
     }
 }
Beispiel #7
0
        public void collisionCarScene(GameObject o1, GameObject o2)
        {
            // Get objects
            Car car;
            GameObject sceneObject;

            if (o1.type == GameObject.Type.CAR)
            {
                car = (Car)o1;
                sceneObject = o2;
            }
            else
            {
                car = (Car)o2;
                sceneObject = o1;
            }

            OrientedBox obb1 = (OrientedBox)car.shape;
            OrientedBox obb2 = (OrientedBox)sceneObject.shape;

            // Crash sfx
            game.audioEngine.SetGlobalVariable("crashVolume", car.velocity.Length() / car.maxSpeed);
            carCrash = game.soundBank.GetCue("crash");
            carCrash.Play();

            // Restore oldPos
            car.position = car.oldPos;

            // Get closest point
            Vector3 q = CollisionManager.closestPointToOBB(obb1.center + obb1.transform.Translation, obb2);

            // Get normal vector
            Vector3 normal = obb1.center + obb1.transform.Translation - q;
            normal.Normalize();

            // Change car velocity to bounce
            float angle = (float)Math.Atan2(normal.Y - car.velocity.Y, normal.X - car.velocity.X);
            Vector3 newDirection = new Vector3((float)System.Math.Sin(-angle), (float)System.Math.Cos(-angle), 0.0f);
            newDirection.Normalize();
            car.velocity = newDirection * car.velocity.Length() * 0.85f;

            // Get angle between normal and car direction
            Vector2 carDirection = new Vector2((float)System.Math.Sin(-car.angle), (float)System.Math.Cos(-car.angle));
            Vector2 normal2D = new Vector2(normal.X, normal.Y);

            float angleNormalCar = (float)Math.Atan2(normal2D.Y - carDirection.Y, normal2D.X - carDirection.X);
        }
Beispiel #8
0
        public void collisionCarCheckPoint(GameObject o1, GameObject o2)
        {
            // Get checkpoint
            CheckPoint checkpoint;

            if (o1.type == GameObject.Type.CHECKPOINT)
                checkpoint = (CheckPoint)o1;
            else
                checkpoint = (CheckPoint)o2;

            if (checkPoints.Count() > 0 && checkpoint == checkPoints[nextCheckPoint])
            {
                checkpoint.passThrough();
                if (checkpoint.state != GameObject.State.ERASE)
                    ++nextCheckPoint;

                // If we reach the end, we start again
                if (nextCheckPoint == checkPoints.Count)
                {
                    nextCheckPoint = 0;
                    ++lapsDone;
                }
            }
        }
Beispiel #9
0
        public void collisionCarBonus(GameObject o1, GameObject o2)
        {
            // Get time bonus
            TimeBonus timeBonus;

            if (o1.type == GameObject.Type.TIMEBONUS)
                timeBonus = (TimeBonus)o1;
            else
                timeBonus = (TimeBonus)o2;

            // Play sound
            pickTime = game.soundBank.GetCue("picktime");
            pickTime.Play();

            // Add time
            remainingTime += timeBonus.seconds * 1000;

            // Delete timebonus
            timeBonus.state = GameObject.State.ERASE;
        }
Beispiel #10
0
 public void addGameObject(String modelName, Vector3 position, Quaternion orientation, float scale)
 {
     GameObject gameObject = new GameObject(game, modelName, position, orientation, scale);
     gameObject.type = GameObject.Type.SCENEOBJECT;
     sceneObjects.Add(gameObject);
 }