Exemplo n.º 1
0
        public Map()
        {
            MapWidth = 19;
            MapHeight = 15;
            Tileset = TileEngine.Tilesets[0];
            SpawnPoints = new List<Point>();

            mapCells = new MapCell[MapHeight,MapWidth];

            Music = 2;

            for (int y = 0; y < MapHeight; y++)
            {
                for (int x = 0; x < MapWidth; x++)
                {
                    mapCells[y, x] = new MapCell(0);
                }
            }
        }
Exemplo n.º 2
0
        //Build the tower on the selected tile
        public virtual void Build(Point point)
        {
            if ((GameScene.CurrentMap.TileIsBuildable(point)  && GameScene.Gold >= GameScene.LoadedPrice))
            {
                //Play sound effect.
                //Create the tower on the given tile
                MapPosition = point;
                Position = new Vector2(point.X * TileEngine.TileWidth, point.Y * TileEngine.TileHeight);
                ParentCell = GameScene.CurrentMap[point.Y, point.X];

                ParentCell.IsWalkable = false;
                ParentCell.IsBuildable = false;
                ParentCell.ContainsTower = true;

                GameScene.Gold -= BuildCost;
                AudioManager.PlaySoundEffect(9);

                GameScene.CurrentMap.SetMovementCost(MapPosition, Pathfinding.Pathfinder.TOWER_COST);

                Initialize();
            }
            else
            {
                //Give error sound
                GameScene.ClearMouseAction();
            }
        }
Exemplo n.º 3
0
        //Handle mouse input during the game.
        public static void HandleMouseInput(GameTime gameTime)
        {
            Point curMouseTile = TileEngine.ScreenSpaceToMapSpace(new Vector2(MouseHandler.CurrentMouseState.X, MouseHandler.CurrentMouseState.Y));
            //Player clicks the mouse
            if (MouseHandler.Click())
            {
                //The mouse is over the map.
                if (MouseHandler.CurrentMouseState.X < CurrentMap.MapWidth * TileEngine.TileWidth && CurrentMouseAction == MouseAction.PlaceTile)
                {
                    if (!isBaseTile)
                    {
                        if (storedTile == 4 && castlePlaced)
                        {
                            for (int i = 0; i < castleTile.tiles.Count; i++)
                            {
                                if (castleTile.tiles[i].TileID == 4)
                                {
                                    castleTile.tiles.RemoveAt(i);
                                    break;
                                }
                            }
                        }

                        if (storedTile == 4)
                        {
                            castleTile = CurrentMap.mapCells[curMouseTile.Y, curMouseTile.X];
                            castlePlaced = true;
                        }

                        if (storedTile == 5)
                        {
                            Scene.CurrentMap.SpawnPoints.Add(new Point(curMouseTile.X, curMouseTile.Y));
                        }
                    }

                    if(!isBaseTile)
                        ClearNonBaseTiles(curMouseTile);

                    PlaceTile(curMouseTile, storedTile, isBaseTile);
                }
            }
            if (MouseHandler.RightClick())
            {
                //If right clicking, break the current operation.
                if (CurrentMouseAction != MouseAction.None)
                    CurrentMouseAction = MouseAction.None;
                else if (MouseHandler.CurrentMouseState.X < CurrentMap.MapWidth * TileEngine.TileWidth && CurrentMouseAction == MouseAction.None)
                {
                    ClearNonBaseTiles(new Point(curMouseTile.X, curMouseTile.Y));
                }
            }
        }