private void findOtherCollideds(SpriteProperties.Directions mainDirection, RectangleF thisrect, Material mainMaterial, PointF CameraLocation) { for (int i = 0; i < this.Properties.GameScreen.Materials.Count; i++) { if (this.Properties.GameScreen.Materials[i] != this && this.Properties.GameScreen.Materials[i] != mainMaterial && this.Properties.GameScreen.Materials[i].Properties.isCollisionable) { RectangleF matrect = AddRect(this.Properties.GameScreen.Materials[i].Properties.CollisionRect, CameraLocation); if (this.Properties.GameScreen.Materials[i].Properties.isRotate) { matrect = FindRotateRectangle(matrect, this.Properties.GameScreen.Materials[i].Properties.RotateAngle); } if (isCollision(thisrect, matrect)) { SpriteProperties.Directions Direction = FindCollidedDirection(this.Properties.GameScreen.Materials[i], CameraLocation); if (Direction != SpriteProperties.Directions.None && Direction == mainDirection) { RectangleF rect = this.Properties.CollisionRect; this.WeCollided(this.Properties.GameScreen.Materials[i], Direction, CameraLocation); this.Properties.GameScreen.Materials[i].OtherCollided(this, Direction, CameraLocation); this.Properties.CollisionRect = rect; } } } } }
public override bool OtherCollided(Sprite sprite, SpriteProperties.Directions collidedDirection, PointF CameraLocation) { //if (sprite.GetType() == typeof(Bullets.ShipFire)) return false; //if (sprite.GetType() == typeof(Bullets.Fire) || sprite.GetType() == typeof(Bullets.Bullet)) //{ // sprite.Properties.isALive = false; // isdie = true; // return false; //} return(false); }
public override bool OtherCollided(Sprite sprite, SpriteProperties.Directions collidedDirection, PointF CameraLocation) { if (sprite.GetType() == typeof(Bullets.Fire)) { return(false); } if (sprite.GetType() == typeof(Bullets.Bullet) || sprite.GetType() == typeof(Bullets.ShipFire)) { isdead = true; return(false); } return(false); }
public override void WeCollided(Core.Sprite.Sprite sprite, SpriteProperties.Directions collidedDirection, PointF CameraLocation) { if (sprite.GetType() == typeof(Bullets.Fire)) { return; } if (sprite.GetType() == typeof(Bullets.Bullet) || sprite.GetType() == typeof(Bullets.ShipFire)) { isdead = true; return; } if (collidedDirection == SpriteProperties.Directions.Up) { jumping = false; JumpLength = RectangleF.Empty; if (this.Properties.VelocityRect.X == 0) { if (!crouch) { this.setAnimation(0); } else { this.setAnimation(2); } } else { if (sprite.Properties.VelocityRect.X == this.Properties.VelocityRect.X) { this.setAnimation(0); } else { if (run) { this.setAnimation(4); } else { this.setAnimation(1); } } } } if (collidedDirection == SpriteProperties.Directions.Down) { jumping = false; } }
private void LookMaterialForCollision(RectangleF thisrect, Material material, PointF CameraLocation, ref bool Gravity) { RectangleF matrect = AddRect(material.Properties.CollisionRect, CameraLocation); if (material.Properties.isRotate) { matrect = FindRotateRectangle(matrect, material.Properties.RotateAngle); } if (isCollision(thisrect, matrect)) { SpriteProperties.Directions Direction = FindCollidedDirection(material, CameraLocation); if (Direction != SpriteProperties.Directions.None) { findOtherCollideds(Direction, thisrect, material, CameraLocation); this.WeCollided(material, Direction, CameraLocation); Gravity = material.OtherCollided(this, Direction, CameraLocation); } } }
public virtual bool OtherCollided(Sprite sprite, SpriteProperties.Directions collidedDirection, PointF CameraLocation) { RectangleF thisrect = this.Properties.CollisionRect; RectangleF spriterect = sprite.Properties.CollisionRect; if (this.Properties.isRotate) { thisrect = FindRotateRectangle(thisrect, this.Properties.RotateAngle); } if (sprite.Properties.isRotate) { spriterect = FindRotateRectangle(spriterect, sprite.Properties.RotateAngle); } bool result = false; if (collidedDirection == SpriteProperties.Directions.Left) { spriterect.X = thisrect.X - spriterect.Width; result = true; } if (collidedDirection == SpriteProperties.Directions.Right) { spriterect.X = thisrect.X + thisrect.Width; result = true; } if (collidedDirection == SpriteProperties.Directions.Up) { spriterect.Y = thisrect.Y - spriterect.Height; } if (collidedDirection == SpriteProperties.Directions.Down) { spriterect.Y = thisrect.Y + thisrect.Height; } sprite.Properties.CollisionRect = spriterect; return(result); }
private SpriteProperties.Directions FindCollidedDirection(Sprite sprite, PointF CameraLocation) { RectangleF collided = this.Properties.CollisionRect, affected = sprite.Properties.CollisionRect; RectangleF velocity = new RectangleF((this.Properties.VelocityRect.X * this.Properties.GameScreen.time), (this.Properties.VelocityRect.Y * this.Properties.GameScreen.time), (this.Properties.VelocityRect.Width * this.Properties.GameScreen.time), (this.Properties.VelocityRect.Height * this.Properties.GameScreen.time)); if (this.Properties.isRotate) { velocity = new RectangleF((this.Properties.RotateStep * this.Properties.GameScreen.time), (this.Properties.RotateStep * this.Properties.GameScreen.time), (this.Properties.VelocityRect.Width * this.Properties.GameScreen.time), (this.Properties.VelocityRect.Height * this.Properties.GameScreen.time)); } collided = AddRect(collided, CameraLocation); affected = AddRect(affected, CameraLocation); if (this.Properties.isRotate) { collided = FindRotateRectangle(collided, this.Properties.RotateAngle); } if (sprite.Properties.isRotate) { affected = FindRotateRectangle(affected, sprite.Properties.RotateAngle); } SpriteProperties.Directions Direction = SpriteProperties.Directions.None; if (CollisionHelper.CollisionUp(collided, affected, velocity)) { if ((velocity.Y == 0 && !this.Properties.isRotate) || (this.Properties.RotateStep == 0 && this.Properties.isRotate)) { return(SpriteProperties.Directions.None); } Direction = SpriteProperties.Directions.Up; } else if (CollisionHelper.CollisionDown(collided, affected, velocity)) { if ((velocity.Y == 0 && !this.Properties.isRotate) || (this.Properties.RotateStep == 0 && this.Properties.isRotate)) { return(SpriteProperties.Directions.None); } Direction = SpriteProperties.Directions.Down; } else if (CollisionHelper.CollisionLeft(collided, affected, velocity)) { if ((velocity.X == 0 && !this.Properties.isRotate) || (this.Properties.RotateStep == 0 && this.Properties.isRotate)) { return(SpriteProperties.Directions.None); } Direction = SpriteProperties.Directions.Left; } else if (CollisionHelper.CollisionRight(collided, affected, velocity)) { if ((velocity.X == 0 && !this.Properties.isRotate) || (this.Properties.RotateStep == 0 && this.Properties.isRotate)) { return(SpriteProperties.Directions.None); } Direction = SpriteProperties.Directions.Right; } return(Direction); }
public virtual void WeCollided(Sprite sprite, SpriteProperties.Directions collidedDirection, PointF CameraLocation) { }