Example #1
0
        public override void Update(float delta)
        {
            if (_isCreating)
            {
                _lastCreatingTime += delta;
                if (_lastCreatingTime >= _cooldown)
                {
                    _isCreating = false;
                }
                return;
            }
            var position  = new Vector3(GameObject.Position.X, GameObject.Position.Y - 0.27f, GameObject.Position.Z);
            var direction = _target.Position - position;

            direction.Normalize();
            Game3DObject copyBullet = _bullet.GetCopy();

            copyBullet.MoveTo(position);
            //copyBullet.MoveTo(GameObject.Position);
            if ((GameObject.Position - _target.Position).Length() <= 1.5f)
            {
                copyBullet.AddScript(new BulletScript(direction));
                GameObject.Scene.AddGameObject(copyBullet);
                OnEggShoot?.Invoke();
            }


            _lastCreatingTime = 0;
            _isCreating       = true;
        }
        public override void Update(float delta)
        {
            if (_isReloading)
            {
                _reloadingTime += delta;
                if (_reloadingTime >= _cooldown)
                {
                    _isReloading = false;
                }
                return;
            }
            if (_inputController.MouseUpdate && _inputController.MouseButtons[0])
            {
                Vector3 rotation = GameObject.Rotation;
                rotation.Y = GameObject.Children[1].Rotation.Y;
                Matrix       rotationMatrix = Matrix.RotationYawPitchRoll(rotation.Z, rotation.Y, rotation.X);
                Vector3      direction      = (Vector3)Vector3.Transform(Vector3.UnitZ, rotationMatrix);
                Game3DObject bullet         = _bulletPrototype.GetCopy();
                bullet.MoveTo(GameObject.Position + direction);
                bullet.AddScript(new BulletScript(direction, 1, 1));
                GameObject.Scene.AddGameObject(bullet);
                OnCakeShoot?.Invoke();

                _reloadingTime = 0;
                _isReloading   = true;
            }
        }