public void add(InPlay obj) { bool haveAdded = false; if (!AdditionalMath.contains(Area, obj.getRekt()) && parent != null) { parent.add(obj); return; } for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { RectangleF rect = obj.getRekt(); if (AdditionalMath.contains(innerQuads[x, y], rect)) { haveAdded = true; if (children[x, y] == null && Area.Height * Area.Width * .25 > minimum) { children[x, y] = new QuadNode(this, innerQuads[x, y], minimum, quadLevel + 1); } children[x, y].add(obj); } } } if (!haveAdded) { dict.Add(obj); } }
public bool operatePlats(GameObject obj) { bool inAnyPlat = false; foreach (Platform plat in platforms) { RectangleF rect = obj.getRekt(); RectangleF platform = plat.getRekt(); RectangleF gravityZone = plat.gravityZone(rect.Height, rect.Width); RectangleF underside = plat.underside(rect.Height, rect.Width); bool inPlat = AdditionalMath.contains(gravityZone, rect); /*&& platform.Contains(rect)*/; bool underPlat = AdditionalMath.contains(underside, rect); if (underPlat) { obj.removeForce("speed up"); RectangleF newRect = new RectangleF(rect.X, underside.Y - underside.Height, rect.Width, rect.Height); obj.setRekt(newRect); } if (inPlat) { inAnyPlat = true; rect = new RectangleF(rect.X, platform.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 (keysDown[0] && obj.getName().Equals("player")) { obj.addForce(new Vector(1000, Math.PI / 2, VectorType.FORCE, "jump up")); } if (Math.Abs(obj.getVelocityMagnitude()) > .3) { //Console.WriteLine(obj.getName() + " friction direction " + (obj.getVelocityDirection() + Math.PI)); obj.addForce(new Vector(plat.getKineticFriction() * g * obj.getMass(), obj.getVelocityDirection() + Math.PI, VectorType.FRICTION, "friction with " + plat.getName())); } else { obj.removeForce("friction with " + plat.getName()); } } } return(inAnyPlat); }
public void traverse(ObjectDelegate del, List <QuadNode> queue, bool movementChange) { for (int a = 0; a < dict.Count; a++) { InPlay obj = dict.ElementAt(a); del(obj); if (movementChange && !AdditionalMath.contains(Area, obj.getRekt())) { if (parent != null) { dict.Remove(obj); parent.add(obj); } } for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { if (movementChange && AdditionalMath.contains(innerQuads[x, y], obj.getRekt())) { if (children[x, y] == null) { children[x, y] = new QuadNode(this, innerQuads[x, y], minimum, quadLevel + 1); } children[x, y].add(obj); dict.Remove(obj); } } } } for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { if (children[x, y] != null) { queue.Add(children[x, y]); } } } }