//public void OnCollisionWithPotion(HealthPotionGameObject potion) //{ // CollideWithPotion?.Invoke(this, potion, new CollisionEventArgs(Position)); //} public void OnCollisionWithEnemy(EnemyGameObject enemy) { if (canAttack) { CollideWithEnemy?.Invoke(this, enemy, new CollisionEventArgs(Position)); } }
/// <summary> /// Response to enemy dying event. Random chance that the enemy drops a potion at their position /// </summary> /// <param name="position"></param> public void SpawnPotion(object sender, EventArgs e) { EnemyGameObject enemy = sender as EnemyGameObject; if (enemy != null && !enemy.droppedPotion) { int random = Utilities.Rand(); PotionGameObject potion; if (random % 2 == 0) { potion = new HealthPotion(enemy.Position); } else { potion = new StrengthPotion(enemy.Position); } potion.LoadContent(Resources); potions.Add(potion); entities.Add(potion); GameInfo.Instance.HealthPotionInfoArray.Add(new HealthPotionInfo(enemy.Position)); InitialiseCollidableObjects(); enemy.droppedPotion = true; } }
public override void OnCollision(Collidable col) { EnemyGameObject enemy = col as EnemyGameObject; if (enemy != null && enemy == target) { isCloseEnoughToAttack = true; return; } HealthPotion hPotion = col as HealthPotion; if (hPotion != null && retrieveItem) { hPotion.flagForRemoval = true; HealPlayer(50); retrieveItem = false; return; } StrengthPotion sPotion = col as StrengthPotion; if (sPotion != null && retrieveItem) { sPotion.flagForRemoval = true; EmboldenPlayer(2); retrieveItem = false; return; } }
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)); } }
//TODO: wire this up //private void HealPlayerTest(object sender, EventArgs e) //{ // player.HealPlayer(50); //} //private void CollideWithPotionTest(object sender, object passedInPotion, CollisionEventArgs e) //{ // HealthPotionGameObject potion = passedInPotion as HealthPotionGameObject; // if (potion != null) // potion.OnHealPlayer(); //} private void CollideWithEnemyTest(object sender, object passedInEnemy, CollisionEventArgs e) { EnemyGameObject enemy = passedInEnemy as EnemyGameObject; if (enemy != null) { player.OnCollisionWithEnemy(enemy); } }
public void Damage(object sender, object other, CollisionEventArgs e)//(object receiver, int amount) { EnemyGameObject enemy = other as EnemyGameObject; if (enemy != null) { enemy.Health -= attackPower; } }
public override void Exit(object owner) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy != null) { enemy.Speed = EnemyGameObject.ChaseSpeed; } }
public override void Update(GameTime gameTime) { this.gameTime = gameTime; isDying = (health <= 0); //if there is a selected target, make sure the target is alive before attacking. if (target != null) { targetPosition = target.Position; //if the target is an enemy and is no longer alive, set it to null, switch off canAttack, and set velocity to 0 to stop moving. if (target != null) { EnemyGameObject enemy = target as EnemyGameObject; if (enemy != null) { if (!enemy.IsAlive) { canAttack = false; target = null; Velocity = Vector2.Zero; } } } } if (!isDying) { if (state == PlayerState.Attack) { sprite.PlayAnimation(attackAnimation); } else if (state == PlayerState.Walk || state == PlayerState.Chase) { sprite.PlayAnimation(walkAnimation); } if (Vector2.Distance(lastMouseLocation, Position) < stoppingDistance) { velocity = Vector2.Zero; } else { Position += Velocity; } BoundingBox = BoundingRectangle; } else { sprite.PlayAnimation(death); } fsm.Update(gameTime); }
public override void Exit(object owner) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy != null) { enemy.Speed = 0.0f; currentTime = 0.0; } }
public override void Enter(object owner) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy != null) { enemy.state = EnemyGameObject.EnemyState.Chase; enemy.Speed = EnemyGameObject.ChaseSpeed; } }
public override void Enter(object owner) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy != null) { enemy.state = EnemyGameObject.EnemyState.Attack; enemy.Speed = 0.0f; currentTime = 0.0; } }
public override void Execute(object owner, GameTime gameTime) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy == null) { return; } enemy.MoveToward(enemy.Target, gameTime); }
public override void Enter(object owner) { //Define enemy and behaviour initialisation EnemyGameObject enemy = owner as EnemyGameObject; if (enemy != null) { enemy.state = EnemyGameObject.EnemyState.Idle; enemy.Speed = EnemyGameObject.WanderSpeed; } currentTime = 0.0; }
public override void Execute(object owner, GameTime gameTime) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy == null) { return; } enemy.Die(); enemy.Speed = 0.0f; }
public void Attack() { //Check if the target is an enemy, and then attack EnemyGameObject enemy = target as EnemyGameObject; if (enemy != null) { sprite.PlayAnimation(attackAnimation); float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 directionToChase = enemy.Position - Position; directionToChase.Normalize(); Velocity = directionToChase * speed / 4 * elapsedTime; OnDamageEnemy(enemy); } }
public override void Execute(object owner, GameTime gameTime) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy == null) { return; } if (currentTime >= directionChangeTime) { currentTime = 0.0f; enemy.SetRandomDirection(); } else { currentTime += gameTime.ElapsedGameTime.TotalSeconds; } }
public override void Execute(object owner, GameTime gameTime) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy == null) { return; } if (enemy.Target != null) { if (enemy.PlayerSeen) { Vector2 newDirection = enemy.Position - enemy.Target.Position; newDirection.Normalize(); enemy.Direction = newDirection; enemy.Velocity = enemy.Direction * enemy.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } } }
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); }
public override void OnCollision(Collidable col) { EnemyGameObject enemy = col as EnemyGameObject; if (enemy != null && isAlive) { Point enemyCentre = enemy.BoundingBox.Center; Point centre = BoundingBox.Center; Vector2 enemyCentreVector = new Vector2(enemyCentre.X, enemyCentre.Y); Vector2 centreVector = new Vector2(centre.X, centre.Y); Vector2 collisionNormal = Vector2.Normalize(enemyCentreVector - centreVector); float distance = Vector2.Distance(enemyCentreVector, centreVector); float penetrationDepth = ((enemy.BoundingBox.Width / 2 + BoundingBox.Width / 2) - distance) * 0.08f; Position += (-collisionNormal * penetrationDepth); } }
public override void Execute(object owner, GameTime gameTime) { EnemyGameObject enemy = owner as EnemyGameObject; if (enemy == null) { return; } if (currentTime >= attackCooldownTime) { enemy.Speed = 0.0f; enemy.Attack(); currentTime = 0.0f; } else { enemy.Speed = 0.0f; currentTime += gameTime.ElapsedGameTime.TotalSeconds; } }
public override void Exit(object owner) { EnemyGameObject enemy = owner as EnemyGameObject; }
public void OnDamageEnemy(EnemyGameObject enemy) { DamageEnemy?.Invoke(this, enemy, new CollisionEventArgs(Position)); }