public void OnCollisionWithEntity(GameObjectBase entity) { MouseState state = Mouse.GetState(); if (entity != null && state.LeftButton == ButtonState.Pressed) { EnemyGameObject enemy = entity as EnemyGameObject; if (enemy != null) { if (enemy.IsAlive) { player.CanAttack = true; player.target = enemy; } return; } PotionGameObject potion = entity as PotionGameObject; if (potion != null) { player.target = potion; player.retrieveItem = true; return; } //SelectEnemy?.Invoke((object)enemy, new CollisionEventArgs(enemy.Position)); } }
public void ResolveRemovals() { List <Collidable> toRemove = new List <Collidable>(); for (int i = 0; i < entities.Count; i++) { PotionGameObject potion = entities[i] as PotionGameObject; if (potion != null) { if (potion.flagForRemoval) { toRemove.Add(potion); entities.RemoveAt(i); } } } for (int i = 0; i < toRemove.Count; i++) { for (int j = 0; j < potions.Count; j++) { if (toRemove[i].Equals(potions[j])) { potions.RemoveAt(i); GameInfo.Instance.HealthPotionInfoArray.RemoveAt(i); //both arrays populated at the same time, so indexes should be the same } } } collisionManager.RemoveCollidable(toRemove); }
public override bool CollisionTest(Collidable col) { if (col != null) { EnemyGameObject enemy = col as EnemyGameObject; if (enemy != null) { return(BoundingBox.Intersects(col.BoundingBox)); } PotionGameObject potion = col as PotionGameObject; if (potion != null) { return(BoundingBox.Intersects(col.BoundingBox)); } } return(false); }