Exemplo n.º 1
0
        public override void Update(GameTime time)
        {
            if (gameEventSystem == null)
            {
                gameEventSystem = GameEventSystem.GetFromServices(Services);
                gameEventSystem.RegisterListener(new TestJumpListener());
            }

            foreach (var kvp in ComponentDatas)
            {
                var movementComponent = kvp.Key;
                var data = kvp.Value;

                if (movementComponent.MoveDirection.HasValue)
                {
                    Move(movementComponent, data, movementComponent.MoveDirection.Value);
                    movementComponent.MoveDirection = null;
                }
                if (data.Character.IsGrounded)
                {
                    data.ModelEntityTransform.Entity.BroadcastEvent <IAnimationEvents>().SetGrounded(true);
                }
                if (movementComponent.ShouldJump)
                {
                    Jump(movementComponent, data);
                    movementComponent.ShouldJump = false;
                }
            }
        }
        public override void Update(GameTime time)
        {
            if (gameEventSystem == null)
            {
                gameEventSystem = GameEventSystem.GetFromServices(Services);
            }

            foreach (var kvp in ComponentDatas)
            {
                var punchComponent = kvp.Key;
                var data           = kvp.Value;

                if (punchComponent.ShouldPunch)
                {
                    // animate punch
                    punchComponent.Entity.BroadcastEvent <IAnimationEvents>().Punch();
                    data.WaitTime = TimeSpan.FromSeconds(0.2);
                }

                if (data.WaitTime.HasValue)
                {
                    if (data.WaitTime.Value > new TimeSpan())
                    {
                        data.WaitTime -= time.Elapsed;
                    }
                    else
                    {
                        gameEventSystem.Log(new PunchEvent(punchComponent.Entity));
                        foreach (var collision in punchComponent.InteractionSource.Collisions)
                        {
                            var otherEntity = collision.ColliderA.Entity.Get <CharacterInteractionSource>() != null
                                ? collision.ColliderB.Entity
                                : collision.ColliderA.Entity;
                            if (otherEntity.Name == "PlayerCharacter")
                            {
                                otherEntity.BroadcastEvent <IDamageEvents>().DealDamage(1);
                            }
                        }
                        data.WaitTime = null;
                    }
                }

                // reset state
                punchComponent.ShouldPunch = false;
            }
        }
        public override void Update(GameTime time)
        {
            if (gameEventSystem == null)
            {
                gameEventSystem = GameEventSystem.GetFromServices(Services);
                gameEventSystem.RegisterListener(new CharacterHealthListener());
            }

            foreach (var kvp in ComponentDatas)
            {
                var stats = kvp.Key;

                var oldHealth = stats.Health;
                var newHealth = MathUtil.Clamp(oldHealth - stats.DamageDealt + stats.AmountHealed, 0, stats.MaxHealth);

                if (oldHealth != newHealth)
                {
                    stats.Health = newHealth;
                    gameEventSystem.Log(new HealthChangeEvent(stats.Entity, oldHealth, newHealth));
                }

                ResetStatsDiff(stats);
            }
        }
 protected override void OnSystemAdd()
 {
     gameEventSystem = GameEventSystem.GetFromServices(Services);
     scriptSystem    = Services.GetService <ScriptSystem>();
 }