Example #1
0
        /*********************************************************************************
        * Tile Functions
        *********************************************************************************/
        public void addTile(string textureName, long tilex, long tiley, bool passable)
        {
            intTile tile = (intTile) new clsTile(textureName, passable);

            tile.location       = new Vector2(tilex * this.tileSize, tiley * this.tileSize);
            tiles[tilex, tiley] = tile;
        }
Example #2
0
        public Vector2 origin;          // origin of texture rotation


        public clsSpriteTile(intTile tile, Dictionary <string, Texture2D> textures)
        {
            this.tile       = tile;
            displayLocation = new Vector2(0, 0);
            origin          = new Vector2(32, 32);
            this.texture    = textures[this.tile.textureName];
        }
Example #3
0
        // get all the valid routes between two points
        // the only rule is that they can not overlap themselves
        public List <List <Vector2> > getAllPaths(List <Vector2> previousWaypoints, Vector2 destinationSquareCoordinate)
        {
            // collection of all possible paths
            List <List <Vector2> > paths = new List <List <Vector2> >();


            // set the current square to the starting location
            Vector2 currentWaypoint = previousWaypoints[previousWaypoints.Count() - 1];
            intTile currentSquare   = (intTile)this.world.getTileFromTileCoordinate(currentWaypoint);

            // get all posible directions off of the current square
            foreach (Vector2 currentDirection in currentSquare.directions)
            {
                // get way point for this direction
                Vector2 newWaypoint = new Vector2(currentWaypoint.X, currentWaypoint.Y) + currentDirection;

                // is this a valid new waypoint
                if (this.world.inTileCoordinateBounds(newWaypoint))        // is it on the map
                {
                    if (!containsWaypoint(previousWaypoints, newWaypoint)) // is it not an infinite loop
                    {
                        // fully copy existing path to a new path and add the new waypoint direction
                        List <Vector2> newPath = copyWaypoints(previousWaypoints);
                        newPath.Add(newWaypoint);

                        // does this new path reach our destination?
                        if ((newWaypoint.X == destinationSquareCoordinate.X) && (newWaypoint.Y == destinationSquareCoordinate.Y))
                        {
                            // add the now completed path to the collection of paths
                            paths.Add(newPath);
                        }
                        else
                        {
                            // do further exploration of this path and all its possibilities
                            List <List <Vector2> > newPaths = getAllPaths(newPath, destinationSquareCoordinate);
                            foreach (List <Vector2> newSubPath in newPaths)
                            {
                                paths.Add(newSubPath);
                            }
                        }
                    }
                }
            }

            // all processing is done
            return(paths);
        }
Example #4
0
        /*****************************************
        *              tile locations
        *****************************************/
        public void processTileLocations()
        {
            // clear all tile object contents
            for (int x = 0; x < this.tiles.GetLength(0); x += 1)
            {
                for (int y = 0; y < this.tiles.GetLength(1); y += 1)
                {
                    this.tiles[x, y].worldObjects = new List <intObject>();
                }
            }

            // loop through each object
            foreach (intObject worldObject in this.worldObjects)
            {
                intTile tile = this.getTileFromWorldLocation(worldObject.location); // get the tile this object is on
                tile.worldObjects.Add(worldObject);                                 // add this object to that tile
            }
        }
Example #5
0
        /*****************************************
        *       Creating the world
        *****************************************/
        public void loadTiles(long tilesWide)
        {
            tiles = new intTile[tilesWide, tilesWide];
            long x, y;

            // grass
            for (y = 0; y < tilesWide; y++)
            {
                for (x = 0; x < tilesWide; x++)
                {
                    this.addGrass(x, y);
                    //tiles[x, y] = new clsTile("grass", false, false, false, false);
                }
            }

            // east west road
            y = tilesWide / 2;
            for (x = 0; x < tilesWide; x++)
            {
                addRoad(x, y, CardinalDirection.East);
                addRoad(x, y - 1, CardinalDirection.West);
            }

            // north south road
            x = (tilesWide / 2);
            for (y = 0; y < tilesWide; y++)
            {
                addRoad(x, y, CardinalDirection.North);
                addRoad(x - 1, y, CardinalDirection.South);
            }

            // intersection
            long center = tilesWide / 2;

            addIntersection(center - 1, center, true, false, false, true);
            addIntersection(center, center - 1, false, true, true, false);
            addIntersection(center - 1, center - 1, false, true, false, true);
            addIntersection(center, center, true, false, true, false);
        }
Example #6
0
        public void calcNextObstruction()
        {
            this.distanceToNextObstruction = 1000;

            // calculate next obstruction & future collsisions
            for (int t = 0; t < _waypoints.Count; t++)
            {
                // get the tile in questions
                intTile tile = world.getTileFromTileCoordinate(_waypoints[t]);

                // look for next obstruction
                foreach (intObject worldObject in tile.worldObjects)
                {
                    if (worldObject.collisionDetection != CollisionType.None) // make sure collision detection is on
                    {
                        // we have to add check it it has collision with self
                        this.nextObstruction           = (clsObject)worldObject;
                        this.distanceToNextObstruction = t;
                        break;
                    }
                }
            }
        }
Example #7
0
 public void addTile(intTile tile, long tilex, long tiley)
 {
     tile.location       = new Vector2(tilex * this.tileSize, tiley * this.tileSize);
     tiles[tilex, tiley] = tile;
 }