}/* * private void UpdateCollisionPoints() * { * CollisionTop = new Point(CollisionRectangle.Center.X, CollisionRectangle.Top - 1); * CollisionBottom = new Point(CollisionRectangle.Center.X, CollisionRectangle.Bottom + 1); * CollisionLeft = new Point(CollisionRectangle.Left - 1, CollisionRectangle.Center.Y); * CollisionRight = new Point(CollisionRectangle.Right + 1, CollisionRectangle.Center.Y); * }*/ public virtual Vector2 CollisionFix(IPhysicsHandler physics, ICollision objectA) { if (objectA is BulletCollision) { } return(new Vector2(0, 0)); }
public void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics) { if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Bottom + 1, rectangle.Width, 0)) && physics.JumpingDown == false && rectangle.Bottom - 0.1f < CollisionRectangle.Top) { physics.OnGround = true; } }
public virtual void HanldeCollisions(IPhysicsHandler physics, ITransform transform) { UpdateRectangle(transform.Position); Vector2 collisionDisplacment = new Vector2(0, 0); foreach (var collidableObject in collidableObstacles) { if (CollisionUtilities.CheckRectangleCollision(CollisionRectangle, collidableObject.CollisionRectangle)) //Check of er een collision is { collisionDisplacment = collidableObject.CollisionFix(physics, this); //Los collision op met collisionfix van object waartegen gebotst werd } } transform.Position += collisionDisplacment; UpdateRectangle(transform.Position); physics.CollisionLeft = false; physics.CollisionRight = false; physics.OnGround = false; physics.CollisionTop = false; foreach (var objectB in collidableObstacles) //Check of je ergens opstaat of niet { objectB.CollisionCheck(CollisionRectangle, physics); } UpdateRectangle(transform.Position); //Opnieuw update want nieuwe positie CollisionRectangleOld = CollisionRectangle; }
public override void HanldeCollisions(IPhysicsHandler physics, ITransform transform) { UpdateRectangle(transform.Position); foreach (var collidableObject in collidableObstacles) { if (CollisionUtilities.CheckRectangleCollision(CollisionRectangle, collidableObject.CollisionRectangle)) //Check of er een collision is { Explode(collidableObstacles); } } CollisionRectangleOld = CollisionRectangle; }
public Vector2 CollisionFix(IPhysicsHandler physics, ICollision objectA) { int heroCenterX = objectA.CollisionRectangleOld.Center.X; int obstacleLeft = CollisionRectangle.Left; int obstacleRight = CollisionRectangle.Right; int obstacleTop = CollisionRectangle.Top; if (heroCenterX > obstacleLeft && heroCenterX < obstacleRight && objectA.CollisionRectangleOld.Bottom - 1 < obstacleTop && physics.JumpingDown == false) { physics.VelocityY = 0; return(new Vector2(0, obstacleTop - objectA.CollisionRectangle.Bottom)); //Naar boven } return(new Vector2(0, 0)); }
public override void HanldeCollisions(IPhysicsHandler physics, ITransform transform) { UpdateRectangle(transform.Position); foreach (var collidableObject in collidableObstacles) { if (CollisionUtilities.CheckRectangleCollision(CollisionRectangle, collidableObject.CollisionRectangle)) //Check of er een collision is { if (collidableObject.Parent is Human) { ((Human)collidableObject.Parent).Health -= ((Bullet)Parent).Damage; //Als het mens is verminder HP met 1 ((Human)collidableObject.Parent).Hit = true; } Parent.Alive = false; //Bullet destroys itself when hit } } CollisionRectangleOld = CollisionRectangle; }
public void Update(GameTime gameTime, IPhysicsHandler physics, ICollision hero, ITransform transform) { OldAnimation = CurrentAnimation; bool reset = false; if (CurrentAnimation == 0 || CurrentAnimation == 1) { if (animations[CurrentAnimation].FrameNumber >= animations[CurrentAnimation].frames.Count - 1) { CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 2 : 3; } else { CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 0 : 1; } } else { CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 2 : 3; } if (Shoot) { reset = true; Shoot = false; CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 0 : 1; animations[CurrentAnimation].FrameNumber = 0; } animations[CurrentAnimation].Update(gameTime, reset); //Update animaties Vector2 direction = Mouse.Position - new Vector2(hero.CollisionRectangle.X, hero.CollisionRectangle.Y); transform.Rotation = MathUtilities.VectorToAngle(direction); if (Mouse.Position.X < hero.CollisionRectangle.Center.X) { transform.Rotation += (float)Math.PI; } }
public void Update(GameTime gameTime, IPhysicsHandler physics, ICollision hero, ITransform transform) { OldAnimation = CurrentAnimation; float animationSpeed = 5; //Reset snelheid //If state then animation enz. if (physics.OnGround) { int threshold = 30; //Ontdendering if (OldAnimation == 2 || OldAnimation == 3) { threshold = 20; } if (physics.VelocityX < threshold && physics.VelocityX > -threshold) { CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 0 : 1; } else { animationSpeed = Math.Abs(physics.VelocityX) / 20f; CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 2 : 3; } } else { CurrentAnimation = Mouse.Position.X < hero.CollisionRectangle.Center.X ? 4 : 5; } bool reset = false; if (CurrentAnimation != OldAnimation) { animations[CurrentAnimation].CurrentFrame = animations[CurrentAnimation].frames[0]; reset = true; } animations[CurrentAnimation].FramesPerSecond = animationSpeed; animations[CurrentAnimation].Update(gameTime, reset); //Update animaties }
public void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics) { //Point CollisionTop = new Point(rectangle.Center.X, rectangle.Top - 1); //Point CollisionBottom = new Point(rectangle.Center.X, rectangle.Bottom + 1); Point CollisionLeft = new Point(rectangle.Left - 1, rectangle.Center.Y); Point CollisionRight = new Point(rectangle.Right + 1, rectangle.Center.Y); if (CollisionRectangle.Contains(CollisionLeft)) { physics.CollisionLeft = true; } if (CollisionRectangle.Contains(CollisionRight)) { physics.CollisionRight = true; } if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Bottom + 1, rectangle.Width, 0))) { physics.OnGround = true; } if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Top - 1, rectangle.Width, 0))) { physics.CollisionTop = true; } }
public override Vector2 CollisionFix(IPhysicsHandler physics, ICollision objectA) { return(((BulletPhysicsHandler)physics).Direction * 0.2f); //Duw object weg waartegen gebotst wordt }
public override void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics) { //throw new NotImplementedException(); }
public void HanldeCollisions(IPhysicsHandler physics, ITransform transform) { //Voor bewegende platformen, niet gebruikt }
public void Initialize(Vector3 gravity, int seed) { TerrainContext = new TerrainContext(seed); PhysicsHandler = new JitterPhysicsHandler(gravity); EntityHandler = new EntityHandler(); }
public void HanldeCollisions(IPhysicsHandler physics, ITransform transform) { // }
public virtual void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics) { //throw new NotImplementedException(); nog niet nodig }
public Vector2 CollisionFix(IPhysicsHandler physics, ICollision objectA) { int heroCenterX = objectA.CollisionRectangleOld.Center.X; int heroCenterY = objectA.CollisionRectangleOld.Center.Y; int obstacleLeft = CollisionRectangle.Left; int obstacleRight = CollisionRectangle.Right; int obstacleBottom = CollisionRectangle.Bottom; int obstacleTop = CollisionRectangle.Top; if (obstacleLeft < heroCenterX && heroCenterX < obstacleRight) //ObjectA is boven of onder ObjectB { if (heroCenterY < obstacleBottom) { physics.VelocityY = 0; return(new Vector2(0, obstacleTop - objectA.CollisionRectangle.Bottom)); //Naar boven } else { physics.VelocityY = 0; return(new Vector2(0, obstacleBottom - objectA.CollisionRectangle.Top)); //Naar beneden } } else if (obstacleTop < heroCenterY && heroCenterY < obstacleBottom) //ObjectA is links of rechts van ObjectB { if (heroCenterX < obstacleLeft) { physics.VelocityX = 0; return(new Vector2(obstacleLeft - objectA.CollisionRectangle.Right, 0)); //Naar links } else { physics.VelocityX = 0; return(new Vector2(obstacleRight - objectA.CollisionRectangle.Left, 0)); //Naar rechts } } else if (obstacleTop > heroCenterY) //ObjectA is linksboven of rechtsboven ObjectB { if (heroCenterX < obstacleLeft) { int left = objectA.CollisionRectangle.Right - obstacleLeft; int top = objectA.CollisionRectangle.Bottom - obstacleTop; if (left > top) { physics.VelocityY = 0; return(new Vector2(0, -top)); //Naar boven } else { physics.VelocityX = 0; return(new Vector2(0, -left)); //Naar links } } else { int right = obstacleRight - objectA.CollisionRectangle.Left; int top = objectA.CollisionRectangle.Bottom - obstacleTop; if (right > top) { physics.VelocityY = 0; return(new Vector2(0, -top)); //Naar boven } else { physics.VelocityX = 0; return(new Vector2(right, 0)); //Naar rechts } } } else //ObjectA is linksonder of rechtsonder ObjectB { if (heroCenterX < obstacleLeft) { int left = objectA.CollisionRectangle.Right - obstacleLeft; int bottom = obstacleBottom - objectA.CollisionRectangle.Top; if (left > bottom) { physics.VelocityY = 0; return(new Vector2(0, -bottom)); //Naar beneden } else { physics.VelocityX = 0; return(new Vector2(-left, 0)); //Naar links } } else { int right = obstacleRight - objectA.CollisionRectangle.Left; int bottom = obstacleBottom - objectA.CollisionRectangle.Top; if (right > bottom) { physics.VelocityY = 0; return(new Vector2(0, bottom)); //Naar beneden } else { physics.VelocityX = 0; return(new Vector2(right, 0)); //Naar rechts } } } }
public void Initialize(GameContext context, Vector2i viewDistance, Vector3 gravity, int seed) { TerrainContext = new TerrainContext(context, viewDistance, seed); PhysicsHandler = new JitterPhysicsHandler(gravity); EntityHandler = new EntityHandler(); }