protected bool wereColliding(GameObject o1, GameObject o2) { return collidingObjects.Contains(new KeyValuePair<GameObject, GameObject>(o1, o2)) || collidingObjects.Contains(new KeyValuePair<GameObject, GameObject>(o2, o1)); }
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; } }
public void removeObject(GameObject gameObject) { objects.Remove(gameObject); }
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; } }
public void addObject(GameObject gameObject) { objects.Add(gameObject); }
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); } }
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); }
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; } } }
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; }
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); }