public FlyingBehavior(GameWorld world, GameActor actor, AnimalActor carry)
     : base(world, actor)
 {
     sprite     = (FlyingSprite)actor;
     this.carry = carry;
     if (sprite.plannedPath != null)
     {
         path = sprite.plannedPath.GetEnumerator();
         path.MoveNext();
         sprite.to = new Vector2(path.Current.x, path.Current.y);
     }
 }
Пример #2
0
        public void expandUnits()
        {
            IEnumerator <AnimalActor> enu = storage.GetEnumerator();
            Tile current            = world.getTileAt(units.First.Value.position);
            LinkedList <Tile> tiles = new LinkedList <Tile>();

            tiles.AddFirst(current);
            AnimalActor currentActor = null;

            while (tiles.Count != 0 && (currentActor != null || enu.MoveNext()))
            {
                if (currentActor == null)
                {
                    currentActor = enu.Current;
                }
                current = tiles.First.Value;
                tiles.RemoveFirst();

                IEnumerator <Tile> tileEnu = current.adjacent.GetEnumerator();
                while (tileEnu.MoveNext())
                {
                    if (tileEnu.Current != null)
                    {
                        tiles.AddLast(tileEnu.Current);
                    }
                }
                AnimalActor a = world.getAnimalOnTile(current);
                if (a == null && current != null)
                {
                    enu.Current.position = new Vector2(current.x, current.y);
                    FlyingSprite sprite = new FlyingSprite(world, units.First.Value.position, new Vector2(0, 0), 1, new Vector2(1, 1), Vector2.Zero, 0, enu.Current.position, enu.Current);

                    sprite.anim = enu.Current.anim;
                    world.addActor(enu.Current);
                    enu.Current.removeMe = false;
                    enu.Current.changeTeam(team);
                    world.addActor(sprite);
                    //enu.Current.customDraw = AnimalActor.drawInvisible;
                    currentActor = null;
                }
            }
        }
Пример #3
0
        /* TODO:
         * What do these functions do?  Why do they exist?
         * It would be very helpful if whoever wrote them also wrote comments.
         */
        public void collapseUnits()
        {
            IEnumerator <AnimalActor> enu = units.GetEnumerator();

            enu.MoveNext();
            AnimalActor first = enu.Current;

            storage = new LinkedList <AnimalActor>();
            while (enu.MoveNext())
            {
                storage.AddFirst(enu.Current);
            }
            enu = storage.GetEnumerator();
            while (enu.MoveNext())
            {
                enu.Current.die();
                FlyingSprite sprite = new FlyingSprite(world, enu.Current.position, new Vector2(0, 0), 1, new Vector2(1, 1), Vector2.Zero, 0, first.position, null);
                sprite.anim = enu.Current.anim;
                world.addActor(sprite);
            }
        }
        /**
         * Attacks the target tile, if there is an actor on that tile fight it.
         */
        public Boolean attackTile(Tile target)
        {
            AnimalActor animalTarget = world.getAnimalOnTile(target);

            if (canAttackActor(animalTarget))
            {
                //If adjacent tiles contain the target tile
                if (findAttackTiles().Contains(target))
                {
                    if (this.attackRange > 1)
                    {
                        FlyingSprite sprite = new FlyingSprite(world, this.position, new Vector2(0, 0), 1, new Vector2(1, 1), Vector2.Zero, 0, new Vector2(target.x, target.y));
                        sprite.anim = new Animation(world.engine.resourceComponent, "Sprites/011_blob/");
                        world.addActor(sprite);
                        animalTarget.fight(this);
                    }
                    else if (this.movementType.Equals(animalTarget.movementType) || this.movementType.Equals(TileCost.Air))
                    {
                        List <Tile> hittingAnim = new List <Tile>();
                        hittingAnim.Add(target);
                        hittingAnim.Add(curTile);

                        FlyingSprite sprite = new FlyingSprite(world, this.position, new Vector2(0, 0), 1, new Vector2(1, 1), Vector2.Zero, 0, new Vector2(curTile.x, curTile.y), this, hittingAnim);

                        sprite.anim = this.anim;

                        world.addActor(sprite);
                        this.customDraw = AnimalActor.drawInvisible;

                        animalTarget.fight(this);
                    }

                    canAct = false;
                    return(true);
                }
            }
            return(false);
        }
        /**
         * Move to the target tile, if there is another animal there do not move there.
         */
        public Boolean moveTile(Tile target)
        {
            if (canMoveTo(target))
            {
                Tile currentTile = world.getTileAt(position);

                canMove = false;
                pathsFromCurrentTile = null;


                // Real tile index-offset= array index in move costs array.

                int offsetx = currentTile.xIndex - (moveRange);
                int offsety = currentTile.yIndex - (moveRange);

                int costX = target.xIndex - offsetx;
                int costY = target.yIndex - offsety;

                //Starting backwards from target tile, find cheapest path back to current tile using previously calculated movement cost array.

                List <Tile> movePath = new List <Tile>();
                movePath.Add(target);
                Tile currentVisit = target;
                while (currentVisit != currentTile)
                {
                    int low  = int.MaxValue;
                    int lowX = -1;
                    int lowY = -1;
                    if (costX - 1 > -1 && pathCost[costX - 1, costY] != -1)
                    {
                        low  = pathCost[costX - 1, costY];
                        lowX = costX - 1;
                        lowY = costY;
                    }
                    if (costY - 1 > -1)
                    {
                        if (pathCost[costX, costY - 1] < low && pathCost[costX, costY - 1] != -1)
                        {
                            low  = pathCost[costX, costY - 1];
                            lowX = costX;
                            lowY = costY - 1;
                        }
                    }

                    if (costX + 1 < pathCost.GetLength(0))
                    {
                        if (pathCost[costX + 1, costY] < low && pathCost[costX + 1, costY] != -1)
                        {
                            low  = pathCost[costX + 1, costY];
                            lowX = costX + 1;
                            lowY = costY;
                        }
                    }

                    if (costY + 1 < pathCost.GetLength(1))
                    {
                        if (pathCost[costX, costY + 1] < low && pathCost[costX, costY + 1] != -1)
                        {
                            low  = pathCost[costX, costY + 1];
                            lowX = costX;
                            lowY = costY + 1;
                        }
                    }
                    currentVisit = world.getTile(lowX + offsetx, lowY + offsety);

                    movePath.Add(currentVisit);
                    costX = lowX;
                    costY = lowY;
                }
                movePath.Reverse();

                FlyingSprite sprite = new FlyingSprite(world, this.position, new Vector2(0, 0), 1, new Vector2(1, 1), Vector2.Zero, 0, new Vector2(target.x, target.y), this, movePath);
                this.position = new Vector2(target.x, target.y);
                sprite.anim   = this.anim;

                world.addActor(sprite);
                this.customDraw = AnimalActor.drawInvisible;



                return(true);
            }
            return(false);
        }