Ejemplo n.º 1
0
        protected override void Execute(List <InputEntity> entities)
        {
            bool isFiring = false;

            foreach (InputEntity e in entities)
            {
                switch (e.input.type)
                {
                case InputType.Fire: isFiring = true; break;
                }
            }

            var playerEntities = players.GetEntities();

            foreach (var player in playerEntities)
            {
                var lastShotTime    = player.weapon.lastShotTime;
                var cooldownSeconds = Config.instance.weaponCooldownSeconds;

                if (isFiring && lastShotTime + cooldownSeconds < Time.time)
                {
                    player.ReplaceWeapon(Time.time);
                    context.CreateBullet(player.position.x, player.position.y, player.direction.value);
                }
            }
        }
    void ShootBulletFrom(GameEntity weapon)
    {
        var transformState = weapon.transform.state;
        var forward        = new Vector3D(transformState.rotation * Vector3.forward);

        transformState.position += forward;

        var velocity       = forward * weapon.projectileSpeed.value;
        var rigidbodyState = new RigidbodyState(velocity);

        var bulletDamage = weapon.damage.value;

        game.CreateBullet(transformState, rigidbodyState, bulletDamage);
    }