Inheritance: MonoBehaviour
        private bool TryGetInsects(CommandLineApplication app, out IReadOnlyCollection <string> insectNames)
        {
            if (string.IsNullOrWhiteSpace(Insect))
            {
                insectNames = Cache.InsectList;
                return(true);
            }

            if (!Cache.InsectList.Contains(Insect.ToLower().Trim()))
            {
                app.Error.WriteLine($"Could not find {Insect}. Use \"--list\" to show valid insects.");
                app.ShowHint();
                insectNames = null;
                return(false);
            }

            if (Level.HasValue && !Cache.GetDownloader(Insect.ToLower().Trim()).GetLevels().Contains(Level.Value))
            {
                app.Error.WriteLine($"Could not find resolution {Level} on insect {Insect}. Use \"--resolutions\" to show valid resolutions for an insect.");
                app.ShowHint();
                insectNames = null;
                return(false);
            }

            insectNames = new[] { Insect.ToLower().Trim() };
            return(true);
        }
Example #2
0
        /// <summary>
        /// Create an animal object of a species (Bee,Butterfly) of Insect cateogry.
        /// </summary>
        /// <param name="Species">Species: Bee, Butterfly, etc.</param>
        /// <returns>Object of the Species type.</returns>
        /// <remarks></remarks>
        public static Insect CreateInsect(InsectSpecies Species)
        {
            Insect animalObj = null;        //type not known at this time

            //type determined by late binding
            switch (Species)
            {
            case InsectSpecies.Bee:
                animalObj = new Bee();               //Late binding
                break;

            //Continue with the rest
            case InsectSpecies.Butterfly:
                animalObj = new Butterfly();        //Late binding
                break;

            default:
                Debug.Assert(false, "To be completed!");
                break;
            }

            //Set the category
            animalObj.Category = CategoryType.Insect;

            return(animalObj);     //return the created animal object.
        }
Example #3
0
    public override InteractionResult InteractWith(Interactable i)
    {
        if (i is UpgradeContainer && (distance(transform, i.transform) <= upgradeDistance))
        {
            return(((UpgradeContainer)i).UpgradeMe(this));
        }

        if (!readyToFire)
        {
            return(new InteractionResult(this, false));
        }

        ShootAt(i.transform);

        if (i is Insect)
        {
            Insect insect = (Insect)i;
            if (destroyMultipleTargets)
            {
                foreach (Insect it in insectReg.GetNearInsects(insect, destructionRange))
                {
                    it.ShootAt(this);
                }
            }
            return(insect.ShootAt(this));
        }

        return(new InteractionResult(this, false, false));
    }
Example #4
0
 public void TryAddEnemy(Insect item)
 {
     lock (syncRoot)
     {
         if (!this.enemyRepo.Contains(item))
         {
             this.enemyRepo.Add(item);
         }
     }
 }
Example #5
0
 private void InsectMiss(Insect insect)
 {
     if (insect.GetComponent <SafeInsect>())
     {
         DangerInsectSmash();
     }
     if (_isLevelComplete)
     {
         LevelComplete();
     }
 }
Example #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //Debug.Log(collision.transform.name);
        if (collision.transform.CompareTag("Enemy") && collision.transform.GetComponent <Insect>())
        {
            Insect collider = collision.transform.GetComponent <Insect>();

            TakeDamage(collider.CollisionDamage, collision.GetComponent <Insect>().GetCollisionVelocity(transform, rb.velocity));
            collider.TakeDamage(GetComponent <Insect>().CollisionDamage);
        }
    }
Example #7
0
 public void AddEnemyToChunk(Insect insect)
 {
     if (!enemiesInChunk.Contains(insect))
     {
         enemiesInChunk.Add(insect);
     }
     if (!display)
     {
         insect.gameObject.SetActive(false);
     }
 }
Example #8
0
 //public HoneycombCell honeyGrid;
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Player"))
     {
         Insect   insect = Instantiate(transform.parent.GetComponent <HoneycombCell>().honeyGrid.GetEnemyPrefab(), transform.position, Quaternion.identity).GetComponent <Insect>();
         MapChunk chunk  = Utility.GetMapChunk(insect.transform.position);
         chunk.AddEnemyToChunk(insect);
         insect.InsectPrefab = transform.parent.GetComponent <HoneycombCell>().honeyGrid.GetEnemyPrefab();
         transform.parent.GetComponent <HoneycombCell>().honeyGrid.DestroyHoneycomb();
     }
 }
 public void BeginDPS()
 {
     entity = GetComponent <Insect>();
     if (entity != null)
     {
         StartCoroutine(Dps());
     }
     else
     {
         Destroy(this);
     }
 }
Example #10
0
 /// <summary>
 /// Attacks the given insect.
 /// </summary>
 /// <param name="insect">The insect target.</param>
 protected void Attack(Insect insect)
 {
     // Go to insect if not in view range, else attack it
     if (!InViewRange(insect))
     {
         GoTo(insect);
     }
     else
     {
         _ant.Attack(insect);
     }
 }
Example #11
0
 public void SetInsectList(InsectList[] insectList)
 {
     foreach (InsectList item in insectList)
     {
         for (int i = 0; i < item.Count; i++)
         {
             Vector3 spawnPoint = new Vector3(Random.Range(-_colliderSizeX, _colliderSizeX), transform.position.y, transform.position.z);
             Insect  insect     = Instantiate(item.Insect, spawnPoint, item.Insect.gameObject.transform.rotation, _spawnerPool.transform);
             InsectSpawned?.Invoke(insect);
             insect.gameObject.SetActive(false);
         }
     }
 }
Example #12
0
    IEnumerator Generate()
    {
        while (nums < points.Count)
        {
            Insect ins = Instantiate(Insect).GetComponent <Insect>();
            ins.transform.SetParent(this.transform);
            ins.transform.localPosition = insectPos.localPosition;
            ins.insectHome = this;
            ins.index      = nums;
            nums++;

            yield return(new WaitForSeconds(deltaTime));
        }
    }
Example #13
0
        public void ReportInsect(Insect insect)
        {
            if (Insects.Contains(insect) && insect.CurrentEnergy > 0)
            {
                return;
            }

            if (insect.CurrentEnergy <= 0)
            {
                Insects.Remove(insect);
            }
            else
            {
                Insects.Add(insect);
            }
        }
Example #14
0
    private void SmashInsect(Insect insect)
    {
        if (insect.GetComponent <SafeInsect>())
        {
            SafeInsectSmash(insect);
        }
        else
        {
            DangerInsectSmash();
        }

        if (_isLevelComplete)
        {
            LevelComplete();
        }
    }
Example #15
0
    public List <Insect> GetNearInsects(Insect i, float range)
    {
        List <Insect> ret = new List <Insect>();

        foreach (Insect it in insects)
        {
            if (it == i)
            {
                continue;
            }
            if ((it.transform.position - i.transform.position).magnitude <= range)
            {
                ret.Add(it);
            }
        }
        return(ret);
    }
Example #16
0
        private void combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox combobox = sender as ComboBox;

            if (combobox.SelectedIndex != -1 && combobox == combobox1)
            {
                combobox1isclick = true;
                Insect insect = (Insect)combobox.SelectedItem;
                InsectData.setInsect(insect.Name);
                frame2.Source = new Uri("pack://application:,,,/Editing/ChartScrollIntoView.xaml");
                frame2.Refresh();
            }
            if (combobox.SelectedIndex != -1 && combobox == combobox2)
            {
                combobox2isclick = true;
                Insect insect = (Insect)combobox.SelectedItem;
                InsectData.setInsect(insect.Name);
                frame3.Source = new Uri("pack://application:,,,/series/ValueOverlays.xaml");
                frame3.Refresh();
            }
        }
Example #17
0
        public Window1()
        {
            InitializeComponent();


            color = lab1.Background;
            List <string> list = InsectData.getInsect();

            insectname = list[1];
            List <Insect> insects = new List <Insect>();

            for (int i = 0; i < list.Count; i++)
            {
                Insect insect = new Insect();
                insect.Id   = i.ToString();
                insect.Name = list[i];
                insects.Add(insect);
            }
            combobox1.ItemsSource       = insects;
            combobox1.DisplayMemberPath = "Name";
            combobox1.SelectedValuePath = "Id";
            combobox1.Visibility        = Visibility.Hidden;
            combobox2.ItemsSource       = insects;
            combobox2.DisplayMemberPath = "Name";
            combobox2.SelectedValuePath = "Id";
            combobox2.Visibility        = Visibility.Hidden;
            brush                = new SolidColorBrush(Color.FromArgb(225, 68, 87, 84));
            grid1.Visibility     = Visibility.Visible;
            grid2.Visibility     = Visibility.Hidden;
            grid3.Visibility     = Visibility.Hidden;
            combobox1.Visibility = Visibility.Hidden;
            combobox2.Visibility = Visibility.Hidden;

            this.lab1.Background = brush;
            //label.Foreground = Brushes.Black;
            frame1.Source = new Uri("pack://application:,,,/MainWindow.xaml");
            frame1.Refresh();
        }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Honeycomb"))
        {
            //Destroy(collision.gameObject);
            if (honeycombBounce)
            {
                Vector2 velocity = GetComponent <Rigidbody2D>().velocity;
                Vector2 normal   = collision.transform.position - transform.position;
            }
            else
            {
                HoneycombPos hexPos = Utility.WorldPointToHoneycombGrid(collision.GetComponent <Honeycomb>().honeyGrid.position);
                collision.GetComponent <Honeycomb>().DamageHoneycomb(Damage);
                if (false) //for testing HoneycombPos.GetAdjecentHoneycomb()
                {
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(0, 1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(1, 1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(1, -1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(0, -1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(-1, -1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                    Map.StaticMap.GetHoneycomb(hexPos.GetAdjecentHoneycomb(-1, 1)).honeycomb.GetComponent <Honeycomb>().DamageHoneycomb(10);
                }
                Destroy(gameObject);
            }
        }

        if (collision.transform.CompareTag("Enemy") && collision.transform.GetComponent <Insect>())
        {
            Insect collider = collision.transform.GetComponent <Insect>();


            collider.TakeDamage(Damage);
            FindObjectOfType <LevelHandler>().UpdatePlayerStats(1, 0);
            Destroy(gameObject);
        }
    }
Example #19
0
    void SpawnInsect()
    {
        if (insectReg.GetNumberOfInsects() >= maxNumberOfInsects)
        {
            return;
        }

        //Which Insect so Spawn
        Debug.Assert(insects.Count >= 1);
        int    insectIndex = Random.Range(0, (insects.Count - 1));
        Insect insect      = insects[insectIndex];

        //Figure out where to Spawn it
        Vector3 spawnPoint = RandomPointOnCircleEdge(Random.Range(minSpawnDistance, maxSpawnDistance));

        //Spawn the insect
        Insect newInsect = Instantiate(insect, spawnPoint, Quaternion.identity, insectParent);

        newInsect.SetInsectRegistry(insectReg);

        averageSpawnTime     /= spawnSpeedup;
        minSpawnTimeVariance /= spawnSpeedup;
        maxSpawnTimeVariance /= spawnSpeedup;
    }
        public static Animal GenerateAnimal(string AnimalType, string[] animalNames, int maxWeight, Random random, float weightScale = 1)
        {
            Animal     animal           = null;
            Array      values           = Enum.GetValues(typeof(AnimalDiet));
            AnimalDiet randomAnimalDiet = (AnimalDiet)values.GetValue(random.Next(values.Length));

            int    index      = random.Next(0, animalNames.Length);
            string animalname = animalNames[index];

            if (AnimalType == typeof(Amphibian).Name)
            {
                animal = new Amphibian(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }
            if (AnimalType == typeof(Reptile).Name)
            {
                animal = new Reptile(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }
            if (AnimalType == typeof(Mammal).Name)
            {
                animal = new Mammal(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }
            if (AnimalType == typeof(Fish).Name)
            {
                animal = new Fish(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }
            if (AnimalType == typeof(Insect).Name)
            {
                animal = new Insect(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }
            if (AnimalType == typeof(Bird).Name)
            {
                animal = new Bird(animalname, random.Next(1, maxWeight) * weightScale, randomAnimalDiet);
            }

            return(animal);
        }
Example #21
0
 public void RegisteerInsect(Insect i)
 {
     insects.Add(i);
 }
Example #22
0
    void Start()
    {
        // Illustrate that factory reuses already made insects
        InsectFlyweightFactory insectFactory = new InsectFlyweightFactory();

        insectFactory.showMessages = true;

        Debug.LogError("Testing reuse of insects");
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                insectFactory.GetInsectData((InsectType)i);
            }
        }

        Debug.LogError("Testing the pattern in action");
        // An example of how this might work to our advantage.
        for (int i = 0; i < 3; i++)
        {
            Insect challenger = insectFactory.GetInsectData((InsectType)i);
            Debug.Log("Insect to test: " + challenger.insectType.ToString());

            List <InsectType> defeatedInsect = new List <InsectType>();

            // At what point can challenger be stronger than other insects at varying health.
            for (int j = 0; j < challenger.maxHealth; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    if (k == i) // Don't attack insects of the same type.
                    {
                        continue;
                    }

                    InsectType insectType = (InsectType)k;

                    if (defeatedInsect.Contains(insectType))
                    {
                        continue;
                    }

                    Insect defender = insectFactory.GetInsectData(insectType);

                    for (int m = defender.maxHealth; m >= 0; m--)
                    {
                        int challengerStrength = challenger.GetStrength(j);
                        int defenderStrength   = defender.GetStrength(m);

                        if (challengerStrength > defenderStrength)
                        {
                            defeatedInsect.Add(insectType);
                            Debug.LogWarning(challenger.insectType.ToString() + " at health: " + j.ToString() + " defeated " + defender.insectType.ToString() + " at full health of " + defender.maxHealth.ToString());
                            break;
                        }
                    }
                }
            }

            // Check if anyone wasn't defeated.
            for (int h = 0; h < 3; h++)
            {
                if (h == i) // Insects of the same type won't be checked since we didn't even try to attack them.
                {
                    continue;
                }

                InsectType insectType = (InsectType)h;
                if (!defeatedInsect.Contains(insectType))
                {
                    Debug.LogError(challenger.insectType.ToString() + " could not defeat " + insectType.ToString());
                }
            }
        }
    }
Example #23
0
 private void SafeInsectSmash(Insect insect)
 {
     _score       += insect.Score;
     _scoreUI.text = _score.ToString();
 }
Example #24
0
    void FlashTarget()
    {
        Insect bug = GrubTarget.GetComponent <Insect>();

        bug.FlashColors();
    }
Example #25
0
 public InsectList(Insect insect, int count)
 {
     _insect = insect;
     _count  = count;
 }
Example #26
0
 private void SpawnInsect(Insect insect)
 {
     insect.Smashed += SmashInsect;
 }
 private static NormalAnimal SelectHemisphereAndConstructInsect(Hemisphere hemisphere, Insect obj, bool owned, bool museumHave)
 {
     if (hemisphere == Hemisphere.North)
     {
         var normal = new NormalAnimal {
             Name = obj.Name, Icon = $"ms-appx:///Icons/{obj.English}.jpg", Number = obj.Number, English = obj.English, Japanese = obj.Japanese, Price = Convert.ToInt32(obj.Price), Position = obj.Position, ShapeOrWeather = obj.Weather, Time = obj.Time, AppearMonth = obj.Hemisphere.North.Month.AppearMonth, Owned = owned, MuseumHave = museumHave
         };
         return(normal);
     }
     else
     {
         var normal = new NormalAnimal {
             Name = obj.Name, Icon = $"ms-appx:///Icons/{obj.English}.jpg", Number = obj.Number, English = obj.English, Japanese = obj.Japanese, Price = Convert.ToInt32(obj.Price), Position = obj.Position, ShapeOrWeather = obj.Weather, Time = obj.Time, AppearMonth = obj.Hemisphere.South.Month.AppearMonth, Owned = owned, MuseumHave = museumHave
         };
         return(normal);
     }
 }
Example #28
0
 public InsectTask(Insect insect)
 {
     Target = insect;
 }
Example #29
0
    /// <summary>
    /// Spawns insects and updates timers.
    /// </summary>
    private void Update()
    {
        // checks if no insects should be spawnned
        if (m_isPaused)
        {
            return;
        }
        if (!loop && !randomiseAllPaths && !randomiseAllTypes && m_insectIndex >= insectOrder.Length && transform.childCount == 0)
        {
            FindObjectOfType <GameController>().gameWin = true;
        }

        // decrements the timer
        m_spawnTimer -= Time.deltaTime;
        // checks if the timer has run out
        if (m_spawnTimer <= 0.0f)
        {
            // gets a new random timer duration between the min and max spawn durations
            m_spawnTimer = Random.Range(minSpawnDuration, maxSpawnDuration);

            // checks if the insect being spawnned should have a random type and path
            if (randomiseAllPaths && randomiseAllTypes)
            {
                // gets a random insect index from the collection of insect prefabs
                int insectIndex = Random.Range(0, insects.Length);
                // gest a random path index from the collection of paths in the scene
                int pathIndex = Random.Range(0, pathCreators.Length);
                // creates an insect on the path
                Insect insect = Instantiate(insects[insectIndex], pathCreators[pathIndex].path.vertices[0], Quaternion.identity);
                insect.pathCreator      = pathCreators[pathIndex];
                insect.transform.parent = gameObject.transform;
                // checks if the enemy spawnned is a fire ant
                if (insectIndex == (int)InsectType.fireAnt)
                {
                    insect.fireAnt = true;
                }
            }
            // checks if only the insect type is random
            else if (randomiseAllTypes)
            {
                // gets a random insect index from the collection of insect prefabs
                int insectIndex = Random.Range(0, insects.Length);
                // gets the path index from the insect order
                int pathIndex = insectOrder[m_insectIndex].pathIndex;
                // if the index provided is out of range then randomise the path
                if (pathIndex >= pathCreators.Length || pathIndex < 0)
                {
                    pathIndex = Random.Range(0, pathCreators.Length);
                }
                // creates an insect on the path
                Insect insect = Instantiate(insects[insectIndex], pathCreators[pathIndex].path.vertices[0], Quaternion.identity);
                insect.pathCreator      = pathCreators[pathIndex];
                insect.transform.parent = gameObject.transform;
                // checks if the enemy spawnned is a fire ant
                if (insectIndex == (int)InsectType.fireAnt)
                {
                    insect.fireAnt = true;
                }
                // increments the current index in the insect order
                m_insectIndex++;
            }
            else if (randomiseAllPaths)
            {
                // gets the insect index from the insect order
                int insectIndex = (int)insectOrder[m_insectIndex].insectType;
                // if the index provided is of random type then randomise the insect type
                if (insectIndex == (int)InsectType.random)
                {
                    insectIndex = Random.Range(0, insects.Length);
                }
                int pathIndex = Random.Range(0, pathCreators.Length);
                // creates an insect on the path
                Insect insect = Instantiate(insects[insectIndex], pathCreators[pathIndex].path.vertices[0], Quaternion.identity);
                insect.pathCreator      = pathCreators[pathIndex];
                insect.transform.parent = gameObject.transform;
                // checks if the enemy spawnned is a fire ant
                if (insectIndex == (int)InsectType.fireAnt)
                {
                    insect.fireAnt = true;
                }
                // increments the current index in the insect order
                m_insectIndex++;
            }
            else
            {
                // gets the insect index from the insect order
                int insectIndex = (int)insectOrder[m_insectIndex].insectType;
                // if the index provided is of random type then randomise the insect type
                if (insectIndex == (int)InsectType.random)
                {
                    insectIndex = Random.Range(0, insects.Length);
                }
                // gets the path index from the insect order
                int pathIndex = insectOrder[m_insectIndex].pathIndex;
                // if the index provided is out of range then randomise the path
                if (pathIndex >= pathCreators.Length || pathIndex < 0)
                {
                    pathIndex = Random.Range(0, pathCreators.Length);
                }
                // creates an insect on the path
                Insect insect = Instantiate(insects[insectIndex], pathCreators[pathIndex].path.vertices[0], Quaternion.identity);
                insect.pathCreator      = pathCreators[pathIndex];
                insect.transform.parent = gameObject.transform;
                // checks if the enemy spawnned is a fire ant
                if (insectIndex == (int)InsectType.fireAnt)
                {
                    insect.fireAnt = true;
                }
                // increments the current index in the insect order
                m_insectIndex++;
            }

            // if the order should loop and the index is out of range the wrap the index
            if (loop && m_insectIndex >= insectOrder.Length)
            {
                m_insectIndex = 0;
            }
        }
    }
Example #30
0
 public void DeregisterInsect(Insect i)
 {
     insects.Remove(i);
 }