Пример #1
0
 public Tile[,] GetSurroundingTiles(Point current, int distance)
 {
     Tile[,] tempTiles = new Tile[(distance * 2) + 2, (distance * 2) + 2];
     int xPos = 0;
     for (int x = current.X - distance; x <= current.X + distance; x++)
     {
         int yPos = 0;
         for (int y = current.Y - distance; y <= current.Y + distance; y++)
         {
             //if the current y/x tile exists then add it the the surrounding tiles list
             if (x >= 0 && y >= 0 && x < tiles.Length && y < tiles[x].Length)
                 tempTiles[xPos, yPos] = tiles[x][y];
             else
                 tempTiles[xPos, yPos] = null;
             yPos += 1;
         }
         xPos += 1;
     }
     return tempTiles;
 }
Пример #2
0
        protected void UpdateMouse()
        {
            MouseState current_mouse = Mouse.GetState();

            // The mouse x and y positions are returned relative to the
            // upper-left corner of the game window.
            mousePos.X = current_mouse.X;
            mousePos.Y = current_mouse.Y;
            pointer.Prepare(mousePos-pointer.center);

            if (current_mouse.LeftButton == ButtonState.Pressed)
            {
                currentClickTile = map.SpriteOverTile(pointer);

                if (currentClickTile.X < map.tiles.Length && currentClickTile.Y < map.tiles[0].Length)
                {
                    //tile
                    if (placement_type == 0)
                    {
                        Tile tempTile = new Tile(map.tiles[currentClickTile.X][currentClickTile.Y].enemySpawns, 0.0f, currentClickTile, map.tiles[currentClickTile.X][currentClickTile.Y].tileTypes,
                                                    current_destroyable, current_collidable, current_power, current_energy, 0, current_worth, tileTextures,
                                                    tileSize.X, tileSize.Y);
                        map.tiles[currentClickTile.X][currentClickTile.Y] = tempTile;

                        map.tiles[currentClickTile.X][currentClickTile.Y].alive = true;
                        map.tiles[currentClickTile.X][currentClickTile.Y].SetContent(Content);
                        map.tiles[currentClickTile.X][currentClickTile.Y].tileTypes[currentTileLevel] = previewTile.tileTypes[0];
                    }

                    //enemy
                    if (placement_type == 1 && keyTimer == 0)
                    {
                        keyTimer = keytimermax*2;
                        if (enemyType.X == 0 && enemyType.Y == 0)
                        {
                            if (map.tiles[currentClickTile.X][currentClickTile.Y].enemySpawns.Count > 0)
                                map.tiles[currentClickTile.X][currentClickTile.Y].enemySpawns.RemoveAt(map.tiles[currentClickTile.X][currentClickTile.Y].enemySpawns.Count - 1);
                        }
                        else
                        {
                            int total_cols = (enemyTextures.Width / tileSize.X);
                            int enemyID = (total_cols * (int)enemyType.Y) + ((int)enemyType.X);
                            map.tiles[currentClickTile.X][currentClickTile.Y].enemySpawns.Add(enemyID);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            tileTextures = Content.Load<Texture2D>("Sprites\\map\\level1");
            enemyTextures = Content.Load<Texture2D>("enemy");

            Texture2D pointerTexture = Content.Load<Texture2D>("pointer");

            pointer = new MovableObject(0.0f, 0.0f, new Vector2(0, 0), false, false, 0, 0, 0, 0, pointerTexture, 32, 32, 0, 0, false);
            pointer.Prepare(mousePos);

            //if cannot load a map file then create a new one
            CreateMap();

            previewTile = new Tile(null, 0.0f, new Point(0, 0), new Vector4[] { new Vector4(0, 0, 0, 0) }, false, false, 90, 0, 0, 0, tileTextures, tileSize.X, tileSize.Y);
            previewTile.Prepare(new Vector2(230.0f, gameArea.Height-5.0f));

            previewEnemey = new Tile(null, 0.0f, new Point(0, 0), new Vector4[] { new Vector4(0, 0, 0,0 ) }, false, false, 90, 0, 0, 0, enemyTextures, tileSize.X, tileSize.Y);
            previewEnemey.Prepare(new Vector2(230.0f, gameArea.Height + 30.0f));

            writer = new ScreenText(Content.Load<SpriteFont>("GameHud"));
        }