Ejemplo n.º 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            NativeQueue <ProjectileQueueData> queueData = new NativeQueue <ProjectileQueueData>(Allocator.TempJob);

            // set weapon states
            JobHandle processWeaponJob = new ProcessWeaponState()
            {
                inputs      = InputQuery.ToComponentDataArray <InputState>(Allocator.TempJob),
                inputsOwner = InputQuery.ToComponentDataArray <OwnerID>(Allocator.TempJob)
            }.Schedule(this, inputDeps);

            // create projectile data for weapons
            JobHandle shootJob = new ShootWeaponJob()
            {
                queueData = queueData.AsParallelWriter()
            }.Schedule(this, processWeaponJob);

            shootJob.Complete();

            // Spawn all of projectiles from the weapons
            for (int i = 0; i < queueData.Count; i++)
            {
                ProjectileQueueData data = queueData.Dequeue();

                ProjectileFactory.CreateProjectiles(WeaponParameters.Instance.GetWeaponDataByID(data.WeaponID).projectileId, data.SpawnPos, data.SpawnRot, data.Owner);
            }

            queueData.Dispose();

            return(shootJob);
        }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        timeTillNextSpawn -= Time.deltaTime;

        if (timeTillNextSpawn < 0)
        {
            timeTillNextSpawn = timeBetweenSpawns;

            ProjectileFactory.CreateProjectiles(ProjectileID, transform.position, transform.rotation, 0);
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (!_gameRunning)
        {
            return;
        }

        _direction = (_player.Position - Position).normalized;

        this.transform.up   = _direction;
        _rigidBody.velocity = _direction * _movementSpeed;

        if (!_hasFired)
        {
            ProjectileFactory.CreateProjectiles(this);

            _hasFired = true;
            Invoke("OnReloadingOver", _firingSpeed);
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (!_gameRunning)
        {
            return;
        }

        Vector2 playerDirection = _player.Position - Position;

        _direction = playerDirection.normalized;

        Vector2 randomDirection = new Vector2(UnityEngine.Random.value, UnityEngine.Random.value);

        Vector2 velocity;

        if (playerDirection.magnitude > _projectileRange)
        {
            velocity = _direction * _movementSpeed;
        }
        else if (playerDirection.magnitude < _hoverRange)
        {
            velocity = -_direction * _movementSpeed;
        }
        else
        {
            velocity = randomDirection * _movementSpeed;
        }

        this.transform.up   = _direction;
        _rigidBody.velocity = velocity;

        if (!_hasFired)
        {
            ProjectileFactory.CreateProjectiles(this);

            _hasFired = true;
            Invoke("OnReloadingOver", _firingSpeed);
        }
    }
Ejemplo n.º 5
0
        protected override void OnUpdate()
        {
            Entities.WithAll <EquippedTag>().ForEach((Entity entity, ref Weapon weapon, ref BurstFire burst, ref WeaponState state, ref ShootFrom shootFrom, ref OwnerID owner) =>
            {
                // if we are TRYING to and CAN burst
                if (state.IsShooting && burst.Value < 0)
                {
                    ProjectileFactory.CreateProjectiles(Parameters.GetWeaponDataByID(weapon.ID).projectileId, shootFrom.Position, shootFrom.Rotation, owner.Value);

                    // Restart timer and increase our burst count
                    burst.Value  = burst.ResetValue;
                    burst.Count += 1;

                    // If we are done bursting now, stop bursting
                    if (burst.Count >= burst.MaxCount)
                    {
                        state.IsShooting = false;
                    }

                    // TODO: Setup actioning on it
                }
            });
        }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (_isAlive && _gameRunning)
        {
            //=============================================
            // Movement

            Vector2 newMovementDirection = Vector2.zero;

            if (Input.GetKey(KeyCode.Z))
            {
                newMovementDirection.y = 1;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                newMovementDirection.y = -1;
            }
            else if (Input.GetKey(KeyCode.Q))
            {
                newMovementDirection.x = -1;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                newMovementDirection.x = 1;
            }

            if (newMovementDirection.magnitude > 0)
            {
                _movementDirection = newMovementDirection;

                _rigidBody.velocity = newMovementDirection * MovementSpeed;
                _legsAnimator.SetBool("Walking", true);
            }
            else
            {
                _rigidBody.velocity = Vector2.zero;

                _legsAnimator.SetBool("Walking", false);
            }

            //===========================================
            // Firing

            if (!_hasFired)
            {
                Vector2 newFiringDirection = Vector2.zero;

                if (Input.GetKey(KeyCode.UpArrow))
                {
                    newFiringDirection.y = 1;
                }
                else if (Input.GetKey(KeyCode.DownArrow))
                {
                    newFiringDirection.y = -1;
                }
                else if (Input.GetKey(KeyCode.LeftArrow))
                {
                    newFiringDirection.x = -1;
                }
                else if (Input.GetKey(KeyCode.RightArrow))
                {
                    newFiringDirection.x = 1;
                }

                if (newFiringDirection.magnitude > 0)
                {
                    FiringDirection = newFiringDirection;

                    ProjectileFactory.CreateProjectiles(this);
                    _headAnimator.SetTrigger("FireTrigger");


                    _hasFired = true;
                    Invoke("OnReloadingOver", 1 / FiringSpeed);
                }
            }
        }
    }