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);
     }
 }
        public override Actor createActor(int id, Vector2 position, Vector2 velocity = null, double color = -1)
        {
            ResourceComponent rc = this.world.engine.resourceComponent;
            GameActor         a  = null;

            if ((position.x >= 0 && position.x < world.width * Tile.size && position.y >= 0 && position.y < world.height * Tile.size))
            {
                switch (id)
                {
                case 0:
                    a = new Rat(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 1:
                    a = new TRex(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 2:
                    a = new Turtle(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 3:
                    a = new Base(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0, team_t.Red, Color.RED);
                    return(a);

                case 4:
                    a = new Base(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0, team_t.Blue, Color.BLUE);
                    return(a);

                case 5:
                    a = new Base(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0, team_t.Yellow, (new Color(255, 255, 0)));
                    return(a);

                case 6:
                    a = new Base(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0, team_t.Purple, (new Color(255, 0, 255)));
                    return(a);

                case 8:
                    a = new Explosion(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 9:
                    a = new Robin(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 10:
                    a = new Llama(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 11:
                    a = new Blob(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);

                case 12:
                    a = new Penguin(world, position, new Vector2(0, 0), 2, new Vector2(2, 2), new Vector2(0, 0), 0);
                    return(a);
                }
            }

            return(a);
        }
 public GameBehavior(GameWorld world, GameActor actor, Tile tile = null, Handle script = null) : base(world, actor, tile, script: script)
 {
 }
 public AnimalBehavior(GameWorld world, GameActor actor)
     : base(world, actor)
 {
     this.actor = actor;
 }
        /*************************************** Movement Functions ***************************************/

        /**
         *
         *
         */
        public List <Tile> findPaths()
        {
            // Cache for lazy evaluation
            if (pathsFromCurrentTile != null)
            {
                return(pathsFromCurrentTile);
            }

            pathsFromCurrentTile = new List <Tile>();
            Tile center = world.getTileAt(position);

            // Assuming animal can move moveRange in any direction, search space is a square of size moverange*2+1
            int[,] moveCost = new int[moveRange * 2 + 1, moveRange * 2 + 1];

            for (int i = 0; i < moveRange * 2 + 1; i++)
            {
                for (int j = 0; j < moveRange * 2 + 1; j++)
                {
                    moveCost[i, j] = -1;
                }
            }

            // Store whether tile has been visited
            Boolean[,] visited = new Boolean[moveRange * 2 + 1, moveRange * 2 + 1];

            for (int i = 0; i < moveRange * 2 + 1; i++)
            {
                for (int j = 0; j < moveRange * 2 + 1; j++)
                {
                    visited[i, j] = false;
                }
            }

            // Real tile index-offset= array index.
            int offsetx = center.xIndex - (moveRange);
            int offsetY = center.yIndex - (moveRange);

            // Set the origin tile's cost to 0
            moveCost[moveRange, moveRange] = 0;

            //
            Vector2 currentTileIndex;

            while (true)
            {
                currentTileIndex = new Vector2(-1, -1);

                // Find minimum cost, reachable non-visited tile.
                for (int i = 0; i < moveRange * 2 + 1; i++)
                {
                    for (int j = 0; j < moveRange * 2 + 1; j++)
                    {
                        if (visited[i, j] || moveCost[i, j] == -1) // If visited or not-reachable, continue.
                        {
                            continue;
                        }
                        // If current not yet set, match first not visited.
                        if (currentTileIndex.x == -1)
                        {
                            currentTileIndex = new Vector2(i, j);
                        }
                        // Find tile with minimum move cost.
                        else if (moveCost[(int)currentTileIndex.x, (int)currentTileIndex.y] > moveCost[i, j])
                        {
                            currentTileIndex = new Vector2(i, j);
                        }
                    }
                }
                // If current was not set in loop, no paths left to evaluate.
                if (currentTileIndex.x == -1)
                {
                    break;
                }

                int currentCost = moveCost[(int)currentTileIndex.x, (int)currentTileIndex.y];
                for (int x = 1; x >= -1; x--)
                {
                    for (int y = 1; y >= -1; y--)
                    {
                        // Only move to adjacent tiles.
                        if (Math.Abs(x) == Math.Abs(y))
                        {
                            continue;
                        }
                        // If within movable square process adjacent tile.
                        if (currentTileIndex.x + x <= moveRange * 2 && currentTileIndex.y + y <= moveRange * 2 && currentTileIndex.x + x >= 0 && currentTileIndex.y + y >= 0)
                        {
                            Tile checking = world.getTile((int)currentTileIndex.x + offsetx + x, (int)currentTileIndex.y + offsetY + y);
                            if (checking == null)
                            {
                                continue;
                            }
                            int tileCost = movementType[(checking as GameTile).type];

                            // Don't allow animal to move past an enemy unit
                            GameActor act = world.getActorOnTile(checking);
                            if (act != null && act is AnimalActor && ((AnimalActor)act).team != this.team)
                            {
                                tileCost = 999;
                            }

                            // If not visited and cheaper from this path or if not previously reachable set cost as cost of path through current.
                            if (!visited[(int)currentTileIndex.x + x, (int)currentTileIndex.y + y] &&
                                (moveCost[(int)currentTileIndex.x + x, (int)currentTileIndex.y + y] > currentCost + tileCost ||
                                 moveCost[(int)currentTileIndex.x + x, (int)currentTileIndex.y + y] == -1))
                            {
                                moveCost[(int)currentTileIndex.x + x, (int)currentTileIndex.y + y] = currentCost + tileCost;
                            }
                        }
                    }
                }
                if (currentCost <= moveRange)
                {
                    pathsFromCurrentTile.Add(world.getTile((int)currentTileIndex.x + offsetx, (int)currentTileIndex.y + offsetY));
                }
                visited[(int)currentTileIndex.x, (int)currentTileIndex.y] = true;
            }
            pathCost = moveCost;
            return(pathsFromCurrentTile);
        }