public void operateCollisions(GameObject obj, int x) { for (int y = x + 1; y < objects.Count; y++) { GameObject obj2 = objects.ElementAt(y); RectangleF rekt1 = obj.getRekt(); RectangleF rekt2 = obj2.getRekt(); if (AdditionalMath.intersects(rekt1, rekt2)) { obj.collision(obj2); } } }
public void collision(InPlay other) { GameObject obj = (GameObject)other; string nome = "player"; if (obj.getName().GetHashCode() == nome.GetHashCode()) { inPlatCounter++; //Console.WriteLine("Collision between " + name + " and " + obj.getName() + " " + inPlatCounter); } RectangleF rect = obj.getRekt(); RectangleF overside = gravityZone(rect.Height, rect.Width); RectangleF under_side = underside(rect.Height, rect.Width); bool inPlat = AdditionalMath.intersects(overside, rect); /*&& platform.Contains(rect)*/; bool underPlat = AdditionalMath.intersects(under_side, rect); if (underPlat) { obj.removeForce("speed up"); RectangleF newRect = new RectangleF(rect.X, under_side.Y - under_side.Height, rect.Width, rect.Height); obj.setRekt(newRect); } if (inPlat) { //Console.WriteLine("Actually in Plat"); obj.InPlat = true; rect = new RectangleF(rect.X, hitbox.Y + rect.Height, rect.Width, rect.Height); obj.setRekt(rect); obj.removeForce("gravity"); Vector v = obj.getVelocity(); double[] comps = v.getComponent(); comps[1] = 0; v.setComponent(comps); if (Universe.keysDown[0] && obj.getName().Equals("player")) { obj.addForce(new Vector(1000, Math.PI / 2, VectorType.FORCE, "jump up")); } //Console.WriteLine(obj.getVelocityMagnitude() + "-speed"); if (Math.Abs(obj.getVelocityMagnitude()) > .3) { //Console.WriteLine(obj.getName() + " friction direction " + (obj.getVelocityDirection() + Math.PI)); obj.addForce(new Vector(kineticFriction * Universe.g * obj.getMass(), obj.getVelocityDirection() + Math.PI, VectorType.FRICTION, "friction with " + name)); } else { obj.removeForce("friction with " + name); } } }
public void collisions() { List <InPlay> allPossibleCollisions = new List <InPlay>(); queueUpInPlays(allPossibleCollisions); for (int x = 0; x < dict.Count; x++) { for (int y = x + 1; y < allPossibleCollisions.Count; y++) { InPlay obj1 = dict.ElementAt(x); InPlay obj2 = allPossibleCollisions.ElementAt(y); if (obj1 is GameObject && obj2 is GameObject) { if (AdditionalMath.intersects(obj1.getRekt(), obj2.getRekt())) { obj1.collision(obj2); } } else { //Console.WriteLine("Comparison between {0} and {1}", obj1.toString(), obj2.toString()); if (obj1 is Platform) { Platform plat = (Platform)(obj1); RectangleF rect = obj2.getRekt(); RectangleF overside = plat.gravityZone(rect.Height, rect.Width); RectangleF underside = plat.gravityZone(rect.Height, rect.Width); if (AdditionalMath.intersects(rect, overside)) { plat.collision(obj2); } } if (obj2 is Platform) { Platform plat = (Platform)(obj2); RectangleF rect = obj1.getRekt(); RectangleF overside = plat.gravityZone(rect.Height, rect.Width); RectangleF underside = plat.gravityZone(rect.Height, rect.Width); if (AdditionalMath.intersects(rect, overside)) { plat.collision(obj1); } } } } } }