Пример #1
0
        /// <summary>
        /// Sets up the world, performing all actions common to all the constructors
        /// </summary>
        public void setUpWorld()
        {
            Vector2 TL = new Vector2(0, 150); //The top left of that area to actually draw the world in
            inputHandler = new WorldInputHandler(TL, new Vector2(1024 - TL.X, 768 - TL.Y), this);
            deadList = new Stack<Creature>();
            plantList = new List<Plant>();
            remainsList = new List<Remains>();
            tiles = new Tile[worldX][];

            for (int i = 0; i < worldX; i++)
            {
                tiles[i] = new Tile[worldY];

                for (int j = 0; j < worldY; j++)
                {
                    tiles[i][j] = new Tile();
                }
            }
            populateWorld();
        }
Пример #2
0
        /// <summary>
        /// Gets the tiles visible in the World for drawing, cropping out the tiles that are not visible
        /// </summary>
        /// <returns>A 2d array of tiles that are visible based on the location and size of the viewing area</returns>
        public Tile[][] getTilesVisible()
        {
            float x = size.X / Display.getTileSize(); //number of tiles to display in each direction
            float y = size.Y / Display.getTileSize();
            if (x % 1 != 0)
            {
                x = x + (1 - Math.Abs(x % 1));
            }
            if (y % 1 != 0)
            {
                y = y + (1 - Math.Abs(y % 1));
            }

            Tile[][] tiles = new Tile[(int)x + 1][];
            for (int i = 0; i < tiles.Length; i++)
            {
                tiles[i] = new Tile[(int)y + 1];
            }

            float locX = location.X;
            float locY = location.Y;
            locX /= Display.getTileSize();
            locY /= Display.getTileSize();
            locX -= locX % 1;
            locY -= locY % 1;

            for (int x2 = 0; x2 < tiles.Length; x2++)
            {
                for (int y2 = 0; y2 < tiles[x2].Length; y2++)
                {
                    Tile t = world.getTile((int)locY + y2, (int)locX + x2);
                    if(t != null)
                    {
                        tiles[x2][y2] = t;
                    }
                }
            }
            return tiles;
        }
Пример #3
0
 /// <summary>
 /// Gets a specified tile given a row and column
 /// </summary>
 /// <param name="row">The row of the tile to look at</param>
 /// <param name="col">The column of the tile to look at</param>
 /// <returns>The tile found at the given row and column</returns>
 public Tile getTile(int row, int col)
 {
     Tile t = null;
     if (col < 0 || col > tiles.Length - 1)
     {
         t = new Tile();
         Obstacle o = new Obstacle();
         o.setLocation(col, row);
         t.addObstacle(o);
     }
     else if (row < 0 || row > tiles[col].Length - 1)
     {
         t = new Tile();
         Obstacle o = new Obstacle();
         o.setLocation(col, row);
         t.addObstacle(o);
     }
     else
     {
         t = tiles[col][row];
     }
     return t;
 }
Пример #4
0
 /// <summary>
 /// Draws a single tile at a specified location
 /// </summary>
 /// <param name="r">The rectangle that the tile should be drawn in</param>
 /// <param name="t">The tile to be drawn</param>
 private void drawTile(Rectangle r, Tile t)
 {
     Simulation.getGraphicsDeviceManager().GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap;
     spriteBatch.Begin(0, null, SamplerState.PointWrap, null, null);
     if (t.plantPresent())
     {
         if (t.getPlant().isDepeleted())
         {
             spriteBatch.Draw(depletedPlantTile, r, Color.White);
         }
         else
         {
             spriteBatch.Draw(plantTile, r, Color.White);
         }
     }
     else if (t.remainsPresent())
     {
         spriteBatch.Draw(remainsTile, r, Color.White);
     }
     else if (t.obstaclePresent())
     {
         spriteBatch.Draw(obstacleTile, r, Color.White);
     }
     else if (t.creaturePresent())
     {
         if (Display.getDrawCreaturesAsGenes())
         {
             Gene g = t.getCreature().getDna();
             spriteBatch.Draw(g.getTexture(), r, Color.White);
         }
         else
         {
             spriteBatch.Draw(creatureTile, r, Color.White);
         }
     }
     else
     {
         spriteBatch.Draw(emptyTile, r, Color.White);
     }
     spriteBatch.End();
 }