public void ProcessEntityPhysics(IPhysical entity, float step) { entity.IsFalling = true; if (entity is ICollidable collidableEntity) { for (int index = 0; index < levelGeometries.Count; index++) { LevelGeometry geom = levelGeometries[index]; CollisionSolver.SolveEntityAgainstGeometry(collidableEntity, geom); } } entity.Physics(step); if (entity is IEntityCollidable ec) { for (int index = 0; index < entities.Count; index++) { ICollidable otherEntity = entities[index] as ICollidable; if (!ec.Equals(otherEntity) && ec.GetType() != otherEntity.GetType()) { CollisionSolver.SolveEntityAgainstEntity(ec, otherEntity); } } } }
private void UpdatePlayer() { var previousPosition = player.Position.Copy(); player.UpdatePosition(keyState, currentLevel.StaticShapes); currentLevel.CollisionsInfo = CollisionSolver.ResolveCollisions(currentLevel.SceneShapes); AudioEngine.UpdateListenerPosition(player.Position); var realVelocity = player.Position - previousPosition; player.MeleeWeapon.MoveRangeBy(realVelocity); cursor.MoveBy(viewForm.GetCursorDiff() + realVelocity); player.UpdateSprites(cursor.Position); if (mouseState.RMB && player.MeleeWeapon.IsReady) { player.RaiseMeleeWeapon(); } else if (mouseState.LMB && player.CurrentWeapon.IsReady && !player.IsMeleeWeaponInAction) { player.HideMeleeWeapon(); var firedBullets = player.CurrentWeapon.Fire(player.Position, cursor); AudioEngine.PlayNewInstance("event:/gunfire/2D/misc/DROPPED_SHELL"); currentLevel.Bullets.AddRange(firedBullets); currentLevel.Particles.Add(ParticleFactory.CreateShell(player.Position, cursor.Position - player.Position, player.CurrentWeapon)); } player.IncrementTick(); }
public static CollisionSolver CheckCollision(Vector2 pos1, Vector2 pos2, InteractiveObject char1, InteractiveObject char2, TimeSpan now, bool perPixel) { CollisionSolver solver = new CollisionSolver(); collisionType = "Bounding-Box"; if (char1.aSS != null) { if (char2.aSS != null) { return(CheckCollision(pos1, pos2, char1.aSS, char2.aSS, now, perPixel)); } else if (char2.aT != null) { return(CheckCollision(pos1, pos2, char1.aSS, char2.animationLibrary[char2.currentAnim], now, perPixel)); } } else { if (char2.aSS != null) { return(CheckCollision(pos1, pos2, char1.animationLibrary[char1.currentAnim], char2.aSS, now, perPixel)); } else if (char2.aT != null) { return(CheckCollision(pos1, pos2, char1.animationLibrary[char1.currentAnim], char2.animationLibrary[char2.currentAnim], now, perPixel)); } } solver.collided = false; return(solver); }
public static CollisionSolver CheckCollision(Vector2 pos1, Vector2 pos2, AnimatedSpriteSheet collider1, AnimationTexture collider2, TimeSpan now, bool perPixel) { CollisionSolver solver = new CollisionSolver(); collisionType = "Bounding-Box"; Texture2D ss = collider1.getSpriteSheet(); Rectangle collider1Range = collider1.getCurrentFrame(now); Texture2D texture = collider2.getCurrentFrame(now); Rectangle collider2Range = new Rectangle(0, 0, texture.Width, texture.Height); collider1Range.X = (int)pos1.X; collider1Range.Y = (int)pos1.Y; collider2Range.X = (int)pos2.X; collider2Range.Y = (int)pos2.Y; //Simple Bounding Box Collisions if ((collider1Range.Left > collider2Range.Right && collider1Range.Right > collider2Range.Left) || (collider2Range.Left > collider1Range.Right && collider2Range.Right > collider1Range.Left) || (collider1Range.Top < collider2Range.Bottom && collider1Range.Bottom < collider2Range.Top) || (collider2Range.Top < collider1Range.Bottom && collider2Range.Bottom < collider1Range.Top)) { solver.collided = false; return(solver); } else { solver.collided = true; if (collider1Range.Right > collider2Range.Left && collider1Range.Left < collider2Range.Right) { if (collider1Range.Center.X < collider2Range.Center.X) { solver.correctionVector.X = (collider1Range.Right - collider2Range.Left) * -1.0f; } else { solver.correctionVector.X = (collider2Range.Right - collider1Range.Left); } } if (collider1Range.Bottom > collider2Range.Top && collider1Range.Top < collider2Range.Bottom) { if (collider1Range.Center.Y > collider2Range.Center.Y) { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom) * -1.0f; } else { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom); } } return(solver); } }
private bool CheckForCollision(Vector2 pos) { var targetCollision = CollisionSolver.CheckThickLineCollision(ClosestPoint, DashObject.StartPosition, LocalPlayer.Instance.MapCollision.MapCollisionRadius); return(targetCollision != null && targetCollision.IsColliding && targetCollision.CollisionFlags.HasFlag(CollisionFlags.LowBlock | CollisionFlags.HighBlock)); }
void Awake() { if (hitboxList == null) { hitboxList = new List <ZeroHitbox>(); } solver = new CollisionSolver(new BruteForceStrategy()); _instance = this; }
void Awake() { if (hitboxList == null) { hitboxList = new List<ZeroHitbox>(); } solver = new CollisionSolver(new BruteForceStrategy()); _instance = this; }
public static CollisionSolver CheckCollision(Vector2 pos1, Vector2 pos2, Texture2D collider1, Texture2D collider2, bool perPixel) { CollisionSolver solver = new CollisionSolver(); collisionType = "Bounding-Box"; Rectangle collider1Range = new Rectangle(0, 0, collider1.Width, collider1.Height); Rectangle collider2Range = new Rectangle(0, 0, collider2.Width, collider2.Height); collider1Range.X = (int)pos1.X; collider1Range.Y = (int)pos1.Y; collider2Range.X = (int)pos2.X; collider2Range.Y = (int)pos2.Y; if ((collider1Range.Left > collider2Range.Right && collider1Range.Right > collider2Range.Left) || (collider2Range.Left > collider1Range.Right && collider2Range.Right > collider1Range.Left) || (collider1Range.Top < collider2Range.Bottom && collider1Range.Bottom < collider2Range.Top) || (collider2Range.Top < collider1Range.Bottom && collider2Range.Bottom < collider1Range.Top)) { solver.collided = false; return(solver); } else { solver.collided = true; if (collider1Range.Right > collider2Range.Left && collider1Range.Left < collider2Range.Right) { if (collider1Range.Center.X < collider2Range.Center.X) { solver.correctionVector.X = (collider1Range.Right - collider2Range.Left) * -1.0f; } else { solver.correctionVector.X = (collider2Range.Right - collider1Range.Left); } } if (collider1Range.Bottom > collider2Range.Top && collider1Range.Top < collider2Range.Bottom) { if (collider1Range.Center.Y > collider2Range.Center.Y) { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom) * -1.0f; } else { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom); } } return(solver); } }
public static bool CheckCollisionToTarget(this Character localPlayer, Character target, float radius) { if (localPlayer != null && target != null) { var heading = target.Pos() - localPlayer.Pos(); var direction = heading.Normalized; var colsolver = CollisionSolver.CheckThickLineCollision(localPlayer.Pos(), target.Pos() + direction, radius); return(colsolver.IsColliding || ObjectTracker.Enemy.Obstacles.TrackedObjects.Any(o => o.BlocksProjectileTo(target, radius))); } return(false); }
public static bool IsColliding(Player localPlayer, Player target) { if (target != null && target.IsLocalPlayer) { return(false); } if (localPlayer != null && target != null) // && !target.IsLocalPlayer) { var heading = target.WorldPosition - localPlayer.WorldPosition; var distance = heading.Length(); var direction = heading / distance; return(CollisionSolver.CheckThickLineCollision(localPlayer.WorldPosition, target.WorldPosition + direction, target.MapCollisionRadius - 0.3f).IsColliding); } return(false); }
public Stage(MinerGame game, StageLevel level, Vector2 size, IEnumerable <GameObject> objects) : base(game) { Level = level; Size = size; CollisionSolver = new CollisionSolver(this, game); GameObjects = objects.ToList(); Game.Components.Add(CollisionSolver); foreach (var o in GameObjects) { Game.Components.Add(o); } Player = (Player)Game.Components.Single(o => o is Player); }
public Core(Vector2 screenSize, GraphicsDeviceManager graphics, ContentManager content) { Director.Initialize(screenSize, graphics, content, this); this.graphics = graphics; graphics.PreferredBackBufferWidth = (int)screenSize.X; graphics.PreferredBackBufferHeight = (int)screenSize.Y; graphics.SynchronizeWithVerticalRetrace = false; graphics.ApplyChanges(); _camera = new Camera(0, 0, (int)screenSize.X, (int)screenSize.Y); _renderer = new Renderer(); Director.Camera = _camera; Director.WorldBounds = new Rectangle(0, 0, (int)screenSize.X, (int)screenSize.Y); CollisionSolver = new CollisionSolver(); this.stopwatch = new Stopwatch(); }
//size of a particle buffer public void Awake() { // Init simulation lGravity = Constants.Gravity * Constants.ParticleMass; fluidSim = new SPHSimulation(Constants.CellSpace, Constants.SimulationDomain); collisionSolver = new CollisionSolver(); collisionSolver.Bounciness = 0.2f; collisionSolver.Friction = 0.01f; // Init. particle system particleSystem = new ParticleSystem(); float freq = 40; int maxPart = 100; particleSystem.MaxParticles = maxPart; particleSystem.MaxLife = (int)((double)maxPart / freq / Constants.TimeStepSeconds); // Add Emitter ParticleEmitter emitter = new ParticleEmitter(); emitter.Position = new Vector2(Constants.SimulationDomain.xMax / 2, Constants.SimulationDomain.yMax - Constants.SimulationDomain.yMax / 8); emitter.VelocityMin = 2.5f; //Constants.ParticleMass * 0.30f; emitter.VelocityMax = 3.0f; //Constants.ParticleMass * 0.35f; emitter.Direction = new Vector2(0.8f, -0.25f); emitter.Distribution = Constants.SimulationDomain.width * 0.1f; emitter.Frequency = freq; emitter.ParticleMass = Constants.ParticleMass; particleSystem.Emitters.Add(emitter); print( "SimulationDomain: (" + Constants.SimulationDomain.width + "," + Constants.SimulationDomain.height + ")" + " Grid: " + fluidSim.m_grid.Count + " (" + fluidSim.m_grid.Width + "," + fluidSim.m_grid.Height + ")" + " CellSpace: " + Constants.CellSpace + " " ); particles = new UnityEngine.ParticleSystem.Particle[Constants.MAX_PARTICLES]; filter = renderer.GetComponent <MeshFilter>(); }
private static CollisionSolver IntersectPixels(Rectangle rectangleA, Color[] dataA, Rectangle rectangleB, Color[] dataB) { collisionType = "Per-Pixel"; CollisionSolver solver = new CollisionSolver(); int top = Math.Max(rectangleA.Top, rectangleB.Top); int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom); int left = Math.Max(rectangleA.Left, rectangleB.Left); int right = Math.Min(rectangleA.Right, rectangleB.Right); if (((rectangleA.Bottom > rectangleB.Top) && (rectangleA.Top < rectangleB.Bottom)))//&& ((rectangleA.Right < rectangleB.Left) && (rectangleB.Right > rectangleA.Left))) { solver.collided = true; if (rectangleA.Right > rectangleB.Left && rectangleA.Left < rectangleB.Right) { if (rectangleA.Center.X < rectangleB.Center.X) { solver.correctionVector.X = (rectangleA.Right - rectangleB.Left) * -1.0f; } else { solver.correctionVector.X = (rectangleB.Right - rectangleA.Left); } } if (rectangleA.Bottom > rectangleB.Top && rectangleA.Top < rectangleB.Bottom) { if (rectangleA.Center.Y > rectangleB.Center.Y) { solver.correctionVector.Y = (rectangleB.Top - rectangleA.Bottom) * -1.0f; } else { solver.correctionVector.Y = (rectangleB.Top - rectangleA.Bottom); } } return(solver); } /* * for (int y = top; y < bottom; y++) * { * for (int x = left; x < right; x++) * { * Color colorA = dataA[(x - rectangleA.Left) + * (y - rectangleA.Top) * rectangleA.Width]; * Color colorB = dataB[(x - rectangleB.Left) + * (y - rectangleB.Top) * rectangleB.Width]; * * if (colorA.A != 0 && colorB.A != 0) * { * solver.collided = true; * * if (rectangleA.Right > rectangleB.Left && rectangleA.Left < rectangleB.Right) * { * if (rectangleA.Center.X < rectangleB.Center.X) * { * solver.correctionVector.X = (rectangleA.Right - rectangleB.Left)*-1.0f; * } * else * { * solver.correctionVector.X = (rectangleB.Right - rectangleA.Left); * } * } * * if (rectangleA.Bottom > rectangleB.Top && rectangleA.Top < rectangleB.Bottom) * { * if (rectangleA.Center.Y > rectangleB.Center.Y) * { * solver.correctionVector.Y = (rectangleB.Top - rectangleA.Bottom) * -1.0f; * } * else * { * solver.correctionVector.Y = (rectangleB.Top - rectangleA.Bottom); * } * * } * * return solver; * } * } * }*/ solver.collided = false; return(solver); }
public static CollisionSolver CheckCollisionCustomBB(Vector2 pos1, Vector2 pos2, InteractiveObject char1, Rectangle bb, TimeSpan now, bool perPixel) { CollisionSolver solver = new CollisionSolver(); collisionType = "Bounding-Box"; if (char1.aSS != null) { Texture2D ss1 = char1.aSS.getSpriteSheet(); Rectangle collider1Range = char1.aSS.getCurrentFrame(now); collider1Range.X = (int)pos1.X; collider1Range.Y = (int)pos1.Y; bb.X = (int)pos2.X; bb.Y = (int)pos2.Y; Rectangle collider2Range = bb; if ((collider1Range.Left > collider2Range.Right && collider1Range.Right > collider2Range.Left) || (collider2Range.Left > collider1Range.Right && collider2Range.Right > collider1Range.Left) || (collider1Range.Top < collider2Range.Bottom && collider1Range.Bottom < collider2Range.Top) || (collider2Range.Top < collider1Range.Bottom && collider2Range.Bottom < collider1Range.Top)) { solver.collided = false; return(solver); } else { solver.collided = true; if (collider1Range.Right > collider2Range.Left && collider1Range.Left < collider2Range.Right) { if (collider1Range.Center.X < collider2Range.Center.X) { solver.correctionVector.X = (collider1Range.Right - collider2Range.Left) * -1.0f; } else { solver.correctionVector.X = (collider2Range.Right - collider1Range.Left); } } if (collider1Range.Bottom > collider2Range.Top && collider1Range.Top < collider2Range.Bottom) { if (collider1Range.Center.Y > collider2Range.Center.Y) { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom) * -1.0f; } else { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom); } } return(solver); } } else if (char1.aT != null) { Texture2D texture = char1.aT.getCurrentFrame(now); Rectangle collider1Range = new Rectangle(0, 0, texture.Width, texture.Height); bb.X = (int)pos2.X; bb.Y = (int)pos2.Y; Rectangle collider2Range = bb; collider1Range.X = (int)pos1.X; collider1Range.Y = (int)pos1.Y; collider2Range.X = (int)pos2.X; collider2Range.Y = (int)pos2.Y; if ((collider1Range.Left > collider2Range.Right && collider1Range.Right > collider2Range.Left) || (collider2Range.Left > collider1Range.Right && collider2Range.Right > collider1Range.Left) || (collider1Range.Top < collider2Range.Bottom && collider1Range.Bottom < collider2Range.Top) || (collider2Range.Top < collider1Range.Bottom && collider2Range.Bottom < collider1Range.Top)) { solver.collided = false; return(solver); } else { solver.collided = true; if (collider1Range.Right > collider2Range.Left && collider1Range.Left < collider2Range.Right) { if (collider1Range.Center.X < collider2Range.Center.X) { solver.correctionVector.X = (collider1Range.Right - collider2Range.Left) * -1.0f; } else { solver.correctionVector.X = (collider2Range.Right - collider1Range.Left); } } if (collider1Range.Bottom > collider2Range.Top && collider1Range.Top < collider2Range.Bottom) { if (collider1Range.Center.Y > collider2Range.Center.Y) { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom) * -1.0f; } else { solver.correctionVector.Y = (collider2Range.Top - collider1Range.Bottom); } } return(solver); } } solver.collided = false; return(solver); }
public void CalculateCollisionForce() { CollisionSolver.CalculateCollisionForce(_particle1, _particles); }
protected void HandleCollisions() { player.touchWallD = false; if (player.pos.Y + player.mov.Y + 32 > 92) { player.vel.Y = 0; player.mov.Y -= (player.pos.Y + player.mov.Y + 32 - 92); player.touchWallD = true; } foreach (var tile in EntityCollection.GetGroup("tiles")) { foreach (Entity enemy in EntityCollection.GetGroup("enemies")) { CollisionSolver.SolveEntTileCollision(enemy, tile); } } foreach (var tile in EntityCollection.GetGroup("tiles")) { foreach (Entity enemy in EntityCollection.GetGroup("enemies")) { CollisionSolver.SecondPassCollision(enemy, tile); } } foreach (var tile in EntityCollection.GetGroup("slots")) { if (tile.PredictIntersect(player, new Vector2(player.pos.X + player.mov.X - 33, 0))) { if (player.vel.Y < 0) { player.vel.Y = 0; } } } foreach (Entity en in EntityCollection.GetGroup("enemies")) { if (!en.isDestroyed && player.PredictIntersect(en)) { if (en.pos.Y - player.pos.Y > 16 && player.vel.Y > 0) { player.React("headJump"); en.React("headJump"); ParticleSystem.CreateInstance(en.pos + new Vector2(8, -16), "stars", true); SoundManager.PlayEffect("hit3"); } else if (!player.invin) { player.ToggleInvin(); inven.LoseHP(); SoundManager.PlayEffect("hit4"); } } } if (!player.Answer("sliding")) { foreach (var pickup in EntityCollection.GetGroup("pickups")) { bool x = false; foreach (FRectangle rect in player.MovHB()) { foreach (FRectangle rect2 in pickup.MovHB()) { if (rect.Intersects(rect2)) { if (pickup.exists) { x = true; } } } } if (x) { inven.AddItem(pickup.SubEntities()[0]); pickup.exists = false; } } } }
private Vector2 CollisionTest(Vector2 moveAmount) { Rectangle afterMoveRect = _collisionRectangle; Vector2 corner1, corner2; if (moveAmount.X != 0) { afterMoveRect.Offset((int)moveAmount.X, 0); corner1 = new Vector2( afterMoveRect.X + afterMoveRect.Width, afterMoveRect.Y + 0.0f); corner2 = new Vector2( afterMoveRect.X + afterMoveRect.Width, afterMoveRect.Y + afterMoveRect.Height - 80.0f); if (CollisionSolver.CheckCollisions( new Rectangle( (int)corner1.X, (int)corner1.Y, 1, Math.Abs((int)(corner1.Y - corner2.Y))), CollidingObjsReference)) { moveAmount.X = 0; Velocity.X = 0; } } if (moveAmount.Y == 0) { return(moveAmount); } else { afterMoveRect = _collisionRectangle; afterMoveRect.Offset((int)moveAmount.X, (int)moveAmount.Y); if (Velocity.Y > 0) { corner1 = new Vector2( afterMoveRect.X + 20.0f, afterMoveRect.Y + afterMoveRect.Height - 2.0f); corner2 = new Vector2( afterMoveRect.X + afterMoveRect.Width - 20.0f, afterMoveRect.Y + afterMoveRect.Height - 2.0f); int collIndex = CollisionSolver.CheckCollisionsReturnCollidedObject( new Rectangle( (int)corner1.X, (int)corner1.Y + 10, Math.Abs((int)(corner1.X - corner2.X)), 1), CollidingObjsReference); if (collIndex != -1) { OnGround = true; moveAmount.Y = 0; Velocity.Y = 0; ((GameObject)this).Position = new Vector2( ((GameObject)this).Position.X, MathHelper.Lerp( ((GameObject)this).Position.Y, CollidingObjsReference[collIndex].CollisionRectangle.Y - Height + 2, 0.1f)); } } } return(moveAmount); }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); IsMouseVisible = true; #region Adding Component: Random number generator RandomGenerator randomGenerator = new RandomGenerator(this); Components.Add(randomGenerator); #endregion #region Adding Component: InputManager InputManager inputMngr = new InputManager(this); ExitInputAction exitAction = new ExitInputAction(this); ExitInputCheckForKeyboard exitInput = new ExitInputCheckForKeyboard(); inputMngr.SetKeyBinding(exitInput, exitAction); FullscreenInputAction fullscreenAction = new FullscreenInputAction(_graphics); FullscreenInputCheckForKeyboard fullscreenInput = new FullscreenInputCheckForKeyboard(); inputMngr.SetKeyBinding(fullscreenInput, fullscreenAction); ToggleDebugModeInputCheckForKeyboard switchDebugModeInput = new ToggleDebugModeInputCheckForKeyboard(); ToggleDebugModeInputAction switchDebugModeAction = new ToggleDebugModeInputAction(this); inputMngr.SetKeyBinding(switchDebugModeInput, switchDebugModeAction); Components.Add(inputMngr); #endregion #region Adding Component: GameObject 1 GameObject testObject1 = new GameObject(this, "Textures/circle", "Textures/cross", "Textures/OutlineBox"); testObject1.Center = new Vector2(_graphics.PreferredBackBufferWidth * 0.5f, _graphics.PreferredBackBufferHeight * 0.5f); testObject1.Scale = 0.3f; Components.Add(testObject1); #endregion #region Disabled - Adding Component: GameObject 2 /*GameObject TestObject2 = new GameObject(this, "circle", "cross", "OutlineBox"); * TestObject2.Center = new Vector2(graphics.PreferredBackBufferWidth * 0.75f, graphics.PreferredBackBufferHeight * 0.75f); * TestObject2.Scale = 0.3f; * Components.Add(TestObject2);*/ #endregion #region Adding Component: Player PlayerObject gamePlayer = new PlayerObject(this, "Textures/circle", "Textures/cross", "Textures/OutlineBox"); gamePlayer.Center = new Vector2(_graphics.PreferredBackBufferWidth * 0.75f, _graphics.PreferredBackBufferHeight * 0.75f); gamePlayer.Scale = 0.3f; //gamePlayer.Speed = 0.01f; Components.Add(gamePlayer); GenericKeyboardValueInputCheck playerInput1 = new GenericKeyboardValueInputCheck(Microsoft.Xna.Framework.Input.Keys.A, -1, ButtonPressType.ButtonPress, "move_left"); inputMngr.SetKeyBinding(playerInput1, gamePlayer); GenericKeyboardValueInputCheck playerInput2 = new GenericKeyboardValueInputCheck(Microsoft.Xna.Framework.Input.Keys.W, -1, ButtonPressType.ButtonPress, "move_up"); inputMngr.SetKeyBinding(playerInput2, gamePlayer); GenericKeyboardValueInputCheck playerInput3 = new GenericKeyboardValueInputCheck(Microsoft.Xna.Framework.Input.Keys.S, 1, ButtonPressType.ButtonPress, "move_down"); inputMngr.SetKeyBinding(playerInput3, gamePlayer); GenericKeyboardValueInputCheck playerInput4 = new GenericKeyboardValueInputCheck(Microsoft.Xna.Framework.Input.Keys.D, 1, ButtonPressType.ButtonPress, "move_right"); inputMngr.SetKeyBinding(playerInput4, gamePlayer); DragInputCheckForMouse playerMouseInput1 = new DragInputCheckForMouse(MouseButtonType.Left, AxisType.X); inputMngr.SetKeyBinding(playerMouseInput1, gamePlayer); DragInputCheckForMouse playerMouseInput2 = new DragInputCheckForMouse(MouseButtonType.Left, AxisType.Y); inputMngr.SetKeyBinding(playerMouseInput2, gamePlayer); /*DragInputCheckForMouse playerMouseInput3 = new DragInputCheckForMouse(MouseButtonType.Right, AxisType.X); * DragInputCheckForMouse playerMouseInput4 = new DragInputCheckForMouse(MouseButtonType.Right, AxisType.Y); * * inputMngr.SetKeyBinding(playerMouseInput3, gamePlayer); * inputMngr.SetKeyBinding(playerMouseInput4, gamePlayer);*/ #endregion #region Adding Component: CollisionSolver CollisionSolver solver = new CollisionSolver(this); Components.Add(solver); #endregion #region Disabled - Adding Component: Event logger //EventLogger Logger = new EventLogger(this); //Components.Add(Logger); #endregion }
internal static void Update() { var invisibleTargets = ComboMenu.GetBoolean("invisible"); var interruptCast = ComboMenu.GetBoolean("interrupt"); //TODO Bubble detection var enemiesBase = Utilities.EnemiesBase; var enemiesProj = enemiesBase.Where(x => !x.HasProjectileBlocker()); if (!invisibleTargets) { enemiesBase = enemiesBase.Where(x => !x.CharacterModel.IsModelInvisible); enemiesProj = enemiesProj.Where(x => !x.CharacterModel.IsModelInvisible); } var TargetM1 = TargetSelector.GetTarget(enemiesProj, TargetMode, AH.M1.Range); var TargetM2 = TargetSelector.GetTarget(enemiesProj, TargetMode, AH.M2.Range); var TargetQNormal = TargetSelector.GetTarget(enemiesBase, TargetMode, AH.Q.Range); var TargetENear = TargetSelector.GetTarget(enemiesProj, TargetMode, ComboMenu.GetSlider("useE.near.safeRange")); var TargetR = TargetSelector.GetTarget(enemiesBase, TargetMode, AH.M1.Range); var TargetF = TargetSelector.GetTarget(enemiesBase, TargetMode, AH.F.Range); var hero = Utilities.Hero; var myPos = hero.MapObject.Position; Drawing.DrawCircle(myPos, 1f, UnityEngine.Color.green); if (TargetM1 != null) { var targetPos = TargetM1.MapObject.Position; var rPos = myPos.Extend(targetPos, 1f); Drawing.DrawCircle(rPos, 1f, UnityEngine.Color.magenta); } #region Aiming if (IsCasting) { LocalPlayer.EditAimPosition = true; switch (LastAbility) { case AbilitySlot.Ability7: if (TargetF != null) { var pred = AH.F.GetPrediction(TargetF, false, myPos); if (pred.CanHit) { LocalPlayer.Aim(pred.CastPosition); } else { LocalPlayer.Aim(InputManager.MousePosition.ScreenToWorld()); } } else { LocalPlayer.Aim(InputManager.MousePosition.ScreenToWorld()); } break; case AbilitySlot.EXAbility1: case AbilitySlot.Ability3: var bestPos = MathUtils.GetBestJumpPosition(0, 40, AH.Space.Range); LocalPlayer.Aim(bestPos); break; case AbilitySlot.EXAbility2: //Not Aimed break; case AbilitySlot.Ability6: if (TargetM1 != null) { var targetPos = TargetM1.MapObject.Position; var wallPos = myPos.Extend(targetPos, 1f); LocalPlayer.Aim(wallPos); } break; case AbilitySlot.Ability5: if (IsCondemning) { LocalPlayer.Aim(CondemnPos); } else if (TargetENear != null) { var pred = AH.E.GetPrediction(TargetENear, true, myPos, Utilities.TrueERange); if (pred.CanHit) { LocalPlayer.Aim(pred.CastPosition); } } break; case AbilitySlot.Ability4: if (IsChainingCC) { LocalPlayer.Aim(ChainCCPos); } else if (TargetQNormal != null) { var pred = AH.Q.GetPrediction(TargetQNormal, false, myPos); if (pred.CanHit) { LocalPlayer.Aim(pred.CastPosition); } else { AH.Interrupt.Cast(); } } else { AH.Interrupt.Cast(); } break; case AbilitySlot.Ability2: if (TargetM2 != null) { var pred = AH.M2.GetPrediction(TargetM2, true, myPos); if (pred.CanHit) { LocalPlayer.Aim(pred.CastPosition); } else { if (interruptCast) { AH.Interrupt.Cast(); } } } else { if (interruptCast) { AH.Interrupt.Cast(); } } break; case AbilitySlot.Ability1: if (TargetM1 != null) { var pred = AH.M1.GetPrediction(TargetM1, true, myPos); if (pred.CanHit) { LocalPlayer.Aim(pred.CastPosition); } else { if (interruptCast) { AH.Interrupt.Cast(); } } } else { if (interruptCast) { AH.Interrupt.Cast(); } } break; } } else { IsChainingCC = false; IsCondemning = false; LocalPlayer.EditAimPosition = false; LastAbility = null; } #endregion #region Casting if (LastAbility == null && !IsCasting && !hero.IsDashing && !hero.IsTraveling) { var priorityM1 = ComboMenu.GetBoolean("useM1.priority"); if (ComboMenu.GetBoolean("useF") && AH.F.IsReady && TargetF != null) { var pred = AH.F.GetPrediction(TargetF, false, myPos); if (pred.CanHit) { AH.F.Cast(); return; } } if (ComboMenu.GetBoolean("useEX1") && AH.EX1.IsReady) { if (hero.EnemiesAroundAlive(JumpSafeRange) > 0) { var minHP = ComboMenu.GetSlider("useEX1.minHP"); var energyReq = ComboMenu.GetIntSlider("useEX1.energy") * 25; if (hero.Living.HealthPercent <= minHP && hero.Energized.Energy >= energyReq) { AH.EX1.Cast(); return; } } } if (ComboMenu.GetBoolean("useSpace") && AH.Space.IsReady) { if (hero.EnemiesAroundAlive(JumpSafeRange) > 0) { AH.Space.Cast(); return; } } if (AH.EX2.IsReady) { var energyReq = ComboMenu.GetIntSlider("useEX2.energy") * 25; if (hero.Energized.Energy >= energyReq) { if (ComboMenu.GetBoolean("useEX2.enemies")) { var count = ComboMenu.GetIntSlider("useEX2.enemies.count"); if (hero.EnemiesAroundAlive(AH.EX2.Range) >= count) { AH.EX2.Cast(); return; } } if (ComboMenu.GetBoolean("useEX2.panic")) { var minHP = ComboMenu.GetSlider("useEX2.panic.minHP"); if (hero.EnemiesAroundAlive(AH.EX2.Range) > 0 && hero.Living.HealthPercent <= minHP) { AH.EX2.Cast(); return; } } } } //if (ComboMenu.GetBoolean("useR.harass") && AH.R.IsReady && AH.M1.IsReady && TargetM1 != null // && BM.HasConflagration) //{ // var energyReq = ComboMenu.GetIntSlider("useR.harass.energy") * 25; // if (hero.Energized.Energy >= energyReq) // { // var pred = AH.M1.GetPrediction(TargetM1, true, myPos); // if (pred.CanHit) // { // AH.R.Cast(); // return; // } // } //} if (AH.E.IsReady) { var trueERange = Utilities.TrueERange; if (ComboMenu.GetBoolean("useE.condemn") && BM.HasKnockout) { var enemies = enemiesBase .Where(x => !x.IsCountering) .OrderBy(x => x.MapObject.ScreenPosition.Distance(InputManager.MousePosition)); foreach (var enemy in enemies) { if (enemy.Distance(hero) > trueERange) { continue; } var pred = AH.E.GetPrediction(enemy, true, myPos, trueERange); if (pred.CanHit) { var direction = pred.CastPosition - myPos; var distance = pred.CastPosition.Distance(myPos); var extendedPos = (direction.Normalized * (distance + 4.5f)) + myPos; Drawing.DrawCircle(extendedPos, 1f, UnityEngine.Color.red); var col = CollisionSolver.CheckLineCollision(pred.CastPosition, extendedPos); if (col.IsColliding) { IsCondemning = true; CondemnPos = pred.CastPosition; AH.E.Cast(); return; } } } } if (ComboMenu.GetBoolean("useE.near") && TargetENear != null) { var pred = AH.E.GetPrediction(TargetENear, true, myPos, trueERange); if (pred.CanHit) { AH.E.Cast(); return; } } } if (!(priorityM1 && HasEnhancedM1)) { if (AH.Q.IsReady) { if (ComboMenu.GetBoolean("useQ")) { if (!ComboMenu.GetBoolean("useQ.chainCC") && TargetQNormal != null) { var pred = AH.Q.GetPrediction(TargetQNormal, false, myPos); if (pred.CanHit) { AH.Q.Cast(); return; } } else if (ComboMenu.GetBoolean("useQ.chainCC")) { var enemies = enemiesBase; foreach (var enemy in enemies) { if (enemy.Distance(hero) <= AH.Q.Range && enemy.HasHardCC() && enemy.CCTotalDuration >= 1.5f) { IsChainingCC = true; ChainCCPos = enemy.MapObject.Position; AH.Q.Cast(); return; } } } } } if (ComboMenu.GetBoolean("useM2") && AH.M2.IsReady && TargetM2 != null) { var safeRange = ComboMenu.GetSlider("useM2.safeRange"); if (hero.EnemiesAroundAlive(safeRange) == 0) { var pred = AH.M2.GetPrediction(TargetM2, true, myPos); if (pred.CanHit) { AH.M2.Cast(); return; } } } } if (ComboMenu.GetBoolean("useM1") && AH.M1.IsReady && TargetM1 != null) { var pred = AH.M1.GetPrediction(TargetM1, true, myPos); if (pred.CanHit) { AH.M1.Cast(); return; } } } #endregion }
public static bool HasCollisionLineToPos(this Character player, Vector2 targetPos) { var col = CollisionSolver.CheckLineCollision(player.MapObject.Position, targetPos); return(col.IsColliding); }
/// <summary> /// Gets the prediction. /// </summary> /// <param name="fromPos">Position where projectile gets fired from.</param> /// <param name="targetUnit">The target unit.</param> /// <param name="range">The ability range.</param> /// <param name="speed">The ability speed.</param> /// <param name="radius">The ability radius (for collision).</param> /// <param name="fixedDelay">The fixed delay. If greater than 0, will use this fixed delay for calculations instead of getting normal best position prediction</param> /// <param name="maxEnemyReactionTime">The maximum enemy reaction time in seconds to calculate HitChance.</param> /// <param name="checkCollision">If set to <c>true</c> [check collision].</param> /// <param name="ignoreFlags">The ignore flags for collision calculations.</param> /// <returns>TestOutput</returns> public static TestOutput GetPrediction(Vector2 fromPos, InGameObject targetUnit, float range, float speed, float radius = 0f, float fixedDelay = 0f, float maxEnemyReactionTime = 1.75f, bool checkCollision = false, CollisionFlags ignoreFlags = CollisionFlags.Bush | CollisionFlags.NPCBlocker) { MapGameObject mapGameObject = targetUnit.Get <MapGameObject>(); NetworkMovementObject networkMovementObject = targetUnit.Get <NetworkMovementObject>(); if (mapGameObject == null) { Logs.Error("TestPrediction: Object of name " + targetUnit.ObjectName + " has no MapGameObject model"); return(new TestOutput() { CanHit = false, Hitchance = TestHitchance.Impossible, CastPosition = Vector2.Zero, }); } var targetPos = mapGameObject.Position; if (networkMovementObject == null) { Logs.Error("TestPrediction: Object of name " + targetUnit.ObjectName + " has no NetworkMovementObject model"); return(new TestOutput() { CanHit = targetPos.Distance(fromPos) <= range ? true : false, Hitchance = targetPos.Distance(fromPos) <= range ? TestHitchance.VeryHigh : TestHitchance.OutOfRange, HitchancePercentage = targetPos.Distance(fromPos) <= range ? 100f : 0f, CastPosition = targetPos, }); } var targetVelocity = networkMovementObject.Velocity; var targetRadius = targetUnit.Get <SpellCollisionObject>().SpellCollisionRadius; //TODO: Check if MapCollisionRadius is better if (fixedDelay < float.Epsilon) //No fixed delay { var predPos = GetStandardPrediction(fromPos, targetPos, speed, targetVelocity); if (predPos == Vector2.Zero) { return(new TestOutput() { CanHit = false, Hitchance = TestHitchance.Impossible, CastPosition = Vector2.Zero, }); } TestOutput solution = new TestOutput() { CanHit = true, CastPosition = predPos, }; var targetCollision = CollisionSolver.CheckThickLineCollision(targetPos, solution.CastPosition, targetRadius); if (targetCollision != null && targetCollision.IsColliding) { solution.CastPosition = targetCollision.CollisionPoint; } if (solution.CastPosition.Distance(fromPos) > range) { solution.CanHit = false; solution.Hitchance = TestHitchance.OutOfRange; } if (checkCollision) { solution.CollisionResult = CollisionSolver.CheckThickLineCollision(fromPos, solution.CastPosition, radius < float.Epsilon ? 0.01f : radius, ignoreFlags); if (solution.CollisionResult.IsColliding) { solution.CanHit = false; solution.Hitchance = TestHitchance.Collision; } } solution.HitchancePercentage = GetHitchance(fromPos, solution.CastPosition, speed, maxEnemyReactionTime, false); solution.Hitchance = GetHitchanceEnum(solution.HitchancePercentage); return(solution); } else //WITH fixed delay { var predPos = GetFixedDelayPrediction(targetPos, fixedDelay, targetVelocity); TestOutput solution = new TestOutput() { CanHit = true, CastPosition = predPos, }; var targetCollision = CollisionSolver.CheckThickLineCollision(targetPos, solution.CastPosition, targetRadius); if (targetCollision != null && targetCollision.IsColliding) { solution.CastPosition = targetCollision.CollisionPoint; } if (solution.CastPosition.Distance(fromPos) > range) { solution.CanHit = false; solution.Hitchance = TestHitchance.OutOfRange; } solution.HitchancePercentage = GetHitchance(fromPos, solution.CastPosition, fixedDelay, maxEnemyReactionTime, true); solution.Hitchance = GetHitchanceEnum(solution.HitchancePercentage); return(solution); } }
public void SetupQuadTree() { CollisionQuad = new QuadTree(0, new BoundingRectangle(0, 0, Controller.WorldBounds.Width, Controller.WorldBounds.Height)); CollisionSolver = new CollisionSolver(CollisionQuad); }