public void CheckIfCanSpawn()
        {
            int     lastEnemyDistance = 0;
            Vector2 spawnPoint        = GameState.Instance.GetVar <Vector2>("spawn_point");
            Penguin penguin           = GameState.Instance.GetVar <Penguin>("penguin");

            spawnPoint.X = penguin.GetPosition().X + GameState.Instance.GetCurrentScene().GetWindowWidth();

            if (LastSpawnedEnemy != null)
            {
                lastEnemyDistance = (int)spawnPoint.X - (int)LastSpawnedEnemy.GetPosition().X;
            }

            double spawnChance = this.SpawnRandom.NextDouble();

            if (LastSpawnedEnemy == null || lastEnemyDistance >= MAX_ENEMY_DISTANCE || (lastEnemyDistance >= MIN_ENEMY_DISTANCE && spawnChance < SPAWN_RATE))
            {
                double walrusChance = this.SpawnRandom.NextDouble();

                if (walrusChance < WALRUS_RATE)
                {
                    Walrus walrus = new Walrus(spawnPoint);
                    GameState.Instance.GetCurrentScene().AddEntity(walrus);
                    LastSpawnedEnemy = walrus;
                }
                else
                {
                    spawnPoint.Y = spawnPoint.Y - 90;
                    Seagull seagull = new Seagull(spawnPoint);
                    GameState.Instance.GetCurrentScene().AddEntity(seagull);
                    LastSpawnedEnemy = seagull;
                }
            }
        }
Exemple #2
0
    private void Generate()
    {
        Seagull seagull = (Seagull)seagullScene.Instance();

        seagull.SetTracker(camera);
        AddChild(seagull);
    }
Exemple #3
0
    void Start()
    {
        randomFreq = (float)(1.0 / randomFreq); // undefined number, a hack to get a truly random number
        Debug.Log("Random Freq: " + randomFreq);

        gameObject.tag = transform.parent.gameObject.tag;

        animationComponent = GetComponentInChildren <Animation>();
        animationComponent.Blend("fly");
        animationComponent["fly"].normalizedTime = Random.value;
        glide = animationComponent["glide"];

        origin             = transform.parent;
        target             = origin.GetComponent <SeagullFlightPath>();
        transform.parent   = null;
        transformComponent = transform;

        Seagull[] tempSeagulls = new Seagull[0];
        if (transform.parent)
        {
            tempSeagulls = transform.parent.GetComponentsInChildren <Seagull>();
        }
        objects       = new Transform[tempSeagulls.GetLength(0)];
        otherSeagulls = new Seagull[tempSeagulls.GetLength(0)];
        for (int i = 0; i < tempSeagulls.Length; i++)
        {
            objects[i]       = tempSeagulls[i].transform;
            otherSeagulls[i] = tempSeagulls[i];
        }

        UpdateRandom();
    }
Exemple #4
0
        public EntityManager()
        {
            staticEntities.Add(new Palmtree(new Vector2(730, 290), this, 50, 50));
            staticEntities.Add(new Palmtree(new Vector2(710, 310), this, 50, 50));
            staticEntities.Add(new Palmtree(new Vector2(650, 220), this, 50, 50));
            staticEntities.Add(new Tent(new Vector2(480, 380), this, 50, 50));
            staticEntities.Add(new Bush(new Vector2(260, 540), this, 50, 50));
            staticEntities.Add(new Bush(new Vector2(380, 150), this, 50, 50));

            Survivor survivor = new Survivor(new Vector2(500, 500), this);

            movingEntities.Add(survivor);

            Seagull seagull1 = new Seagull(new Vector2(100, 250), this);
            Seagull seagull2 = new Seagull(new Vector2(230, 230), this);
            Seagull seagull3 = new Seagull(new Vector2(140, 300), this);
            Seagull seagull4 = new Seagull(new Vector2(100, 100), this);
            Seagull seagull5 = new Seagull(new Vector2(150, 150), this);

            movingEntities.Add(seagull1);
            movingEntities.Add(seagull2);
            movingEntities.Add(seagull3);
            movingEntities.Add(seagull4);
            movingEntities.Add(seagull5);
        }
Exemple #5
0
    private void HandleGullDeath(Seagull gull)
    {
        GameObject points = _points.Dequeue();

        points.SetActive(true);
        points.transform.position = gull.transform.position;
        points.GetComponentInChildren <Text>().text = "+" + gull.GullKillValue;
        _points.Enqueue(points);
    }
 private void OnTriggerEnter(Collider other)
 {
     if (other.transform.tag == "Enemy")
     {
         Seagull s = other.GetComponent <Seagull>();
         s.SetTarget(transform);
         affectedEnemies.Add(s);
     }
 }
Exemple #7
0
    private void PullGull()
    {
        // Pull new gull.
        activeGull = seagulls[0];
        seagulls.RemoveAt(0);
        hasActiveGull = true;

        refRing.Initialize();
    }
Exemple #8
0
    void RunQ4()
    {
        /*
         * 海鸥的飞行速度是20,翅膀为灰色,最喜欢吃的食物是沙丁鱼。
         * 海燕的飞行速度是80,翅膀为棕色,最喜欢吃的食物是小虾。
         * 鸵鸟的奔跑速度是30,翅膀为褐色,最喜欢吃的食物是苹果。
         * */
        Seagull seagull = new Seagull(20, "grey", "sardine");
        Petrel  petrel  = new Petrel(80, "brown", "shrimp");
        Ostrich ostrich = new Ostrich(30, "brown", "apple");

        Debug.Log("海鸥飞行速度" + seagull.flySpeed + " 翅膀颜色" + seagull.wingColor + " 爱吃" + seagull.favoriteFood);
        Debug.Log("海燕飞行速度" + petrel.flySpeed + " 翅膀颜色" + petrel.wingColor + " 爱吃" + petrel.favoriteFood);
        Debug.Log("鸵鸟奔跑速度" + ostrich.runSpeed + " 翅膀颜色" + ostrich.wingColor + " 爱吃" + ostrich.favoriteFood);
    }
Exemple #9
0
 private void HandleGullHit(Seagull gull)
 {
     _lastGullHitTime = Time.time;
 }
 // Use this for initialization
 void Start()
 {
     _blueTurtleParent = GameObject.Find("BlueTurtleParent");
     _greenTurtleParent = GameObject.Find ("GreenTurtleParent");
     _seagull = GameObject.Find("Seagull").GetComponent<Seagull>();
 }
Exemple #11
0
    void Update()
    {
        float   speed      = velocity.magnitude;
        Vector3 avoidPush  = Vector3.zero;
        Vector3 avgPoint   = Vector3.zero;
        int     count      = 0;
        float   f          = 0.0f;
        Vector3 myPosition = transformComponent.position;
        Vector3 forceV;
        float   d;

        for (int i = 0; i < objects.Length; i++)
        {
            Transform o = objects[i];
            if (o != transformComponent)
            {
                var otherPosition = o.position;
                avgPoint += otherPosition;
                count++;

                forceV = myPosition - otherPosition;
                d      = forceV.magnitude;
                if (d < followRadius)
                {
                    if (d < avoidanceRadius)
                    {
                        f = 1.0f - (d / avoidanceRadius);
                        if (d > 0)
                        {
                            avoidPush += (forceV / d) * f * avoidanceForce;
                        }
                    }

                    f = d / followRadius;
                    Seagull otherSealgull = otherSeagulls[i];
                    avoidPush += otherSealgull.normalizedVelocity * f * followVelocity;
                }
            }
        }

        Vector3 toAvg;

        if (count > 0)
        {
            avoidPush /= count;
            toAvg      = (avgPoint / count) - myPosition;
        }
        else
        {
            toAvg = Vector3.zero;
        }

        forceV = origin.position + target.offset - myPosition;
        d      = forceV.magnitude;
        f      = d / toOriginRange;
        if (d > 0)
        {
            originPush = (forceV / d) * f * toOriginForce;
        }

        if (speed < minSpeed && speed > 0)
        {
            velocity = (velocity / speed) * minSpeed;
        }

        Vector3 wantedVel = velocity;

        wantedVel -= wantedVel * damping * Time.deltaTime;
        wantedVel += randomPush * Time.deltaTime;
        wantedVel += originPush * Time.deltaTime;
        wantedVel += avoidPush * Time.deltaTime;
        wantedVel += toAvg.normalized * gravity * Time.deltaTime;
        Vector3 diff = transformComponent.InverseTransformDirection(wantedVel - velocity).normalized;

        bank     = Mathf.Lerp(bank, diff.x, Time.deltaTime * 0.8f);
        velocity = Vector3.RotateTowards(velocity, wantedVel, turnSpeed * Time.deltaTime, 100.0f);

        transformComponent.rotation = Quaternion.LookRotation(velocity);
        transformComponent.Rotate(0, 0, -bank * bankTurn);

        // Raycast
        float distance = speed * Time.deltaTime;

        if (raycast && distance > 0.00 && Physics.Raycast(myPosition, velocity, out hit, distance))
        {
            velocity = Vector3.Reflect(velocity, hit.normal) * bounce;
        }
        else
        {
            transformComponent.Translate(velocity * Time.deltaTime, Space.World);
        }

        // Animation Controls
        if (speed > 0)
        {
            float up = (velocity / speed).y;
            if (gliding && up > 0)
            {
                gliding = false;
                animationComponent.Blend("glide", 0.0f, 0.2f);
                animationComponent.Blend("fly", 1.0f, 0.2f);
            }
            if (!gliding && up < -0.20)
            {
                gliding = true;
                animationComponent.Blend("glide", 1.0f, 0.2f);
                animationComponent.Blend("fly", 0.0f, 0.2f);
                glide.speed = 0;
            }
        }

        // Sounds
        if (SeagullSoundHeat.heat < Mathf.Pow(Random.value, 1 / soundFrequency / Time.deltaTime))
        {
            AudioSource.PlayClipAtPoint(sounds[Random.Range(0, sounds.GetLength(0))], myPosition, 0.9f);
            SeagullSoundHeat.heat += (1 / soundFrequency) / 10;
        }

        normalizedVelocity = velocity.normalized;
    }
Exemple #12
0
 private void AddDeadSeagullMoney(Seagull gull)
 {
     SandDollars += gull.GullKillValue;
 }