IEnumerator CorSortieOctopus()
    {
        yield return(new WaitForSeconds(spawnTimer));

        while (true)
        {
            sortie = null;
            for (int i = 0; i < octopusModum.Count; i++)
            {
                if (octopusModum[i].gameObject.activeSelf == false)
                {
                    sortie = octopusModum[i];
                    break;
                }
            }
            if (sortie == null)
            {
                yield return(new WaitForSeconds(spawnTimer));
            }
            else
            {
                if (probability > Random.Range(0, 100))
                {
                    animator.SetBool("Create", true);
                }
            }
            yield return(new WaitForSeconds(spawnTimer));
        }
    }
Пример #2
0
    public bool variant_mode;                      //indicates if we are playing in variant mode or not

    void Start()
    {
        //set variant mode to false
        variant_mode = false;
        //check if we are in variant mode
        if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "VariantMode")
        {
            variant_mode = true;                        //if we are set it to true
        }
        gold_objects    = new LinkedList <Gold>();      //instantiate list of gold objects
        angry_fish_list = new LinkedList <AngryFish>(); //instantiate list of fish
        octopus_list    = new Octopus[2];               //instantiate array of octopus
        for (int i = 0; i < octopus_list.Length; i++)
        {
            octopus_list[i] = new Octopus(level_time); //create two new empty octopus
            //they wont show up but they will have a spawn time based on how long the level is
        }
        last_gold_add = DateTime.Now; //set last gold add to now
        total_gold    = 0;            //the total gold the player has collected should be 0 to start

        //we need to instantiate 5 angry fish at different depths
        for (int i = 0; i < 5; i++)
        {
            //create a new angry fish at random depth
            AngryFish new_fish = new AngryFish(Instantiate(angry_fish, new Vector3(-15.0f, UnityEngine.Random.Range(-3.1f, 1.1f), -1), transform.rotation));
            angry_fish_list.AddLast(new_fish); //add it to the list
        }

        //set the time in level to 0 to start
        time_in_level = 0;

        //also set level to 1
        level = 1;
    }
Пример #3
0
    //this function is called in update and checks if the level should be updated
    private void check_level_update()
    {
        //this function checks if it is time to update the level and should be called once every frame
        //to update the  time the player has spent in the level and if applicable increase the level and
        //the speed of the fish
        time_in_level += Time.deltaTime;
        if (time_in_level > level_time)
        {
            //first reset time in level to 0
            time_in_level = 0;
            //then we need to increase the move_speed of the fish
            foreach (AngryFish fish in angry_fish_list)
            {
                fish.MoveSpeed = fish.MoveSpeed * 1.1f; //increase fish speed by 10%
            }
            //finally we need to increase the level indicator in the UI.
            level_indicator_text.text = "Level: " + ++level;

            //reset the octopus since the level starts with none
            for (int i = 0; i < octopus_list.Length; i++)
            {
                Destroy(octopus_list[i].Oct);
                octopus_list[i] = new Octopus(level_time);
            }
        }
    }
Пример #4
0
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoHormiga Update(Hormiga h)
    {
        //Si el objetivo esta muerto vamos al estado de muerte, ya que la hormiga ya ha comenzado su ataque suicida aunque no haga daño a ningun enemigo
        if (target == null)
        {
            return(h.eMuerta);
        }

        //Comprobamos que tipo de enemigo es para hacerle daño correctamente
        if (target.gameObject.CompareTag("Gallina"))
        {
            Gallina g = target.gameObject.GetComponent <Gallina>();
            g.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("Pulpo"))
        {
            Octopus o = target.gameObject.GetComponent <Octopus>();
            o.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("TRex"))
        {
            TRex t = target.gameObject.GetComponent <TRex>();
            t.GetHit(h.fuerza);
        }

        return(h.eMuerta);
    }
Пример #5
0
        public static void WaterAnimals()
        {
            Console.WriteLine("");
            Console.WriteLine("Dino-Shark I am!");
            DinoShark dinoShark = new DinoShark();

            Console.WriteLine($"Scales: {dinoShark.Scales}.");
            Console.WriteLine($"Packs: {dinoShark.Packs}.");
            Console.WriteLine($"Location: {dinoShark.Location}.");
            Console.WriteLine($"Eyes: {dinoShark.Eyes}.");
            Console.WriteLine($"Feeding Cost:${dinoShark.FeedCost}.");
            Console.WriteLine($"Are they safe: {dinoShark.Safe}.");
            Console.WriteLine($"Eat: {dinoShark.Eat()}.");
            Console.WriteLine($"How many eggs laid a year: {dinoShark.EggsPerYear()}.");


            Console.WriteLine("");
            Console.WriteLine("Octopus I am!");
            Octopus octopus = new Octopus();

            Console.WriteLine($"Scales: {octopus.Scales}.");
            Console.WriteLine($"Packs: {octopus.Packs}.");
            Console.WriteLine($"Location: {octopus.Location}.");
            Console.WriteLine($"Eyes: {octopus.Eyes}.");
            Console.WriteLine($"Feeding Cost:${octopus.FeedCost}.");
            Console.WriteLine($"Are they safe: {octopus.Safe}.");
            Console.WriteLine($"Eat: {octopus.Eat()}.");
            Console.WriteLine($"How many eggs laid a year: {octopus.EggsPerYear()}.");
            Console.WriteLine($"Smarts: {octopus.Smart()}.");

            Console.WriteLine("");
            Console.WriteLine("Orca I am!");
            Orca orca = new Orca();

            Console.WriteLine("");
            Console.WriteLine($"Tails: {orca.Tail}.");
            Console.WriteLine($"Packs: {orca.Packs}.");
            Console.WriteLine($"Location: {orca.Location}.");
            Console.WriteLine($"Eyes: {orca.Eyes}.");
            Console.WriteLine($"Feeding Cost:${orca.FeedCost}.");
            Console.WriteLine($"Are they safe: {orca.Safe}.");
            Console.WriteLine($"Eat: {orca.Eat()}.");
            Console.WriteLine($"How many does it give birth per year: {orca.GiveBirth()}.");

            //Interface here as Well
            Console.WriteLine("Dino-Otter I am!");
            DinoOtter dinoOtter = new DinoOtter();

            Console.WriteLine($"Tails: {dinoOtter.Tail}.");
            Console.WriteLine($"Packs: {dinoOtter.Packs}.");
            Console.WriteLine($"Location: {dinoOtter.Location}.");
            Console.WriteLine($"Eyes: {dinoOtter.Eyes}.");
            Console.WriteLine($"Feeding Cost:${dinoOtter.FeedCost}.");
            Console.WriteLine($"Are they safe: {dinoOtter.Safe}.");
            Console.WriteLine($"Eat: {dinoOtter.Eat()}.");
            Console.WriteLine($"How many does it give birth per year: {dinoOtter.GiveBirth()}.");
            Console.WriteLine($"Interface => Fun Tricks: {dinoOtter.FunTricks}.");
            Console.WriteLine($"Interface => Loves Humans: {dinoOtter.Splash()}.");
            Console.ReadLine();
        }
Пример #6
0
    //public void Shoot()
    //{
    //    GetComponent<Animator>().SetBool("shoot", true);
    //    Instantiate(bullet, firepoint.position, firepoint.rotation);
    //}
    public void Shoot()
    {
        RaycastHit2D hitinfo = Physics2D.Raycast(firepoint.position, firepoint.right);

        if (hitinfo)
        {
            Enemy   enemy   = hitinfo.transform.GetComponent <Enemy>();
            Octopus octopus = hitinfo.transform.GetComponent <Octopus>();
            if (enemy != null)
            {
                enemy.Takedamage(damage);
            }
            else if (octopus != null)
            {
                octopus.Takedamage(damage);
            }
            else if (hitinfo.transform.gameObject.tag == "pickups")
            {
                hitinfo.transform.gameObject.GetComponent <Pickup>().destroystone(damage);
                //Debug.Log(status);
            }
            Instantiate(shootani, hitinfo.point, Quaternion.identity);//Quaternion.identity:fancy way of showing no rotation
        }

        GetComponent <Animator>().SetBool("shoot", true);
        line.SetPosition(0, firepoint.position);
        line.SetPosition(1, hitinfo.point);
        line.enabled = true;
    }
Пример #7
0
        public IActionResult ShowOctopus(int id)
        {
            Octopus thisOctopus = dbContext.Octopi
                                  .Include(o => o.Tentacles)
                                  .FirstOrDefault(oct => oct.OctopusId == id);

            return(View(thisOctopus));
        }
Пример #8
0
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoGallina Update(Gallina g)
    {
        if (Time.time - time > 1)
        {
            time = Time.time;

            //Si el objetivo esta muerto volvemos a buscar
            if (target == null)
            {
                return(g.eBuscar);
            }

            //Comprobamos que tipo de enemigo es para hacerle daño correctamente
            if (target.gameObject.CompareTag("Hormiga"))
            {
                Hormiga h = target.gameObject.GetComponent <Hormiga>();
                if (h == null)
                {
                    HormigaReina hr = target.gameObject.GetComponent <HormigaReina>();
                    hr.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
                }
                else
                {
                    h.GetHit();
                }
            }

            if (target.gameObject.CompareTag("Pulpo"))
            {
                Octopus o = target.gameObject.GetComponent <Octopus>();
                o.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            if (target.gameObject.CompareTag("TRex"))
            {
                TRex t = target.gameObject.GetComponent <TRex>();
                t.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            //Cada ataque reduce un poco la fuerza de la gallina
            if (g.fuerza > 10)
            {
                g.fuerza -= 1;
            }

            //Si el ataque acabo con su objetivo, la gallina se lo come para restaurar sus estadisticas
            if (target == null)
            {
                g.vida      = g.vidaInicial;
                g.fuerza    = g.fuerzaInicial;
                g.velocidad = g.velocidadInicial;
                g.berserk   = false;
            }
        }

        return(g.eAtacar);
    }
Пример #9
0
 void Start()
 {
     for (int i = 0; i < Settings.numPulpos; i++)
     {
         Octopus o = Instantiate(octopusPrefab).GetComponent <Octopus>();
         o.transform.parent   = transform;
         o.transform.position = transform.position;
         o.waterTerrain       = lago;
     }
 }
Пример #10
0
        private static void PowerUpNearbyOctopii(Octopus octopus, List <Octopus> octopii)
        {
            List <Octopus> nearbyOctopii = octopii.Where(o => o.X >= octopus.X - 1 && o.X <= octopus.X + 1 &&
                                                         o.Y >= octopus.Y - 1 && o.Y <= octopus.Y + 1 &&
                                                         !o.Flashed &&
                                                         $"{o.X},{o.Y}" != $"{octopus.X},{octopus.Y}")
                                           .ToList();

            nearbyOctopii.ForEach(nearby => nearby.Power += 1);
        }
    IEnumerator CorBornOctopus()
    {
        while (octopusModum.Count < maxOctopus)
        {
            Octopus temp = Instantiate(octopusPrefab, transform.position, Quaternion.identity, transform);
            temp.gameObject.SetActive(false);
            octopusModum.Add(temp);

            yield return(new WaitForFixedUpdate());
        }
    }
Пример #12
0
        public FoodTaskTracker(Octopus parent, FoodTaskDef taskDef)
            : base(taskDef)
        {
            this.parent  = parent;
            parent.Mouth = new Mouth(taskDef.Mouth);

            initialFood = new HashSet <Food>();
            initialFood.UnionWith(taskDef.Food.Select(f => new Food(f)));

            parent.Food.UnionWith(initialFood);
        }
Пример #13
0
 public PointTaskTracker(Octopus parent, PointTaskDef def)
 {
     env             = parent;
     terminated      = false;
     terminalReward  = def.Reward;
     minTargetRadius = def.MinTargetRadius;
     maxTargetRadius = def.MaxTargetRadius;
     sampler         = new Random();
     env.Targets     = new Target[] { new Target(10, 0, terminalReward) };
     Reset();
 }
Пример #14
0
 public Octipodes(int[][] energyReadings)
 {
     octopuses = new Octopus[10][];
     for (var y = 0; y < 10; y++)
     {
         octopuses[y] = new Octopus[10];
         for (var x = 0; x < 10; x++)
         {
             octopuses[y][x] = new Octopus(this, x, y, energyReadings[y][x]);
         }
     }
 }
Пример #15
0
 public IStatesOctopus Update(Octopus o)
 {
     //Va hacia el agua.
     o.agent.destination = o.waterTerrain.position;
     if (o.water)
     {
         return(o.wanderState);
     }
     else
     {
         return(o.runState);
     }
 }
Пример #16
0
 public IActionResult SaveOctopus(Octopus oct)
 {
     if (ModelState.IsValid)
     {
         _context.Add(oct);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("NewOctopus"));
     }
 }
Пример #17
0
        private void button1AddMullusk_Click(object sender, EventArgs e)
        {
            string molluskType;


            string name     = textBox1Name.Text;
            int    sizeInCm = int.Parse(textBox2Size.Text);
            int    minTemp  = int.Parse(textBox3MinTemp.Text);
            int    maxTemp  = int.Parse(textBox4MaxTemp.Text);
            string color    = textBox5Color.Text;



            if (radioButton3Starfish.Checked)
            {
                molluskType = radioButton3Starfish.Text;

                starFish = new Starfish();
                aquarium.AllAnimalsCollection.Add(starFish);
                aquarium.MolluskCollection.Add(starFish);
                starFish.Img        = FishGUI.Properties.Resources.starfish_icon;
                starFish.XPossition = locationGenerator.Next(Аquarium.xMinValue + 100, Аquarium.xMaxValue);
                starFish.YPossition = locationGenerator.Next(Аquarium.yMaxValue - 20, Аquarium.yMaxValue);
            }
            if (radioButton1Octopus.Checked)
            {
                molluskType = radioButton1Octopus.Text;

                octopus            = new Octopus();
                octopus.AnimalName = name;
                aquarium.AllAnimalsCollection.Add(octopus);
                aquarium.MolluskCollection.Add(octopus);
                octopus.Img        = FishGUI.Properties.Resources.octopus_icon;
                octopus.XPossition = locationGenerator.Next(Аquarium.xMinValue + 300, Аquarium.xMaxValue);
                octopus.YPossition = locationGenerator.Next(Аquarium.yMaxValue - 200, Аquarium.yMaxValue);
            }
            if (radioButton2Snail.Checked)
            {
                molluskType = radioButton2Snail.Text;

                snail = new Snail();
                aquarium.AllAnimalsCollection.Add(snail);
                aquarium.MolluskCollection.Add(snail);
                snail.Img        = FishGUI.Properties.Resources.Snail_icon;
                snail.XPossition = locationGenerator.Next(Аquarium.xMinValue + 500, Аquarium.xMaxValue);
                snail.YPossition = locationGenerator.Next(Аquarium.yMaxValue - 400, Аquarium.yMaxValue);
            }


            this.DialogResult = DialogResult.OK;
        }
        public OctopusEnergyMeter(string[] lines)
        {
            OctopusGrid = new Octopus[KGrid, KGrid];

            for (int y = 0; y < KGrid; y++)
            {
                var chs = lines[y].ToCharArray();
                for (int x = 0; x < KGrid; x++)
                {
                    OctopusGrid[x, y] = new Octopus(x, y, (int)(chs[x] - '0'), OctopusGrid);
                }
            }
            TotalFlashes = 0;
            Synchronized = int.MaxValue;
        }
Пример #19
0
    public IStatesOctopus Update(Octopus o)
    {
        //Si está en agua, va el doble de rápido.
        if (o.water)
        {
            o.agent.speed = speed * 2;
        }
        else
        {
            o.agent.speed = speed;
        }

        //Nuevo destino aleatorio.
        o.agent.destination = o.transform.position + new Vector3((Random.value - 0.5f) * 80, (Random.value - 0.5f) * 80, (Random.value - 0.5f) * 80);
        return(o.wanderState);
    }
Пример #20
0
        public override void LoadContent()
        {
            base.LoadContent();

            octopus = new Octopus(CoordinateTransfor((int)cStart.X, (int)cStart.Y) - new Vector2(7.5f, 9.1f),
                                  CoordinateTransfor(1, 1) - new Vector2(7.5f, 9.1f));

            buttonFindRoad = new Button(TextureManager.GetTexture2D(ETexture2D.HelpButton), 4, 1, 4, 30,
                                        "Help", false, new Vector2(360, 15));

            buttonNextLevel = new ConvertButton(TextureManager.GetTexture2D(ETexture2D.Button), 4, 1, 4, 30,
                                                "Next Level", false, ScreenManager, this, new MainGame(idLevel + 1), new Vector2(580, 550));

            buttonBack = new ConvertButton(TextureManager.GetTexture2D(ETexture2D.Button), 4, 1, 4, 30,
                                           "Back", false, ScreenManager, this, new LevelMenu(), new Vector2(20, 550));

            buttonBeanSearch = new Button(TextureManager.GetTexture2D(ETexture2D.Button), 4, 1, 4, 30,
                                          "HillClimbing", false, new Vector2(540, 15));
        }
Пример #21
0
    //private void OnTriggerEnter2D(Collider2D collision)
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Enemy   enemy   = collision.transform.GetComponent <Enemy>();
        Octopus octopus = collision.transform.GetComponent <Octopus>();

        if (enemy != null)
        {
            enemy.Takedamage(damage);
        }
        else if (octopus != null)
        {
            octopus.Takedamage(damage);
        }
        else if (collision.gameObject.tag == "pickup")
        {
            collision.transform.gameObject.GetComponent <Pickup>().destroystone(damage);
        }
        Instantiate(shootani, transform.position, transform.rotation);
        Destroy(gameObject);
    }
Пример #22
0
    public Robot RandomRobot()
    {
        Robot _TestRobot;

        if (SplashKit.Rnd() < 0.5)
        {
            _TestRobot = new Boxy(_GameWindow, _Player);
        }
        else
        {
            if (SplashKit.Rnd() < 0.5)
            {
                _TestRobot = new Roundy(_GameWindow, _Player);
            }
            else
            {
                _TestRobot = new Octopus(_GameWindow, _Player);
            }
        }
        return(_TestRobot);
    }
Пример #23
0
        private static List <Octopus> ParseOctopii(string[] inputs)
        {
            List <Octopus> octopii = new List <Octopus>();

            for (int y = 0; y < inputs.Length; y++)
            {
                for (int x = 0; x < inputs[y].Length; x++)
                {
                    Octopus octopus = new Octopus
                    {
                        X       = x,
                        Y       = y,
                        Flashed = false,
                        Power   = int.Parse(inputs[y][x].ToString())
                    };

                    octopii.Add(octopus);
                }
            }

            return(octopii);
        }
Пример #24
0
    public static void Main()
    {
        Octopus o = new Octopus();

        if (o.isHungry())
        {
            Console.WriteLine("The octopus is hungry!\n");
        }
        else
        {
            Console.WriteLine("The octopus isn't hungry!\n");
        }

        o.Digest(75);
        Console.WriteLine("The octopus is {0}% hungry", o.HungerPercent);
        Console.WriteLine("Feeding the octopus with an int...");
        o.Eat(10);
        Console.WriteLine("The octopus is {0}% hungry", o.HungerPercent);
        Console.WriteLine("Feeding the octopus with a string...");
        o.Eat("10");
        Console.WriteLine("The octopus is {0}% hungry", o.HungerPercent);
    }
    public static void Main()
    {
        Octopus o = new Octopus();

        o.name = "Fred";

        Console.WriteLine("The octopus {0} hungry!\n", o.isHungry() ? "is" : "isn't");

        Console.WriteLine("Digesting 75 food!");
        o.Digest(75);
        Console.WriteLine("The octopus is {0}% hungry\n", o.HungerPercent);

        Console.WriteLine("Feeding the octopus with an int...");
        o.Eat(10);
        Console.WriteLine("The octopus is {0}% hungry\n", o.HungerPercent);

        Console.WriteLine("Feeding the octopus with a string...");
        o.Eat("10");
        Console.WriteLine("The octopus is {0}% hungry\n", o.HungerPercent);

        Console.WriteLine("The octopus is named: {0}", o.name);
        Console.WriteLine("The octopus is age: {0}", o.age);
        Console.WriteLine("The octopus has {0} legs and {1} eyes!", Octopus.legs, Octopus.eyes);
    }
Пример #26
0
 /// <summary>
 ///  Spawns the Octopus at the given Position
 /// </summary>
 public void SpawnOctopus(Vector2 position)
 {
     Octopus = new Octopus(position);
     mAllShipList.Add(Octopus);
 }
Пример #27
0
    public IStatesTRex Update(TRex t)
    {
        //Si el enemigo desaparece, el TRex vaga.
        if (t.enemy == null)
        {
            return(t.wanderState);
        }

        t.agent.speed = attackSpeed;
        force         = Settings.tamTrex * 20;

        //Si no hay colisión, sigue persiguiendo.
        if (!colision)
        {
            t.agent.isStopped = false;
            if (t.enemy == null)
            {
                return(t.wanderState);
            }
            else
            {
                t.agent.destination = t.enemy.transform.position;
                return(t.attackState);
            }

            //Si hay colisión, ataca.
        }
        else
        {
            colision = false;

            if (Time.time - time > 1f)
            {
                time = Time.time;

                //Se para.
                t.agent.isStopped = true;

                //Si es un pulpo, ataca hasta morir o matar, si lo mata puede comer.
                if (t.enemy.gameObject.CompareTag("Pulpo"))
                {
                    Octopus rival = t.enemy.GetComponent <Octopus>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }

                    //Si es una hormiga, ataca hasta matar o morir.
                }
                else if (t.enemy.gameObject.CompareTag("Hormiga"))
                {
                    Hormiga rival = t.enemy.GetComponent <Hormiga>();
                    if (rival == null)
                    {
                        HormigaReina rivalHR = t.enemy.GetComponent <HormigaReina>();
                        rivalHR.GetHit((int)force);
                    }
                    else
                    {
                        rival.GetHit();
                    }

                    //Si es una gallina, ataca hasta morir o matar, si lo mata puede comer.
                }
                else if (t.enemy.gameObject.CompareTag("Gallina"))
                {
                    Gallina rival = t.enemy.GetComponent <Gallina>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }
                }
            }
        }

        return(t.attackState);
    }
Пример #28
0
        public Hyades(InputDevice input)
        {
            this.input = input;
            instance   = this;

            background_music          = Resources.background_music.CreateInstance();
            background_music.IsLooped = true;
            background_music.Play();


            player            = new Player(input);
            player.position.Z = 2.0f;

            camera        = new FirstPersonCamera(player);
            camera.width  = Application.WIDTH;
            camera.height = Application.HEIGHT;
            camera.near   = 0.1f;
            camera.far    = 500;
            camera.fov    = 1.1f;

            level = new Level();
            level.Load();

            Skybox skybox = new Skybox(player);

            level.Add(skybox);

            StaticModelEntity birthstone = new StaticModelEntity(Resources.rock_model);

            birthstone.position   = Vector3.Zero;
            birthstone.rotation.X = 1.11592329f;
            birthstone.rotation.Y = 0.188416481f;
            birthstone.rotation.Z = 1.31485772f;
            birthstone.size       = new Vector3(0.0006f);
            AmbientEntityBubblesLogic birthstone_logic = new AmbientEntityBubblesLogic(birthstone, 80, 10);

            level.Add(birthstone);


            for (int i = 0; i < 10; i++)
            {
                Bubble bubble = new Bubble(0.03f + (float)rand.NextDouble() * 0.02f);
                bubble.SetPosition(new Vector2(-50000, 0));
                bubble.SetVelocity(new Vector2(0, -1.0f));
                level.Add(bubble);
            }

            Enemy enemy;

            for (int i = 0; i < 2; i++)
            {
                enemy = new Fish();
                // enemy.size *= 0.1f;
                enemy.size *= (((float)rand.NextDouble())) * 0.06f + 0.05f;
                // enemy.size.Z *= 0.2f;
                //enemy.position.Z = (((float)rand.NextDouble()) -0.5f)*2;
                enemy.SetPosition(new Vector2(-50000, 0));
                level.Add(enemy);
            }

            for (int i = 0; i < 1; i++)
            {
                enemy       = new Octopus();
                enemy.size *= 0.1f;
                enemy.SetPosition(new Vector2(-50000, -10));
                level.Add(enemy);
            }

            character = new Character(player, input);
            character.SetPosition(new Vector2(0, 0));
            level.Add(character);
            Enemy.player = character;

            particlemanager = ParticleManager.GetInstance();

            AmbientParticleLogic ambient_logic = new AmbientParticleLogic(character, 10);

            for (int i = 0; i < 400; i++)
            {
                ambient_logic.Emit();
            }

            AmbientCircleParticleLogic ambient_circle_logic = new AmbientCircleParticleLogic(character, 20);

            for (int i = 0; i < 10; i++)
            {
                ambient_circle_logic.Emit();
            }

            WormParticleLogic worm_logic = new WormParticleLogic(character, 10);

            for (int i = 0; i < 20; i++)
            {
                worm_logic.Emit();
            }

            Update(0);
        }
Пример #29
0
 public TargetTaskTracker(Octopus parent, TargetTaskDef def)
     : base(def)
 {
     Parent           = parent;
     objectiveTracker = MakeObjectiveTracker(def.Objective);
 }
Пример #30
0
        /// <summary>
        ///  Check for possible actions for the Fleets and single Ships controled by the AI.
        /// </summary>
        public void Update(GameTime gameTime, QuadTree quadTree)
        {
            //FisherShips
            var counter = mAiFisherShipList.Count;

            for (var i = 0; i < counter; i++)
            {
                var fShip = mAiFisherShipList[i];
                if (!fShip.Moving)
                {
                    if (mFishingMovingDelay <= 0)
                    {
                        var randomNumber = new Random();
                        //moving to a random position in the Map
                        var x = randomNumber.Next(0, 5760);
                        var y = randomNumber.Next(0, 5760);
                        fShip.Move(PathFinder.CalculatePath(fShip.Position, new Vector2(x, y), false));
                        mFishingMovingDelay = 8;
                    }
                    else
                    {
                        mFishingMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }
                if (!fShip.Owned && fShip.Hp > 0)
                {
                    continue;
                }
                mAiFisherShipList.RemoveAt(i);
                counter--;
                fShip.HealthBar = null;
                fShip.CrewBar   = null;
                if (fShip.Owned
                    )
                {
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                }
            }

            //TradingShips
            counter = mAiTradingShipList.Count;
            for (var i = 0; i < counter; i++)
            {
                var tShip = mAiTradingShipList[i];
                if (!tShip.Moving)
                {
                    if (mTradingMovingDelay <= 0)
                    {
                        var randomNumber = new Random();
                        var number       = randomNumber.Next(0, IslandManager.IslandCount);
                        var destination  = new Vector2(IslandManager.Islands[IslandManager.mIslandNames[number]].X + randomNumber.Next(20, 50),
                                                       IslandManager.Islands[IslandManager.mIslandNames[number]].Y + randomNumber.Next(20, 50));
                        if (Vector2.Distance(destination, tShip.Position) > 100 &&
                            Game1.mMapScreen.mGridMap.GetCell(destination).IsWalkable &&
                            !Game1.mMapScreen.mGridMap.GetCell(destination).Occupied)
                        {
                            tShip.Move(PathFinder.CalculatePath(tShip.Position, destination, false));
                            mTradingMovingDelay = 5;
                        }
                    }
                    else
                    {
                        mTradingMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }

                if (tShip.Hp < tShip.MaxHp) //shoot back
                {
                    if (!mDefendingShipList.Contains(tShip))
                    {
                        tShip.Defend(tShip.ShipPath);
                        mDefendingShipList.Add(tShip);
                    }
                    if (tShip.Hp <= 40) //fleeing
                    {
                        tShip.TargetShip = null;
                        tShip.Move(tShip.ShipPath);
                        tShip.CurrentBState = TradingShip.ShipBattleState.Idle;
                        mDefendingShipList.Remove(tShip);
                    }
                }

                if (!tShip.Owned && tShip.Hp > 0)
                {
                    continue;
                }
                mAiTradingShipList.RemoveAt(i);
                counter--;
                if (tShip.Owned)
                {
                    tShip.CrewBar   = null;
                    tShip.HealthBar = null;
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                    var random = new Random();
                    if (random.Next(0, 4) == 1)// 25% dropchance
                    {
                        RessourceManager.AddRessource("mapParts", 1);
                    }
                }
            }


            //BattleShips
            counter = mAiBattleShipsList.Count;
            for (var i = 0; i < counter; i++)
            {
                var bShip = mAiBattleShipsList[i];
                if (bShip.CurrentBState == BattleShip.ShipBattleState.Idle)
                {
                    if (!bShip.Moving)
                    {
                        if (mBattleMovingDelay <= 0)
                        {
                            //moving to a random position in the Map
                            var randomNumber = new Random();
                            var x            = randomNumber.Next(0, 5760);
                            var y            = randomNumber.Next(0, 5760);
                            bShip.Move(PathFinder.CalculatePath(bShip.Position, new Vector2(x, y), false));
                            mBattleMovingDelay = 3;
                        }
                        else
                        {
                            mBattleMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }

                    //scan for possible enemies in reach and attack them if they aren't to powefull
                    var possibleCollisions = new List <AShip>();
                    var enemyShipsCount    = 0;
                    quadTree.Retrieve(possibleCollisions, bShip);
                    if (possibleCollisions.Count > 0)
                    {
                        AShip nearestShip = null;
                        for (var index = 0; index < possibleCollisions.Count; index++)
                        {
                            var rangeCircle = new CircleF(bShip.Position, 500f); //scan radius
                            if (rangeCircle.Contains(possibleCollisions[index].Position) &&
                                possibleCollisions[index].Owned && possibleCollisions[index].Hp >= 0)
                            {
                                if (nearestShip == null)
                                {
                                    nearestShip = possibleCollisions[index];
                                }
                                enemyShipsCount++;
                                //save the nearest Ship
                                if (Vector2.Distance(bShip.Position, possibleCollisions[index].Position) <
                                    Vector2.Distance(bShip.Position, nearestShip.Position))
                                {
                                    nearestShip = possibleCollisions[index];
                                }
                            }
                        }
                        //only attack up to 3 ships
                        if (enemyShipsCount > 0 && enemyShipsCount <= 3 && nearestShip != null)
                        {
                            var random = new Random();
                            var number = random.Next(0, 2);
                            if ((number == 1) && nearestShip.EnterAttackValue - 8 < bShip.EnterAttackValue)
                            {
                                bShip.Move(PathFinder.CalculatePath(bShip.Position, nearestShip.Position, false));
                                bShip.Enter(nearestShip);
                                mEnteringShipList.Add(bShip);
                            }
                            else
                            {
                                bShip.Move(PathFinder.CalculatePath(bShip.Position, nearestShip.Position, false));
                                bShip.Attack(nearestShip);
                                mAttackingShipList.Add(bShip);
                            }
                        }
                        else if (enemyShipsCount > 3)
                        {
                            bShip.CurrentBState = BattleShip.ShipBattleState.Defending;
                            mDefendingShipList.Add(bShip);
                        }
                    }
                }

                if (!bShip.Owned && bShip.Hp > 0)
                {
                    continue;
                }
                mAiBattleShipsList.RemoveAt(i);
                counter--;
                bShip.CrewBar   = null;
                bShip.HealthBar = null;
                if (!Game1.mMapScreen.mTechDemo && bShip.Owned)
                {
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                    var random = new Random();
                    if (random.Next(0, 3) == 1)// 33% dropchance
                    {
                        RessourceManager.AddRessource("mapParts", 1);
                    }
                }
            }

            //Fleets
            counter = mAiFleetList.Count;
            for (var t = 0; t < counter; t++)
            {
                var fleet = mAiFleetList[t];
                //check if the ships are still in the fleet
                var bCounter = fleet.BattleShips.Count;
                for (var i = 0; i < bCounter; i++)
                {
                    if (!(fleet.BattleShips[i].Hp <= 0) && !fleet.BattleShips[i].Owned)
                    {
                        continue;
                    }
                    fleet.BattleShips.RemoveAt(i);
                    bCounter--;
                }
                var tCounter = fleet.TradingShips.Count;
                for (var i = 0; i < tCounter; i++)
                {
                    if (!(fleet.TradingShips[i].Hp <= 0) && !fleet.TradingShips[i].Owned)
                    {
                        continue;
                    }
                    fleet.TradingShips.RemoveAt(i);
                    tCounter--;
                }

                //ceck if fleets are whiped out
                if (fleet.FleetCount() <= 0)
                {
                    mAiFleetList.Remove(fleet);
                    counter--;
                }


                if (!fleet.InBattle)
                {
                    //search for enemies when not in Battle
                    var possibleCollisions = new List <AShip>();
                    var toAttack           = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, fleet.FlagShip);
                    //check if the ships are enemies and in range
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        var rangeCircle = new CircleF(fleet.FlagShip.Position, 600f); //scan radius
                        if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            toAttack.Add(potentialEnemyShip);
                        }
                    }
                    //if there are any enemies, attack them
                    if (toAttack.Count > 0)
                    {
                        fleet.Attack(toAttack);
                    }

                    //random movement. Determines with the Flagship if the fleet is moving.
                    if (!fleet.FlagShip.Moving && !fleet.Defending)
                    {
                        if (mBattleMovingDelay <= 0)
                        {
                            //moving to a random position in the Map
                            var randomNumber = new Random();
                            var x            = randomNumber.Next(0, 5760);
                            var y            = randomNumber.Next(0, 5760);
                            fleet.Move(new Vector2(x, y));
                            mBattleMovingDelay = 3;
                        }
                        else
                        {
                            mBattleMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }
                }
                else//when in battle
                {
                    //check if own ships were entered
                    for (int i = 0; i < fleet.BattleShips.Count; i++)
                    {
                        if (fleet.BattleShips[i].Owned)
                        {
                            fleet.MarkedShips.Add(fleet.BattleShips[i]);
                            fleet.BattleShips.RemoveAt(i);
                        }
                    }
                    //check if own ships were entered
                    for (int i = 0; i < fleet.TradingShips.Count; i++)
                    {
                        if (fleet.TradingShips[i].Owned)
                        {
                            fleet.MarkedShips.Add(fleet.TradingShips[i]);
                            fleet.TradingShips.RemoveAt(i);
                        }
                    }


                    //check if the marked ships still exist and the distance
                    var kCounter = fleet.MarkedShips.Count;
                    for (var i = 0; i < kCounter; i++)
                    {
                        if (fleet.MarkedShips[i].Hp <= 0 || !fleet.MarkedShips[i].Owned || Vector2.Distance(fleet.MarkedShips[i].Position, fleet.FlagShip.Position) > 600)
                        {
                            fleet.MarkedShips.RemoveAt(i);
                            kCounter--;
                            i--;
                        }
                    }

                    fleet.UpdateBattle();
                    //check for enemies
                    var possibleCollisions = new List <AShip>();
                    var toAttack           = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, fleet.FlagShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(fleet.FlagShip.Position, 700f); //scan radius
                        if (!fleet.MarkedShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            toAttack.Add(potentialEnemyShip);
                        }
                    }
                    if (toAttack.Count > 0)
                    {
                        fleet.MarkedShips.AddRange(toAttack);
                    }


                    //if there is no enemy left, the fleet will stop battling
                    if (fleet.MarkedShips.Count <= 0)
                    {
                        fleet.InBattle = false;
                        fleet.StopBattle();
                    }
                }
            }

            //GhostShip
            if (GhostShip != null)
            {
                if (GhostShip.CurrentBState == GhostShip.ShipBattleState.Idle)
                {
                    //check if there are any enemyShips nearby
                    var enemyShips         = new List <AShip>();
                    var possibleCollisions = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, GhostShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(GhostShip.Position, 600f); //scan radius
                        if (!GhostShip.TargetShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            enemyShips.Add(potentialEnemyShip);
                        }
                    }
                    if (enemyShips.Count > 0)
                    {
                        GhostShip.Attack(enemyShips);
                    }
                    //move to the island if not already next to it.
                    if (Vector2.Distance(GhostShip.Position, GhostShip.TreasureIslandPosition) >= 200 && !GhostShip.Moving)
                    {
                        GhostShip.Move(PathFinder.CalculatePath(GhostShip.Position, GhostShip.TreasureIslandPosition, true));
                    }
                }
                else if (GhostShip.CurrentBState == GhostShip.ShipBattleState.Attacking)
                {
                    GhostShip.Update(gameTime);
                    //check if there are any new enemyShips nearby
                    var possibleCollisions = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, GhostShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(GhostShip.Position, 600f); //scan radius
                        if (!GhostShip.TargetShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            GhostShip.TargetShips.Add(potentialEnemyShip);
                        }
                    }

                    //moving
                    mGhostMovementDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (mGhostMovementDelay <= 0 && GhostShip.NearestTarget != null)
                    {
                        Vector2 movementTarget;
                        if (Vector2.Distance(GhostShip.NearestTarget.Position, GhostShip.Position) <= 120)
                        {
                            if (GhostShip.MoveRight)
                            {
                                movementTarget = GhostShip.Position +
                                                 (Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position).PerpendicularCounterClockwise() * 100f);
                                GhostShip.MoveRight = false;
                            }
                            else
                            {
                                movementTarget = GhostShip.Position +
                                                 (Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position).PerpendicularClockwise() * 100f);
                                GhostShip.MoveRight = true;
                            }
                            mGhostMovementDelay = 1.5;
                        }
                        else
                        {
                            movementTarget = GhostShip.NearestTarget.Position +
                                             Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position) * 20f;
                            mGhostMovementDelay = 1;
                        }
                        GhostShip.Move(PathFinder.CalculatePath(GhostShip.Position, movementTarget, true));
                    }
                }
                if (GhostShip.Hp <= 0)
                {
                    GhostShip.DropLoot();
                    mAllShipList.Remove(GhostShip);
                    GhostShip = null;
                }
            }
            else
            {
                //spawn ships if necessary
                RespawnShips();
            }



            if (Octopus != null)
            {
                //search for enemies
                if (Octopus.CurrentBState == Octopus.ShipBattleState.Idle)
                {
                    /*
                     * var possibleCollisions = new List<AShip>();
                     * quadTree.Retrieve(possibleCollisions, Octopus);
                     * AShip nearestShip = null;
                     * foreach (var potentialEnemyShip in possibleCollisions)
                     * {
                     *  //only add ships that are new
                     *
                     *  var rangeCircle = new CircleF(Octopus.Position, 400f); //scan radius
                     *  if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                     *       potentialEnemyShip.Hp >= 0)
                     *  {
                     *      if (nearestShip == null)
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *      else if (Vector2.Distance(nearestShip.Position, Octopus.Position) > Vector2.Distance(potentialEnemyShip.Position, Octopus.Position))
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *  }
                     * }*/
                    var nearestShip = SearchClosestShip(Octopus, quadTree, 400f);//testing
                    if (nearestShip != null)
                    {
                        Octopus.Enter(nearestShip);//attack the closest enemy
                    }

                    //move back to original position
                    if (Vector2.Distance(Octopus.Position, Octopus.HousingPosition) >= 200 && !Octopus.Moving)
                    {
                        Octopus.Move(PathFinder.CalculatePath(Octopus.Position, Octopus.HousingPosition, true));
                    }
                }
                else if (Octopus.CurrentBState == Octopus.ShipBattleState.Entering)
                {
                    Octopus.Update(gameTime);
                    mOctopusChasingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (Octopus.TargetShip != null && Vector2.Distance(Octopus.Position, Octopus.TargetShip.Position) >= 70 && mOctopusChasingDelay <= 0)
                    {
                        mOctopusChasingDelay = 2;
                        Octopus.Move(PathFinder.CalculatePath(Octopus.Position, Octopus.TargetShip.Position, true));
                    }
                }
                if (Octopus.Hp <= 0)
                {
                    Octopus.DropLoot();
                    mAllShipList.Remove(Octopus);
                    Octopus = null;
                }
            }

            if (Dragon != null)
            {
                Dragon.Update(gameTime, quadTree);//special Updates for the dragon..
                Dragon.UpdateDragonMovement(gameTime);

                //check if the Dragoon is fighting or not
                if (Dragon.CurrentBState == Dragon.ShipBattleState.Idle)
                {
                    if (!Dragon.Moving)
                    {
                        //moving to a random position in the Map
                        var randomNumber = new Random();
                        var x            = randomNumber.Next(0, 5760);
                        var y            = randomNumber.Next(0, 5760);
                        Dragon.MoveDragon(new Vector2(x, y));
                    }

                    /*
                     * var possibleCollisions = new List<AShip>();
                     * quadTree.Retrieve(possibleCollisions, Dragon);
                     * AShip nearestShip = null;
                     * foreach (var potentialEnemyShip in possibleCollisions)
                     * {
                     *  //only add ships that are new
                     *  var rangeCircle = new CircleF(Octopus.Position, 200f); //scan radius
                     *  if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                     *       potentialEnemyShip.Hp >= 0)
                     *  {
                     *      if (nearestShip == null)
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *      else if (Vector2.Distance(nearestShip.Position, Octopus.Position) > Vector2.Distance(potentialEnemyShip.Position, Octopus.Position))
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *  }
                     * }*/
                    var nearestShip = SearchClosestShip(Dragon, quadTree, 200f);
                    if (nearestShip != null)
                    {
                        Dragon.Attack(nearestShip); //attack the closest enemy
                    }
                }
                else if (Dragon.CurrentBState == Dragon.ShipBattleState.Attacking)
                {
                    //Chasing
                    if (Dragon.TargetShip != null && Vector2.Distance(Dragon.Position, Dragon.TargetShip.Position) >= 70)
                    {
                        Dragon.MoveDragon(Dragon.TargetShip.Position);
                    }
                }


                if (Dragon.Hp <= 0)
                {
                    Dragon.DropLoot();
                    mAllShipList.Remove(Dragon);
                    Dragon = null;
                }
            }
        }