public void CheckCollisions() { List <Entity> colliding = CollisionSolver.GetAllColliding(this); foreach (Entity e in colliding) { Type eType = e.GetType(); if (eType == typeof(Pickup)) { ToungeGrabbed(e); } if (eType == typeof(BadFrog)) { BadFrog b = (BadFrog)e; if (GetStrengthOfMotion() > b.GetStrengthOfMotion()) { b.Kill(); } else { Kill(); } //dramatic effect Renderer.cam.SetShake(2f, 0.4f); } if (eType == typeof(Frog) && e != this && x == e.x && y == e.y) //don't get stuck on each other { AddForce(1, 0); } } }
public static void FlingFrog() { Frog f = (Frog)EntityManager.FindFirstEntityOfType(typeof(Frog)); if (f == null) { return; } bool mouseOnFrog = CollisionSolver.IsPointInBounds(f.x, f.y, f.width, f.height, mouseX, mouseY); }
public void Translate(Vector2 currentPos, Vector2 newPos) { List <Entity> newPosCollides = CollisionSolver.GetAllPotentiallyColliding(newPos.X, newPos.Y, width, height, onlyWalls: true); if (newPosCollides.Count > 0) { //it has hit one wall (or more) Bounce(newPosCollides[0]); } else { x = newPos.X; y = newPos.Y; } }
public static void Update() { List <Entity> entityList = EntityManager.GetEntities(); //set mode if (InputManager.MouseRightDown()) { mode = CursorMode.BoundingBox; } else { mode = CursorMode.Normal; } if (mode == CursorMode.BoundingBox) { if (InputManager.MouseRightJustPressed()) { boundingA = new Vector2(InputManager.mouseX, InputManager.mouseY); boundingB = new Vector2(InputManager.mouseX, InputManager.mouseY); } if (InputManager.MouseRightHeld()) { if (boundingB.X < boundingA.X || boundingB.Y < boundingA.Y) { updatingB = false; } else { updatingB = true; } if (updatingB) { boundingB = new Vector2(InputManager.mouseX, InputManager.mouseY); } else { boundingA = new Vector2(InputManager.mouseX, InputManager.mouseY); } } //select all frogs in range foreach (Entity e in entityList) { if (e.GetType() == typeof(Frog)) { Rectangle frogScreenPos = Renderer.GetRenderRect(e.x, e.y, e.width, e.height); if (CollisionSolver.IsColliding( frogScreenPos.X, frogScreenPos.Y, frogScreenPos.Width, frogScreenPos.Height, boundingA.X, boundingA.Y, (int)(boundingB.X - boundingA.X), (int)(boundingB.Y - boundingA.Y))) { ((Frog)e).isInGroup = true; } else { ((Frog)e).isInGroup = false; } } } } else { if (InputManager.MouseRightJustReleased()) { //deselect all frogs in range foreach (Entity e in entityList) { if (e.GetType() == typeof(Frog)) { Rectangle frogScreenPos = Renderer.GetRenderRect(e.x, e.y, e.width, e.height); if (CollisionSolver.IsColliding( frogScreenPos.X, frogScreenPos.Y, frogScreenPos.Width, frogScreenPos.Height, boundingA.X, boundingA.Y, (int)(boundingB.X - boundingA.X), (int)(boundingB.Y - boundingA.Y))) { ((Frog)e).isInGroup = false; } } } } } }