public bool hitTest(Entity other) { bool returnValue = false; returnValue |= !(position.X > other.position.X + other.dimensions.X || position.X + dimensions.X <other.position.X || position.Y> other.position.Y + other.dimensions.Y || position.Y + dimensions.Y < other.position.Y); if (HasSecondaryHitBoxes) { for (int j = 0; j < secondaryHitBoxes.Length; j++) { returnValue |= SecondaryHitBox.hitTestBoxEntity(secondaryHitBoxes[j], other); } } if (other.HasSecondaryHitBoxes) { for (int i = 0; i < other.SecondaryHitBoxes.Length; i++) { returnValue |= SecondaryHitBox.hitTestBoxEntity(other.SecondaryHitBoxes[i], this); if (HasSecondaryHitBoxes) { for (int j = 0; j < secondaryHitBoxes.Length; j++) { returnValue |= SecondaryHitBox.hitTestBoxWithBox(secondaryHitBoxes[j], other.SecondaryHitBoxes[i]); } } } } return(returnValue); }
public SnakeWorm(LevelState parentWorld, Vector2 position) { this.parentWorld = parentWorld; this.position = position; this.dimensions = new Vector2(24); snakeState = SnakeWormState.Moving; velocity = Vector2.Zero; direction = (float)(Game1.rand.NextDouble() * Math.PI * 2); dirModifier = 1.0f; switchTimer = 0.0f; switchDuration = averageSwitchDuration; enemy_life = 16; enemy_type = EnemyType.Alien; prob_item_drop = 0.3; number_drop_items = 4; tailData = new TailPosition[tailPiecesCount, positionsCount]; tailMostRecent = 0; for (int j = 0; j < tailPiecesCount; j++) { for (int i = 0; i < positionsCount; i++) { tailData[j, i] = new TailPosition(position, direction); } } secondaryHitBoxes = new SecondaryHitBox[secondaryHitBoxCount]; for (int i = 0; i < secondaryHitBoxCount; i++) { secondaryHitBoxes[i] = new SecondaryHitBox(position, new Vector2(16)); } testAnim = AnimationLib.getFrameAnimationSet("snakeA"); tailAnimA = AnimationLib.getFrameAnimationSet("snakeB"); tailAnimB = AnimationLib.getFrameAnimationSet("snakeC"); animation_time = 0; }
public static bool hitTestBoxWithBox(SecondaryHitBox boxA, SecondaryHitBox boxB) { return(!(boxA.Position.X > boxB.Position.X + boxB.Dimensions.X || boxA.Position.X + boxA.Dimensions.X < boxB.Position.X || boxA.Position.Y > boxB.Position.Y + boxB.Dimensions.Y || boxA.Position.Y + boxA.Dimensions.Y < boxB.Position.Y)); }
public static bool hitTestBoxEntity(SecondaryHitBox box, Entity other) { return(!(box.Position.X > other.position.X + other.dimensions.X || box.Position.X + box.Dimensions.X < other.position.X || box.Position.Y > other.position.Y + other.dimensions.Y || box.Position.Y + box.Dimensions.Y < other.position.Y)); }