示例#1
0
    private IEnumerator chargeEnergyball()
    {
        canMove = false;
        float   tempx = transform.position.x + anim.GetFloat("x") * 0.25f;
        float   tempy = transform.position.y + anim.GetFloat("y") * 0.25f;
        Vector3 temp  = new Vector3(tempx, tempy, transform.position.z);

        ball = Instantiate(energyBall, temp, Quaternion.identity).GetComponent <EnergyBall>();
        if (ball != null && Input.GetKey(KeyCode.RightShift) == false)
        {
            GameObject obj1 = GameObject.FindGameObjectWithTag("energyball");
            Destroy(obj1);
            isCharge = false;
        }
        yield return(new WaitForSeconds(0.32f));

        if (ball != null && Input.GetKey(KeyCode.RightShift) == false)
        {
            GameObject obj1 = GameObject.FindGameObjectWithTag("energyball");
            Destroy(obj1);
            isCharge = false;
        }
        if (ball != null && Input.GetKey(KeyCode.RightShift))
        {
            energyBallAnimator = ball.GetComponent <Animator>();
            energyBallAnimator.SetBool("grow", false);
            chargeReady = true;
        }
    }
示例#2
0
    void OnTriggerStay(Collider other)
    {
        if (Player.lightOn)
        {
            EnergyBall energyBall = other.GetComponent <EnergyBall>();
            if (Input.GetAxis("Suck") > 0)
            {
                if (!this.Sucking)
                {
                    this.SuckStrength = 1.1f; this.Sucking = true;
                }

                this.SuckStrength = Mathf.Clamp(this.SuckStrength * 1.1f, 1, 50);
                Vector3 towardsPlayer = (transform.parent.position - other.transform.position).normalized;
                energyBall.GetComponent <Rigidbody>().velocity = towardsPlayer * SuckStrength;
                energyBall.SetSucking(true);
            }

            else
            {
                this.Sucking       = false;
                this.SuckStrength *= 0.5f;
                energyBall.SetSucking(false);
            }
        }
    }
示例#3
0
    public void KillAgent()
    {
        GameConstants.Instance.PlayerObject.GetComponent <PlayerHandler>().IncreaseKilledSpaceShipsCount(1);

        int randomExplosion = Random.Range(0, 3);

        if (randomExplosion == 0)
        {
            AudioSystem.Instance.PlaySound("Explosion", 0.08f);
        }
        else if (randomExplosion == 1)
        {
            AudioSystem.Instance.PlaySound("Explosion01", 0.08f);
        }
        else
        {
            AudioSystem.Instance.PlaySound("Explosion02", 0.08f);
        }

        mBoidController.ResetBoid();
        mBoidController.RemoveBoidFromManager();

        for (int i = 0; i < 5; i++)
        {
            GameObject newEnergyBall    = PoolSystem.Instance.GetObjectFromPool(mEnergyBall, argShouldExpandPool: true, argShouldCreateNonExistingPool: true);
            EnergyBall energyBallScript = newEnergyBall.GetComponent <EnergyBall>();
            energyBallScript.SetupEnergyBall(Random.Range(3, 7), transform.position);
            energyBallScript.ActivateEnergyBall();
        }

        gameObject.SetActive(false);
    }
示例#4
0
    bool RangeAttack()
    {
        Collider2D[] colInfo = Physics2D.OverlapCircleAll(transform.position, rangedAttackRadius);

        for (int i = 0; i < colInfo.Length; ++i)
        {
            // One of the collided object is player
            if (colInfo[i].gameObject.CompareTag("Player"))
            {
                rangedAttackTimer = rangedAttackCooldown;

                GameObject  rangedAtk = Instantiate(rangedAttackObject, rangedAttackSpawnPos.position, Quaternion.identity);
                Rigidbody2D rbAtk     = rangedAtk.GetComponent <Rigidbody2D>();
                EnergyBall  ebAtk     = rangedAtk.GetComponent <EnergyBall>();

                Vector2 dir = playerGO.transform.position - rangedAtk.transform.position;
                rbAtk.AddForce(dir * rangedAttackForce, ForceMode2D.Impulse);
                ebAtk.targetGoal = playerGO.transform.position;
                ebAtk.damage     = rangedAttackDamage;
                //colInfo[i].gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
                //Debug.Log("Sandworm vel: " + GetComponent<Rigidbody2D>().velocity);
                //Debug.Log("Player vel: " + colInfo[i].gameObject.GetComponent<Rigidbody2D>().velocity);

                return(true);
            }
        }

        return(false);
    }
示例#5
0
    void DropEnergy()
    {
        GameObject energyBallObj = Instantiate(energyBallPrefab, transform.position, Quaternion.Euler(0, UnityEngine.Random.Range(0f, 360f), 0));
        EnergyBall energyBall    = energyBallObj.GetComponent <EnergyBall>();

        energyBall.forwardForce = UnityEngine.Random.Range(minForwardForce, maxForwardForce);
        energyBall.upForce      = UnityEngine.Random.Range(minUpForce, maxUpForce);
    }
示例#6
0
    public void UseSkill3()
    {
        playerShooter.gun.gunAudioPlayer.PlayOneShot(playerShooter.gun.shotClip);
        GameObject _ball       = Instantiate(energyBall, playerShooter.gun.muzzleFlash.transform.position + transform.forward * 2, Quaternion.identity);
        EnergyBall _energyBall = _ball.GetComponent <EnergyBall>();

        _energyBall.SetVelocity();
        _energyBall.SetRemoveTime(4);
        _energyBall.Set(skill3Damage, skill3Stuntime);
    }
示例#7
0
    void OnTriggerExit(Collider other)
    {
        this.Sucking = false;
        EnergyBall energyBall = other.GetComponent <EnergyBall>();

        if (energyBall)
        {
            energyBall.SetSucking(false);
        }
    }
示例#8
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "EnergyBall" && bs.ballUsed == false)
     {
         EnergyBall eb = other.GetComponent <EnergyBall>();
         eb.DestroyBall();
         bs.ballUsed = true;
         onBallReceived.Invoke();
         ballReceiveSound.Invoke();
     }
 }
示例#9
0
        private IEnumerable <Wait> RoutineHorn(Creature creature, Creature targetCreature)
        {
            var horn = SpriteLoader.Instance.AddSprite("content/death_golem_sickle");

            var cutter = new EnergyBall(creature.World, horn, null, creature.VisualTarget + new Vector2(0, -8), targetCreature.VisualTarget, 1.0f, MathHelper.Pi * 0.1f, 60, LerpHelper.Quadratic, 50);

            yield return(new WaitTime(50));

            var wait = creature.Attack(targetCreature, SkillUtil.SafeNormalize(targetCreature.VisualTarget - creature.VisualTarget), HornAttack);

            yield return(wait);
        }
示例#10
0
    private IEnumerator launchEnergyball()
    {
        canMove = true;
        Vector2 temp = new Vector2(anim.GetFloat("x"), anim.GetFloat("y"));

        ball.Setup(temp, ChooseProjDirection());
        ball = null;
        energyBallAnimator = null;
        chargeReady        = false;
        yield return(new WaitForSeconds(2f));

        isCharge = false;
    }
示例#11
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Ship"))
        {
            PlayerShip playerShip = other.GetComponent <PlayerShip>();
            Rigidbody  rb         = other.GetComponent <Rigidbody>();

            playerShip.GetHitByEmp(shutDownDuration);
        }
        else if (other.gameObject.CompareTag("EnergyBall"))
        {
            EnergyBall energyBall = other.GetComponent <EnergyBall>();
            energyBall.Die();
        }
    }
示例#12
0
    // Launch a charged energyball
    private IEnumerator launchEnergyball()
    {
        // Enable player movement
        canMove = true;
        // Set a vector based on the direction the player is facing
        Vector2 temp = new Vector2(anim.GetFloat("x"), anim.GetFloat("y"));

        // Setup the direction and velocity of the energyball
        ball.Setup(temp, ChooseProjDirection());
        // Reset the ball reference object and animator reference object
        ball = null;
        energyBallAnimator = null;
        // Set the charge ready state boolean to false for a 2 second cooldown
        chargeReady = false;
        yield return(new WaitForSeconds(2f));

        isCharge = false;
    }
示例#13
0
    // Begin charging an energyball
    private IEnumerator chargeEnergyball()
    {
        // Disable movement
        canMove = false;
        // Set coordinates to slightly infront of the player
        float   tempx = transform.position.x + anim.GetFloat("x") * 0.25f;
        float   tempy = transform.position.y + anim.GetFloat("y") * 0.25f;
        Vector3 temp  = new Vector3(tempx, tempy, transform.position.z);

        // Instantiate the energyball
        ball = Instantiate(energyBall, temp, Quaternion.identity).GetComponent <EnergyBall>();
        // Check if the player has released shift
        if (ball != null && Input.GetKey(KeyCode.RightShift) == false)
        {
            // Destroy the energyball if shift key is not being pressed
            GameObject obj1 = GameObject.FindGameObjectWithTag("energyball");
            Destroy(obj1);
            // Update the isCharge state boolean
            isCharge = false;
        }
        // Wait for the energyball to fully charge
        yield return(new WaitForSeconds(0.32f));

        // Check if the player has released shift
        if (ball != null && Input.GetKey(KeyCode.RightShift) == false)
        {
            // Destroy the energyball if shift key is not being pressed
            GameObject obj1 = GameObject.FindGameObjectWithTag("energyball");
            Destroy(obj1);
            // Update the isCharge state boolean
            isCharge = false;
        }
        // Check if the player has released shift
        if (ball != null && Input.GetKey(KeyCode.RightShift))
        {
            // Reset the animator grow boolean
            energyBallAnimator = ball.GetComponent <Animator>();
            energyBallAnimator.SetBool("grow", false);
            // Set the charge ready state boolean to true
            chargeReady = true;
        }
    }
示例#14
0
    protected void AnalyzePrey()
    {
        // when eating, dont try to hunt anyone
        if (this.State == STATE.EATING)
        {
            return;
        }

        if (size == SIZE.GOD)
        {
            // God fish has special logic, it will sense energies and chase them no matter how far away
            EnergyBall eBall = checkForEnergy();
            if (eBall)
            {
                this.PhysicalTarget = eBall;
                Hunt();
            }
            else
            {
                Idle();
            }

            return;
        }

        FishTarget orbTarget = this.PhysicalTarget as FishTarget;

        if (orbTarget)
        {
            // light orb presents, ignore all else
            return;
        }

        BoidsFish predatee = this.PhysicalTarget as BoidsFish;

        // if the target is out of sight, stop hunting
        if (predatee && !checkIfVisible(predatee))
        {
            predatee = null;
        }

        if (predatee != null)
        {
            foreach (BoidsFish potentialSwitch in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(potentialSwitch))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Don't switch if the predatee is A.U.L.I.V.
                    if (predatee == GameManager.Instance.Player)
                    {
                        break;
                    }

                    // Switch to A.U.L.I.V. if within prey
                    if (potentialSwitch == GameManager.Instance.Player)
                    {
                        predatee = potentialSwitch;
                        break;
                    }
                }

                // Skip if potential switch is smaller in size or the same fish as already being hunted
                if (potentialSwitch == predatee || potentialSwitch.Size < predatee.Size)
                {
                    continue;
                }

                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    // Skip small fish that aren't in a big enough flock
                    SmallBoidsFish potentialSmall = potentialSwitch as SmallBoidsFish;
                    SmallBoidsFish predateeSmall  = predatee as SmallBoidsFish;
                    if ((predateeSmall != null && potentialSmall != null) && (potentialSmall.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToCurrent   = (this.transform.position - predatee.transform.position).sqrMagnitude;
                float sqrDistToPotential = (this.transform.position - potentialSwitch.transform.position).sqrMagnitude;
                if (sqrDistToPotential < sqrDistToCurrent)
                {
                    predatee = potentialSwitch;
                }
            }

            this.PhysicalTarget = predatee;
        }
        else
        {
            float     closestSqrDist = float.PositiveInfinity;
            BoidsFish closestFish    = null;
            foreach (BoidsFish fish in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(fish))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Set A.U.L.I.V. as prey immediately if present
                    if (fish == GameManager.Instance.Player)
                    {
                        closestFish = fish;
                        break;
                    }
                }

                // Large fish skip small fish that aren't in a big enough flock
                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    SmallBoidsFish small = fish as SmallBoidsFish;
                    if (fish == GameManager.Instance.Player && (small != null) && (small.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToFish = (this.transform.position - fish.transform.position).sqrMagnitude;
                if (sqrDistToFish < closestSqrDist)
                {
                    closestSqrDist = sqrDistToFish;
                    closestFish    = fish;
                }
            }

            if (closestFish != null)
            {
                this.PhysicalTarget = predatee = closestFish;
                this.Hunt();
            }
            else
            {
                this.PhysicalTarget = null;
                this.Idle();
            }
        }

        // Only medium fish are scared of approaching flocks
        if (this.Size == SIZE.MEDIUM)
        {
            SmallBoidsFish smallPredatee = predatee as SmallBoidsFish;
            if (smallPredatee != null)
            {
                if (smallPredatee.FlockSize > BoidsSettings.Instance.MinFlockSizeToScareMediumFish)
                {
                    this.PhysicalTarget = predatee = null;
                    this.Idle();
                }
            }
        }

        // if (this.Size != SIZE.SMALL)
        // {
        //     if (predatee != null)
        //         this.Hunt ();
        //     else
        //     {
        //         this.Idle ();
        //     }
        // }
    }
示例#15
0
        public override void Update(float p_delta, Collider p_collider)
        {
            var __tmpPosition      = position + (_velocity * _targetDirectionVector * p_delta);
            var __reachedTargetPos = ReachedTargetPosition(__tmpPosition, _targetPosition);
            var __isColliding      = IsColliding(p_collider, __tmpPosition);

            if (__reachedTargetPos && _targetPosition != Vector2.Zero)
            {
                if (_weapons.Count == 0)
                {
                    var __middleBall = new EnergyBall(this, _player, new Vector2(16, 12.0f));

                    _weapons.Add(__middleBall);
                    _weapons.Add(new EnergyBall(this, _player, new Vector2(16, 12.0f), 10.0f * Main.s_scale));
                    _weapons.Add(new EnergyBall(this, _player, new Vector2(16, 12.0f), -10.0f * Main.s_scale));

                    AddWeaponsToManager.Invoke(_weapons);

                    _attacking = true;
                    _animationController.ChangeAnimation("Attack");

                    SoundManager.instance.Play(World.s_random.Next(2) == 1 ? SoundType.BOSS_SCREAM_1 : SoundType.BOSS_SCREAM_2);
                }
                else
                {
                    for (var __i = _weapons.Count - 1; __i >= 0; __i--)
                    {
                        var __w = _weapons[__i];

                        if (__w.state == State.DISABLED)
                        {
                            RemoveWeaponFromManagerByWeaponId.Invoke(__w.id);
                            _weapons.Remove(__w);
                        }
                    }

                    if (_weapons.Count == 0)
                    {
                        _attacking = false;
                    }
                }
            }

            if (!_attacking)
            {
                if (_animationController.Animation.name != "Idle")
                {
                    _animationController.ChangeAnimation("Idle");
                }

                if (__reachedTargetPos || __isColliding)
                {
                    SortNextMove();

                    direction = _targetDirection;
                }
                else
                {
                    position = __tmpPosition;
                }
            }

            base.Update(p_delta, p_collider);
        }
示例#16
0
 public void CopyFromOtherBall(EnergyBall other)
 {
     this.energyCrimsonfill.fillAmount = other.energyCrimsonfill.fillAmount;
 }
示例#17
0
 void CreateNewEnergyBall()
 {
     _currentBall = Instantiate(_energyBallPrefab, _firePoint.transform.position, transform.rotation, _firePoint.transform);
     _currentBall.transform.localScale = Vector3.zero;
 }
示例#18
0
 public void RemoveFromAliveEnemies(EnergyBall enemy)
 {
     enemies.Remove(enemy);
 }
示例#19
0
 public void destroyEnergy(EnergyBall ball)
 {
     EnergyList.RemoveAll(orb => orb == ball);
     GameObject.Destroy(ball.gameObject);
 }
示例#20
0
 public void addEnergy(EnergyBall e)
 {
     this.EnergyList.Add(e);
 }
示例#21
0
    void EnergyBall()
    {
        // Create the Bullet from the Bullet Prefab
        if (EBRateOfFire > EBRateOfFireMax)
        {
            // Add velocity to the bullet
            var bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, movementScript.CameraT.rotation);
            bullet.GetComponent <Rigidbody>().velocity = bullet.transform.forward * EBlastSpeed;

            EnergyBall PlayerShooter = bullet.GetComponent <EnergyBall>();
            PlayerShooter.Shooter = this.gameObject;

            // Destroy the bullet after 2 seconds
            Destroy(bullet, ProjectileLife);
            EBRateOfFire = 0;
        }
        else
        {
            EBRateOfFire += 1 * Time.deltaTime;
        }
        if (MultiHit > 0)
        {
            //Can the Player shoot any more projectiles for Multi Cast?
            if (EBRateOfFireMulitiCount > 0)
            {
                //Cast Timer for MultiCast
                if (EBRateOfFireMuliti > EBRateOfFireMulitiMax)
                {
                    EBRateOfFireMulitiCount -= 1;
                    EBRateOfFireMuliti       = 0;
                    // Add velocity to the bullet
                    var bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, movementScript.CameraT.rotation);
                    bullet.GetComponent <Rigidbody>().velocity = bullet.transform.forward * EBlastSpeed;
                    EnergyBall PlayerShooter = bullet.GetComponent <EnergyBall>();
                    PlayerShooter.Shooter = this.gameObject;


                    // Destroy the bullet after 2 seconds
                    Destroy(bullet, ProjectileLife);
                    EBRateOfFire = 0;
                }
                else
                {
                    EBRateOfFireMuliti += (1 * Time.deltaTime) * 3;
                }
            }
            else
            {
                //Cooldown
                if (EBRateOfFireMulitiCool > EBRateOfFireMulitiCoolMax)
                {
                    EBRateOfFireMulitiCount = EBRateOfFireMulitiCountMax;
                    EBRateOfFireMulitiCool  = 0;
                }
                else
                {
                    EBRateOfFireMulitiCool += 1 * Time.deltaTime;
                }
            }
        }
    }
示例#22
0
    public virtual void SeekTarget()
    {
//		Collider[] cols = Physics.OverlapSphere(transform.position,targetSeekRadius);
        float     dist    = Mathf.Infinity;
        Transform closest = null;

        if (!this)
        {
            return;
        }

        if (PlayerInRange())
        {
            List <Ammo> ammos = new List <Ammo>();
            if (AnimalIsFrogType())
            {
//				Debug.Log("seek frog.");
                // Frogs and toads search your whole inventory.
                foreach (Gadget g in PlayerGadgetController.inst.GetAllGadgetInInventory())
                {
//					Debug.Log("gadget."+g+".  its ammoinfo count:"+g.GetAmmoInfo().Count);
                    foreach (Ammo a in g.GetAmmoInfo())
                    {
                        // Try to set the target to the number held by the player so you can bait the animal to follow you
//						Debug.Log("A:"+a.ammoValue);
                        if (AnimalBehaviorManager.inst.CheckValidTarget(GetAnimalTargetPreference(), this, a.ammoValue))
                        {
//							Debug.Log("try to set target to player gadg:"+g+", ammo;"+a);
                            AttemptToSetTarget(Player.inst.transform, false, g);
                            // Note that if a gadget has TWO ammos loaded only ONE of which is valid, we only pass the GADGET as the target. Later we'll need to sort whether this gadget really has edible ammo.
                            return;                             // prefer player.
                        }
                        else
                        {
//							Debug.Log("A wasn't valid:"+a);
                        }
                    }
                }
//				Debug.Log("got ammos;"+ammos.Count);
            }
            else
            {
                // Not a frog, search current gadget only.
                foreach (Ammo a in PlayerGadgetController.inst.GetCurrentGadget().GetAmmoInfo())
                {
                    // Try to set the target to the number held by the player so you can bait the animal to follow you
                    if (AnimalBehaviorManager.inst.CheckValidTarget(GetAnimalTargetPreference(), this, a.ammoValue))
                    {
                        //					Debug.Log("try to set target to playER");
                        AttemptToSetTarget(Player.inst.transform);
                        return;                         // prefer player.
                    }
                }
            }

            if (AnimalIsFrogType())
            {
                // If player not holding number in hand, and animal was frog, also check player inventory.
                // This is because we want frogs to act as restrictors and they can eat all numbers from your inventory if the rules match (e.g. all whole numbers)
                foreach (NumberInfo ni2 in Inventory.inst.GetNumbersInInventory())
                {
                    if (ni2.GetComponent <FrogTarget>())
                    {
                        continue;
                    }
                    if (AnimalBehaviorManager.inst.CheckValidTarget(GetAnimalTargetPreference(), this, ni2))
                    {
                        AttemptToSetTarget(ni2.transform, true);
                        return;                         // prefer player.
                    }
                }

                // only frogs target vehicle numbers. For now.
                foreach (Vehicle v in VehicleManager.inst.vehicles)
                {
                    EnergyBall eb = v.GetComponentInChildren <EnergyBall>();
                    if (eb)
                    {
                        NumberInfo ni2 = eb.GetComponent <NumberInfo>();
//						Debug.Log("eb:"+ni2.name);
                        if (AnimalBehaviorManager.inst.CheckValidTarget(GetAnimalTargetPreference(), this, ni2, false))
                        {
//							Debug.Log("attempt:"+ni2.transform.position+","+transform.position+", delta:"+Vector3.Distance(ni2.transform.position,transform.position));
                            if (AttemptToSetTarget(ni2.transform))
                            {
                                return;
                            }
//							return;
                        }
                        else
                        {
//							Debug.Log("invalid");
                        }
                    }
                }
            }
        }

//		Debug.Log(name + " is looping 1. Numbers in range:"+GetNumbersInRange().Count);
//		NumberManager.inst.GetAllNumbersInScene(); // ?? This is really the most efficient? hm
        foreach (NumberInfo ni in GetNumbersInRange())
        {
            if (!ni)
            {
                continue;
            }
            if (ni.GetComponent <FrogTarget>() && !ni.GetComponent <Animal_Frog>())
            {
                continue;
            }
//			if ((AnimalIsFrogType()) && ni.GetComponent<FrogTarget>()) continue;
            float diff = Vector3.Distance(ni.transform.position, transform.position);
            if (diff < dist)
            {
                if (AnimalBehaviorManager.inst.CheckValidTarget(GetAnimalTargetPreference(), this, ni))
                {
                    dist    = diff;
                    closest = ni.transform;
                }
                else
                {
//					Debug.Log("invalid:"+ni);
                }
            }
        }
        if (closest)
        {
//			Debug.Log(name + " tried to set target to "+closest);
            AttemptToSetTarget(closest);
        }
    }