private void ProduceOffspring(AnimalActor parent)
        {
            GameTile    spawnLocation = FindOpenTile(parent, (world.getTileAt(parent.position) as GameTile));
            AnimalActor offspring     = (AnimalActor)world.actorFactory.createActor(world.actorFactory.getActorId(parent.actorName), new Vector2(spawnLocation.x, spawnLocation.y));

            offspring.teamColor = parent.teamColor;
            offspring.changeTeam(parent.team);
            offspring.changeActorSprite(true);
            world.addActor(offspring);
        }
Exemple #2
0
        public override void Update()
        {
            //if (!stashed && world.collapse.isPressed)
            //{
            //	collapseUnits();
            //	stashed = true;
            //}
            //if (stashed && world.uncollapse.isPressed)
            //{
            //	expandUnits();

            //	stashed = false;

            //}
            CalculateTileFlash();
            //System.Console.WriteLine("Number of units in thing " + units.Count + " movedUnits" + movedUnits.Count +"\n");
            // End current turn if every animal has moved
            if (movedUnits.Count == currentUnitCount)
            {
                finishTurn();
                return;
            }

            if (selectedAnimalActor != null)
            {
                if (moveRange == null && selectedAnimalActor.canMove)
                {
                    moveRange = selectedAnimalActor.findPaths();
                }

                IEnumerator <Tile> adjacent = null;
                if (selectedAnimalActor.canMove)
                {
                    adjacent = moveRange.GetEnumerator();
                    while (adjacent.MoveNext())
                    {
                        if (adjacent.Current != null)
                        {
                            // Change color of ambient light on tiles
                            adjacent.Current.color = moveColor;
                        }
                    }

                    // Don't light up tile that actor is on so player can tell which unit is selected
                    world.getTileAt(selectedAnimalActor.position).color = selectedColor;
                }


                if (selectedAnimalActor.canAct && !selectedAnimalActor.canMove)
                {
                    adjacent = attackRange.GetEnumerator();
                    while (adjacent.MoveNext())
                    {
                        if (adjacent.Current != null)
                        {
                            // Change color of ambient light on tiles
                            adjacent.Current.color = atkColor;
                        }
                    }

                    // Don't light up tile that actor is on so player can tell which unit is selected
                    world.getTileAt(selectedAnimalActor.position).color = selectedColor;
                }
            }
            // Reset the move and attack color values
            else
            {
                moveColor = new Color(0, 0, 1);
                atkColor  = new Color(1, 0, 0);
            }

            // Handle end turn command
            if (enter.isPressed)
            {
                if (enterButtonReleased)
                {
                    finishTurn();
                    return;
                }
            }
            else
            {
                enterButtonReleased = true;
            }

            if (rightClick.isPressed)
            {
                // Animal has moved, return to the old position and cancel attack phase
                if (selectedAnimalActor != null)
                {
                    if (selectedAnimalActor.canMove == false)
                    {
                        selectedAnimalActor.position = selectedAnimalActor.oldPosition;
                        selectedAnimalActor.canMove  = true;
                    }

                    selectedAnimalActor.anim.ticksPerFrame *= 2;
                }
                selectedAnimalActor = null;
                moveRange           = null;
            }

            // Handle unit selection through clicks
            if (click.isPressed)
            {
                if (mouseButtonReleased)
                {
                    mouseButtonReleased = false;

                    // Get position of the mouseclick in pixels
                    Vector2 position = world.engine.graphicsComponent.camera.screen2World(world.engine.inputComponent.getMousePosition());
                    // Convert position to a multiple of 32
                    position = new Vector2(position.x - (position.x % 32), position.y - (position.y % 32));

                    Tile        clickedTile  = world.getTileAt(position);
                    AnimalActor animalOnTile = world.getAnimalOnTile(clickedTile);

                    if (selectedAnimalActor == null)
                    {
                        if (animalOnTile != null && animalOnTile.canMove == true)
                        {
                            selectedAnimalActor = animalOnTile;
                            selectedAnimalActor.anim.ticksPerFrame /= 2;
                        }
                    }

                    else if (moveRange != null && moveRange.Contains(world.getTileAt(position)) && (animalOnTile == null || animalOnTile == selectedAnimalActor) && selectedAnimalActor.canMove)
                    {
                        selectedAnimalActor.moveTile(world.getTileAt(position));

                        attackRange = selectedAnimalActor.findAttackTiles();
                        moveRange   = null;
                        //selected = null;
                    }
                    else if (!selectedAnimalActor.canMove && attackRange.Contains(world.getTileAt(position)))
                    {
                        // If an animal is on the attacked tile, attack it (don't allow an animal to attack itself)
                        if (animalOnTile != null && clickedTile != world.getTileAt(selectedAnimalActor.position))
                        {
                            selectedAnimalActor.attackTile(clickedTile);
                        }
                        // Update all of the attacking animal's variables and add to moved unit list
                        selectedAnimalActor.canAct = false;
                        movedUnits.AddFirst(selectedAnimalActor);
                        selectedAnimalActor.anim.ticksPerFrame *= 2;
                        selectedAnimalActor.changeActorSprite(true);
                        attackRange = null;
                        selectedAnimalActor.oldPosition = selectedAnimalActor.position;
                        selectedAnimalActor             = null;
                    }
                }
            }
            else
            {
                mouseButtonReleased = true;
            }

            if (world.selectLeft.isPressed && (selectedAnimalActor == null || selectedAnimalActor.canMove == true))
            {
                if (selectLeftReleased)
                {
                    currentAutoselect = (currentAutoselect + 1) % units.Count;
                    while (movedUnits.Contains(units.ElementAt(currentAutoselect)))
                    {
                        currentAutoselect = (currentAutoselect + 1) % units.Count;
                    }

                    moveRange = null;
                    if (selectedAnimalActor != null)
                    {
                        selectedAnimalActor.anim.ticksPerFrame *= 2;
                    }
                    selectedAnimalActor = units.ElementAt(currentAutoselect);
                    selectedAnimalActor.anim.ticksPerFrame /= 2;
                    selectLeftReleased = false;
                }
            }
            else
            {
                selectLeftReleased = true;
            }

            if (world.selectRight.isPressed && (selectedAnimalActor == null || selectedAnimalActor.canMove == true))
            {
                if (selectRightReleased)
                {
                    currentAutoselect = (currentAutoselect - 1);
                    if (currentAutoselect < 0)
                    {
                        currentAutoselect = units.Count - 1;
                    }
                    while (movedUnits.Contains(units.ElementAt(currentAutoselect)))
                    {
                        currentAutoselect = (currentAutoselect - 1);
                        if (currentAutoselect < 0)
                        {
                            currentAutoselect = units.Count - 1;
                        }
                    }

                    moveRange = null;
                    if (selectedAnimalActor != null)
                    {
                        selectedAnimalActor.anim.ticksPerFrame *= 2;
                    }
                    selectedAnimalActor = units.ElementAt(currentAutoselect);
                    selectedAnimalActor.anim.ticksPerFrame /= 2;
                    selectRightReleased = false;
                }
            }
            else
            {
                selectRightReleased = true;
            }
        }