public void TestCanHit() { var objectVelocity = new Vector(0, 1); Assert.IsNotNull(DynamicCollisionDetector.AreCollideWithStatic(StartPosition, objectVelocity, StaticBodyCircle)); Assert.IsNotNull(DynamicCollisionDetector.AreCollideWithStatic(StartPosition, objectVelocity, StaticBodyAABB)); }
private void CalculateEntityRespond(LivingEntity entity, Bullet bullet, List <AbstractParticleUnit> levelParticles) { var penetrationTimes = DynamicCollisionDetector.AreCollideWithDynamic(bullet, entity.CollisionShape, entity.Velocity); if (penetrationTimes == null) { return; } var penetrationPlace = bullet.Position + bullet.Velocity * penetrationTimes[0]; entity.TakeHit(bullet.Damage); if (entity.Armor > 50) { bullet.IsStuck = true; levelParticles.Add(ParticleFactory.CreateSmallBloodSplash(penetrationPlace)); } else { bullet.SlowDown(); levelParticles.Add(ParticleFactory.CreateBloodSplash(penetrationPlace)); levelParticles.Add(ParticleFactory.CreateBloodSplash(penetrationPlace)); } if (entity.IsDead) { if (!entity.Velocity.Equals(Vector.ZeroVector)) { entity.MoveTo(entity.CollisionShape.Center + entity.Velocity * penetrationTimes[0]); } HandleKill(entity, entity.Position - bullet.Position, levelParticles); } }
public void TestCheckTime() { var objectVelocity = new Vector(0, 1); var resultTime = new float[] { 1, 3 }; Assert.AreEqual(resultTime, DynamicCollisionDetector.AreCollideWithStatic(StartPosition, objectVelocity, StaticBodyCircle)); Assert.AreEqual(resultTime, DynamicCollisionDetector.AreCollideWithStatic(StartPosition, objectVelocity, StaticBodyAABB)); }
private void CalculateStaticPenetrations(Bullet bullet) { var staticShapes = currentLevel.StaticShapes; foreach (var obstacle in staticShapes) { var penetrationTime = DynamicCollisionDetector.AreCollideWithStatic(bullet, obstacle); if (penetrationTime == null) { continue; } var distanceToPenetrations = new float[2]; for (var i = 0; i < 2; i++) { distanceToPenetrations[i] = bullet.Speed * penetrationTime[i]; } bullet.StaticPenetrations.Add(distanceToPenetrations); } bullet.CalculateTrajectory(); }
private void Dash(Core.KeyStates keyState, List <RigidShape> sceneStaticShapes) { CreateVelocity(keyState, DashSpeed); if (Equals(Velocity, Vector.ZeroVector)) { return; } var firstPosition = Position + Velocity.Normalize() * (Radius - 1); var closestPenetrationTime = float.PositiveInfinity; foreach (var shape in sceneStaticShapes) { var penetrationTimes = DynamicCollisionDetector.AreCollideWithStatic(firstPosition, Velocity, shape); if (penetrationTimes == null) { continue; } if (penetrationTimes[0] < 1 && penetrationTimes[0] < closestPenetrationTime && penetrationTimes[0] > 0) { closestPenetrationTime = penetrationTimes[0]; } } if (closestPenetrationTime < 1) { Velocity *= closestPenetrationTime; } ticksFromLastDash = 0; dashCount++; if (dashCount == 3) { dashCount = 1; } }