public override void HandleMessage(Message message) { base.HandleMessage(message); if (message is DamageMessage) { DamageMessage damageMessage = message as DamageMessage; if (CurrentShield > 0) { if (damageMessage.Damage > CurrentShield) { float healthDamage = damageMessage.Damage - CurrentShield; CurrentShield = 0; CurrentHealth -= healthDamage; } else { CurrentShield -= damageMessage.Damage; } GameObjectFactory.CreateShieldDamageEffect(Parent.Position); } else { CurrentHealth -= damageMessage.Damage; } } }
public override void HandleMessage(Message message) { base.HandleMessage(message); if(message is AnimationFinishedMessage) { Parent.HandleMessage(new InvalidateMessage(this)); } }
public override void HandleMessage(Message message) { if (message is CollisionMessage) { CollisionMessage collisionMsg = message as CollisionMessage; collisionMsg.GameObject.HandleMessage(new DamageMessage(this, Damage)); } }
/// <summary> /// Call this to send the component a message, or override it to handle a message. /// </summary> /// <param name="message">The message</param> public void HandleMessage(Message message) { if (message is InvalidateMessage) Valid = false; foreach(Component comp in Components) { if (comp != message.Sender) comp.HandleMessage(message); } }
public override void HandleMessage(Message message) { base.HandleMessage(message); if(message is CollisionMessage) { CollisionMessage collisionMessage = message as CollisionMessage; GameObjectFactory.CreateExplosion(Parent.Position); // suicide Parent.HandleMessage(new InvalidateMessage(this)); } }
public override void HandleMessage(Message message) { //TODO: get magic numbers out of here. if(message is FlyMessage) { FlyMessage flyMessage = message as FlyMessage; PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(flyMessage.Direction.X, flyMessage.Direction.Y) * MovementImpulse); } if(message is InvalidateMessage) { GameObjectFactory.CreateDeadFlyingBug(Parent.Position); } }
public override void HandleMessage(Message message) { if (message is WalkLeftMessage) { if (!InAir) PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(-WalkImpulse, 0)); else PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(-InAirMovementImpulse, 0)); AnimationSetRenderComponent.FlipX = true; if (AnimationSetRenderComponent.CurrentKey != "Jumping" && AnimationSetRenderComponent.CurrentKey != "Falling" && AnimationSetRenderComponent.CurrentKey != "Attacking") { IsWalking = true; AnimationSetRenderComponent.SetAnimation("Walking"); } } else if (message is WalkRightMessage) { if (!InAir) PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(WalkImpulse, 0)); else PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(InAirMovementImpulse, 0)); AnimationSetRenderComponent.FlipX = false; if (AnimationSetRenderComponent.CurrentKey != "Jumping" && AnimationSetRenderComponent.CurrentKey != "Falling" && AnimationSetRenderComponent.CurrentKey != "Attacking") { IsWalking = true; AnimationSetRenderComponent.SetAnimation("Walking"); } } else if (message is JumpMessage) { if (FeetColliders.Count > 0) { //FeetColliders.Clear(); PhysicsComponent.Body.ApplyLinearImpulse(new Vector2(0.0f, -JumpImpulse)); AnimationSetRenderComponent.SetAnimation("Jumping"); } } if (message is DamageMessage) { Camera.Shake(); } if (message is AttackMessage) { //TODO: this is ugly. foreach (Component comp in Parent.Components) { if (comp is WeaponHoldingComponent) { WeaponHoldingComponent weaponHoldingComp = comp as WeaponHoldingComponent; AttackMessage attackMessage = message as AttackMessage; { if (attackMessage.Melee) { if (weaponHoldingComp.MeleeWeaponComponent.TryAttack()) { AnimationSetRenderComponent.SetAnimation("Attacking"); } } else { if (weaponHoldingComp.GunWeaponComponent.TryAttack()) { // do nothing for gun attack. //AnimationSetRenderComponent.SetAnimation("Attacking"); } } } } } } if(message is InvalidateMessage) { GameObjectFactory.CreateDeadPlayer(Parent.Position); } if(message is CollisionMessage) { CollisionMessage collisionMsg = message as CollisionMessage; if(collisionMsg.Contact.Manifold.LocalNormal.Y > 0) // only friction the floor { FeetColliders.Add(collisionMsg.GameObject); if (AnimationSetRenderComponent.CurrentKey == "Jumping" || AnimationSetRenderComponent.CurrentKey == "Falling" && AnimationSetRenderComponent.CurrentKey != "Attacking") { AnimationSetRenderComponent.SetAnimation("Idle"); } } else // don't friction walls or ceilings { collisionMsg.Contact.Friction = 0.0f; } } if (message is SeperationMessage) { SeperationMessage seperationMsg = message as SeperationMessage; if (FeetColliders.Contains(seperationMsg.GameObject)) { FeetColliders.Remove(seperationMsg.GameObject); } } InAir = FeetColliders.Count == 0; if (InAir) PhysicsComponent.Body.LinearDamping = InAirLinearDamping; else PhysicsComponent.Body.LinearDamping = WalkingLinearDamping; }
public override void HandleMessage(Message message) { base.HandleMessage(message); if (message is AttackMessage) { AttackMessage attackMsg = message as AttackMessage; TryAttack(); } if(message is WalkLeftMessage) { AttackDirection = -1; } if(message is WalkRightMessage) { AttackDirection = 1; } }
public virtual void HandleMessage(Message message) { }