Ejemplo n.º 1
0
 /// <summary>
 /// Resets the DSP.
 /// </summary>
 private void Reset()
 {
     outputData.Clear();
     outputData.Enqueue(0xAA);
     this.state = BlasterState.WaitingForCommand;
     this.blockTransferSizeSet = false;
     this.dsp.Reset();
 }
Ejemplo n.º 2
0
    public override void ReleaseTrigger(Player player)
    {
        bulletTracer.enabled = false;
        state = BlasterState.Ready;
        fireSound.Stop();
        MuzzleFlashLight.gameObject.SetActive(false);

        //disable particles
        AllowHitEffect(false);
        var meff = MuzzleEffect.emission;

        meff.enabled = false;
    }
Ejemplo n.º 3
0
    public void LaunchBullet(int direction)
    {
        if (direction == 1)
        {
            spriteAnimator.Sprite.scale = Vector3.one;
        }
        else
        {
            spriteAnimator.Sprite.scale = new Vector3(-1, 1, 1);
        }

        this.direction = direction;

        blasterState = BlasterState.Launched;
    }
    // Update is called once per frame
    void Update()
    {
        if (enemyController.freezeEnemy)
        {
            // add anything here to happen while frozen i.e. time compensations
            return;
        }

        // get player object - used for distance check
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        // blaster has only two states - closed and open
        // while closed he's invincible and when open vulnerable
        // and fires four bullets at different vectors
        switch (blasterState)
        {
        case BlasterState.Closed:
            animator.Play("Blaster_Closed");
            // check distance to player
            if (player != null && !doAttack)
            {
                float distance = Vector2.Distance(transform.position, player.transform.position);
                if (distance <= playerRange)
                {
                    doAttack    = true;
                    closedTimer = closedDelay;
                }
            }
            // within distance and can attack
            if (doAttack)
            {
                // delay before opening to attack
                closedTimer -= Time.deltaTime;
                if (closedTimer <= 0)
                {
                    // switch to open state
                    // NOTE: animation has events that shoot the bullets and goes back to closed state
                    blasterState = BlasterState.Open;
                }
            }
            break;

        case BlasterState.Open:
            // firing of the bullets is performed via animation events calling ShootBullet()
            animator.Play("Blaster_Open");
            break;
        }
    }
Ejemplo n.º 5
0
        private void HandleIdle()
        {
            var observations = _entity.observations;

            observations.Sort(new GameObjectDistanceSortComparer(this.transform.position));

            var count = observations.Count;

            for (int i = 0; i < count; i++)
            {
                var obs = observations[i];

                var nest = obs.GetComponent <NestStructure>();
                if (nest != null)
                {
                    if (_entity.IsAllied(nest))
                    {
                        // try to avoid attacking own nest
                        continue;
                    }

                    _attackTarget = nest;
                    _currentState = BlasterState.Exploding;
                    return;
                }

                var otherUnit = obs.GetComponent <UnitBase>();
                if (otherUnit != null)
                {
                    if (_entity.IsAllied(otherUnit))
                    {
                        // try to avoid attacking allied units
                        continue;
                    }

                    _attackTarget = otherUnit;
                    _currentState = BlasterState.Exploding;
                    return;
                }
            }

            // nothing interesting in memory, do some random wandering
            if (!_entity.isMoving)
            {
                _entity.RandomWander();
            }
        }
Ejemplo n.º 6
0
        void IOutputPort.WriteByte(int port, byte value)
        {
            switch (port)
            {
            case Ports.DspReset:
                // Expect a 1, then 0 written to reset the DSP.
                if (value == 1)
                {
                    this.state = BlasterState.ResetRequest;
                }
                else if (value == 0 && this.state == BlasterState.ResetRequest)
                {
                    this.state = BlasterState.Resetting;
                    Reset();
                }
                break;

            case Ports.DspWrite:
                if (this.state == BlasterState.WaitingForCommand)
                {
                    this.currentCommand = value;
                    this.state          = BlasterState.ReadingCommand;
                    this.commandData.Clear();
                    commandLengths.TryGetValue(value, out this.commandDataLength);
                    if (this.commandDataLength == 0)
                    {
                        ProcessCommand();
                    }
                }
                else if (this.state == BlasterState.ReadingCommand)
                {
                    this.commandData.Add(value);
                    if (this.commandData.Count >= this.commandDataLength)
                    {
                        ProcessCommand();
                    }
                }
                break;

            case Ports.MixerAddress:
                this.mixer.CurrentAddress = value;
                break;
            }
        }
Ejemplo n.º 7
0
    public void CheckValidTarget()
    {
        if (!rayHit.collider)
        {
            return;
        }

        var isPlayer = rayHit.collider.CompareTag("PlayerHitbox");
        var isNPC    = rayHit.collider.CompareTag("NPCHitbox");

        if (isPlayer || isNPC)
        {
            AbstractCharacter target;

            if (isNPC)
            {
                target = rayHit.collider.GetComponent <BossMonster>();
                HitPlayerEffect.transform.position = rayHit.point;
            }
            else
            {
                target = rayHit.collider.GetComponentInParent <PlayerHitbox>().player;
                HitPlayerEffect.transform.position = target.transform.position;
            }
            if (!target.IsAlive())
            {
                return;
            }

            targetBeingDamaged = target;
            HitPlayerEffect.transform.rotation = transform.rotation;
            AllowHitEffect(true);
            state = BlasterState.HittingValidTarget;
        }
        else
        {
            // if not player or npc then it hit terrain
            state = BlasterState.Firing;
            AllowHitEffect(false);
        }
    }
Ejemplo n.º 8
0
    public override void PullTrigger(Player player)
    {
        if (timeTillNextShot > 0)
        {
            return;
        }

        if (!fireSound.isPlaying)
        {
            fireSound.Play();
        }

        timeTillNextShot     = fireRate;
        bulletTracer.enabled = true;
        state = BlasterState.Firing;
        DrawLine();
        MuzzleFlashLight.gameObject.SetActive(true);
        var meff = MuzzleEffect.emission;

        meff.enabled = true;
    }
Ejemplo n.º 9
0
        private void HandleExploding()
        {
            if (_attackTarget == null || _attackTarget.isDead)
            {
                _attackTarget = null;
                _currentState = BlasterState.Idle;
                return;
            }

            if ((_attackTarget.transform.position - _entity.transform.position).sqrMagnitude > (_entity.explodeRadius * _entity.explodeRadius))
            {
                // attack target outside of range
                if (!_entity.isMoving)
                {
                    _entity.MoveTo(_attackTarget.transform.position);
                }

                return;
            }

            // attack target within range
            _entity.Attack();
        }
 // called from the last animation event in the Blaster_Open animation
 private void OpenAnimationStop()
 {
     doAttack     = false;
     blasterState = BlasterState.Closed;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Performs the action associated with the current DSP command.
        /// </summary>
        private void ProcessCommand()
        {
            outputData.Clear();
            switch (currentCommand)
            {
            case Commands.GetVersionNumber:
                outputData.Enqueue(4);
                outputData.Enqueue(5);
                break;

            case Commands.DspIdentification:
                outputData.Enqueue((byte)~commandData[0]);
                break;

            case Commands.SetTimeConstant:
                dsp.SampleRate = 256000000 / (65536 - (commandData[0] << 8));
                break;

            case Commands.SetSampleRate:
                dsp.SampleRate = (commandData[0] << 8) | commandData[1];
                break;

            case Commands.SetBlockTransferSize:
                dsp.BlockTransferSize     = (commandData[0] | (commandData[1] << 8)) + 1;
                this.blockTransferSizeSet = true;
                break;

            case Commands.SingleCycleDmaOutput8:
            case Commands.HighSpeedSingleCycleDmaOutput8:
            case Commands.SingleCycleDmaOutput8_Alt:
            case Commands.SingleCycleDmaOutput8Fifo_Alt:
                //if(commandData.Count >= 2 && (commandData[0] | (commandData[1] << 8)) >= 2048)
                dsp.Begin(false, false, false);
                //else
                //    this.vm.InterruptController.RaiseHardwareInterrupt(this.irq);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM4Ref:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM4, true);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM4 with reference byte");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM4:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM4, false);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM4");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM2Ref:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM2, true);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM2 with reference byte");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM2:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM2, false);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM2");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM3Ref:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM3, true);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM3 with reference byte");
                vm.PerformDmaTransfers();
                break;

            case Commands.SingleCycleDmaOutputADPCM3:
                dsp.Begin(false, false, false, CompressionLevel.ADPCM3, false);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA ADPCM3");
                vm.PerformDmaTransfers();
                break;

            case Commands.AutoInitDmaOutput8:
            case Commands.HighSpeedAutoInitDmaOutput8:
                if (!this.blockTransferSizeSet)
                {
                    dsp.BlockTransferSize = ((commandData[1] | (commandData[2] << 8)) + 1);
                }
                this.dsp.Begin(false, false, true);
                System.Diagnostics.Debug.WriteLine("Auto-init DMA");
                break;

            case Commands.AutoInitDmaOutput8_Alt:
            case Commands.AutoInitDmaOutput8Fifo_Alt:
                if (!this.blockTransferSizeSet)
                {
                    dsp.BlockTransferSize = ((commandData[1] | (commandData[2] << 8)) + 1);
                }
                this.dsp.Begin(false, (commandData[0] & (1 << 5)) != 0, true);
                System.Diagnostics.Debug.WriteLine("Auto-init DMA");
                break;

            case Commands.ExitAutoInit8:
                this.dsp.ExitAutoInit();
                break;

            case Commands.SingleCycleDmaOutput16:
            case Commands.SingleCycleDmaOutput16Fifo:
                this.dsp.Begin(true, (commandData[0] & (1 << 5)) != 0, false);
                System.Diagnostics.Debug.WriteLine("Single-cycle DMA");
                break;

            case Commands.AutoInitDmaOutput16:
            case Commands.AutoInitDmaOutput16Fifo:
                System.Diagnostics.Debug.WriteLine("Auto-init DMA");
                this.dsp.Begin(true, (commandData[0] & (1 << 5)) != 0, true);
                break;

            case Commands.TurnOnSpeaker:
                break;

            case Commands.TurnOffSpeaker:
                break;

            case Commands.PauseDmaMode:
            case Commands.PauseDmaMode16:
            case Commands.ExitDmaMode16:
                this.dmaChannel.IsActive = false;
                this.dsp.IsEnabled       = false;
                System.Diagnostics.Debug.WriteLine("Pause Sound Blaster DMA");
                break;

            case Commands.ContinueDmaMode:
            case Commands.ContinueDmaMode16:
                this.dmaChannel.IsActive = true;
                this.dsp.IsEnabled       = true;
                System.Diagnostics.Debug.WriteLine("Continue Sound Blaster DMA");
                break;

            case Commands.RaiseIrq8:
                RaiseInterrupt();
                break;

            case Commands.SetInputSampleRate:
                // Ignore for now.
                break;

            case Commands.PauseForDuration:
                this.pauseDuration = commandData[0] | (commandData[1] << 8);
                break;

            default:
                throw new NotImplementedException($"Sound Blaster command {currentCommand:X2}h not implemented.");
            }

            this.state = BlasterState.WaitingForCommand;
        }