public TilePalette(List<Tile> t)
        {
            tiles = t;
            selectedTile = tiles[0];

            isActive = false;
        }
Exemplo n.º 2
0
        public Map(string n, Tile[,] t, int width, int height)
        {
            name = n;
            tiles = t;
            tilesList = new List<Tile>();
            mapWidth = width;
            mapHeight = height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    tilesList.Add(tiles[x,y]);
                }
            }
        }
Exemplo n.º 3
0
        public void Draw(SpriteBatch s, Tile[,] tiles, List<NPC> npcs)
        {
            List<Tile> charTiles = new List<Tile>();

            foreach (Tile t in tiles)
            {
                if( (t.worldPosition.X > camBounds.X && t.worldPosition.X < camBounds.Width) &&
                    (t.worldPosition.Y > camBounds.Y && t.worldPosition.Y < camBounds.Height) )
                {
                    charTiles.Add(t);
                }
            }

            foreach (Tile t in charTiles)
                t.Draw(s, position);

            foreach (NPC npc in npcs)
                npc.Draw(s, position);

            foreach (Magic m in MagicManager.friendlyMagic)
                m.Draw(s, position);
        }
Exemplo n.º 4
0
 public void setTiles(Tile[,] t)
 {
     tiles = t;
 }
Exemplo n.º 5
0
 public void SetTile(Tile t, int x, int y)
 {
     tiles[x, y] = t;
 }
        public static Map LoadMap(string mapName, int width, int height, ContentManager Content)
        {
            // test out load file dialog

            Tile[,] tiles = new Tile[width,height];

            Map tempMap = new Map("", 0, 0);
            int xCount = 0;
            int yCount = 0;
            Tile[,] tempTiles = new Tile[0, 0];

            using (XmlReader reader = XmlReader.Create(mapName + ".xml"))
            {
                while (reader.Read())
                {
                    // only detect start elements
                    if (reader.IsStartElement())
                    {
                        // get the element name and switch on it
                        switch (reader.Name)
                        {
                            case "Name":
                                reader.Read();
                                tempMap.name = reader.Value;
                                break;
                            case "height":
                                reader.Read();
                                tempMap.Height = Int32.Parse(reader.Value);
                                break;
                            case "width":
                                reader.Read();
                                tempMap.Width = Int32.Parse(reader.Value);
                                tempTiles = new Tile[tempMap.Width, tempMap.Height];
                                break;
                            case "tile":
                                int type = 0;
                                reader.Read();
                                reader.Read();
                                reader.Read();
                                type = Int32.Parse(reader.Value);

                                Texture2D text = Content.Load<Texture2D>("water");

                                if (type == 0)
                                    text = Content.Load<Texture2D>("water");
                                if (type == 1)
                                    text = Content.Load<Texture2D>("grass");
                                if (type == 2)
                                    text = Content.Load<Texture2D>("rock");

                                tempTiles[xCount, yCount] = new Tile(type, new Vector2(xCount * 32, yCount * 32), text);

                                xCount++;
                                if (xCount > tempMap.Width - 1)
                                {
                                    xCount = 0;
                                    yCount++;
                                }
                                break;
                        }
                    }
                }

            }

            //Map map = new Map("My Map", tiles, width, height);
            tempMap.setTiles(tempTiles);
            return tempMap;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            currKeyState = Keyboard.GetState();
            currMouseState = Mouse.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                (currKeyState.IsKeyUp(Keys.Escape) && prevKeyState.IsKeyDown(Keys.Escape) ))
                this.Exit();

            c.Update();

            foreach (NPC npc in npcs)
            {
                npc.Update(rand.Next(16, 600), rand.Next(16, 600));
            }

            cam.Update(c.worldPosition);

            if (currKeyState.IsKeyUp(Keys.F5) && prevKeyState.IsKeyDown(Keys.F5))
                mapMode = !mapMode;

            MagicManager.Update();

            colMan.CheckMagicCollisions(npcs);
            colMan.CheckWallCollisions(map, c);

            Rectangle cRect = new Rectangle((int)c.WorldPosition.X, (int)c.WorldPosition.Y, 32, 32);

            foreach (Event evnt in map.Events)
            {
                Rectangle eventRect = new Rectangle((int)evnt.Position.X, (int)evnt.Position.Y, 32, 32);

                if (cRect.Intersects(eventRect))
                {
                    map = FileManager.LoadMap(evnt.Value, mapWidth, mapHeight, Content);

                    events = new List<Event>();

                    events.Add(new Event(new Vector2(352, 256), "building1"));
                    events.Add(new Event(new Vector2(384, 256), "building1"));
                    events.Add(new Event(new Vector2(416, 256), "building1"));

                    map.Events = events;

                    c.WorldPosition = new Vector2(160, 160);
                }
            }

            if (mapMode)
            {
                if (currKeyState.IsKeyUp(Keys.D1) && prevKeyState.IsKeyDown(Keys.D1))
                    selectedTile = 0;
                if (currKeyState.IsKeyUp(Keys.D2) && prevKeyState.IsKeyDown(Keys.D2))
                    selectedTile = 1;
                if (currKeyState.IsKeyUp(Keys.D3) && prevKeyState.IsKeyDown(Keys.D3))
                    selectedTile = 2;

                if (currKeyState.IsKeyDown(Keys.LeftControl) && currKeyState.IsKeyUp(Keys.S) && prevKeyState.IsKeyDown(Keys.S))
                {
                    FileManager.SaveMap(map);
                }

                if (currKeyState.IsKeyDown(Keys.LeftControl) && currKeyState.IsKeyUp(Keys.L) && prevKeyState.IsKeyDown(Keys.L))
                {
                    map = FileManager.LoadMap(Content);
                    events = new List<Event>();

                    events.Add(new Event(new Vector2(352, 256), "building1"));
                    events.Add(new Event(new Vector2(384, 256), "building1"));
                    events.Add(new Event(new Vector2(416, 256), "building1"));

                    map.Events = events;
                }

                Rectangle mouseRect = new Rectangle(currMouseState.X + (int)cam.position.X, currMouseState.Y + (int)cam.position.Y, 8, 8);

                for (int x = 0; x < map.Width; x++)
                {
                    for (int y = 0; y < map.Height; y++)
                    {
                        if (mouseRect.Intersects(map.getTile(x, y).GetTileBounds()))
                        {
                            if (currMouseState.RightButton == ButtonState.Pressed)
                            {
                                Tile tile = new Tile();
                                tile.sprite = tilePalette[selectedTile];
                                tile.worldPosition = new Vector2(x * 32, y * 32);
                                tile.type = selectedTile;
                                map.SetTile(tile, x, y);
                            }

                        }
                    }
                }

            }

            if (currKeyState.IsKeyUp(Keys.F1) && prevKeyState.IsKeyDown(Keys.F1))
            {
                graphics.ToggleFullScreen();

                if (graphics.IsFullScreen)
                {
                    graphics.PreferredBackBufferWidth = 1920;
                    graphics.PreferredBackBufferHeight = 1080;
                    cam.height = 1080;
                    cam.width = 1920;
                }
                else
                {
                    graphics.PreferredBackBufferWidth = 800;
                    graphics.PreferredBackBufferHeight = 480;
                    cam.width = 800;
                    cam.height = 480;
                }

                c.position = new Vector2((graphics.PreferredBackBufferWidth / 2) - 32, (graphics.PreferredBackBufferHeight / 2) - 32);
                cam.camOffset = c.position;
                graphics.ApplyChanges();
            }

            prevKeyState = currKeyState;
            prevMouseState = currMouseState;

            base.Update(gameTime);
        }
Exemplo n.º 8
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);
            colMan = new CollisionManager();

            currKeyState = Keyboard.GetState();
            prevKeyState = currKeyState;

            currMouseState = Mouse.GetState();
            prevMouseState = currMouseState;

            font = Content.Load<SpriteFont>("font");

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 480;
            graphics.ApplyChanges();

            c = new Character(new Vector2(0, 0), new Vector2(520,520), Content.Load<Texture2D>(@"hero"), Content.Load<Texture2D>("testProjectile"));
            c.position = new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2));

            cam = new Camera(c.worldPosition);
            cam.camOffset = c.position;
            cam.width = 800;
            cam.height = 480;

            map = FileManager.LoadMap("overworld", mapWidth, mapHeight, Content);
            /*
            string mapName = "temp";

            int width = 10;
            int height = 10;

            Tile[,] tiles = new Tile[width, height];

            Random rand = new Random();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int num = rand.Next(0, 3);

                    Tile t = new Tile();
                    t.worldPosition = new Vector2(x * 32, y * 32);

                    if (num == 0)
                    {
                        t.type = 0;
                        t.sprite = Content.Load<Texture2D>("water");
                    }
                    if (num == 1)
                    {
                        t.type = 1;
                        t.sprite = Content.Load<Texture2D>("grass");
                    }
                    if (num == 2)
                    {
                        t.type = 2;
                        t.sprite = Content.Load<Texture2D>("rock");
                    }

                    tiles[x, y] = t;
                }

            }

            map = new Map(mapName, tiles, width, height);
            */
            map.Events = events;

            npcs = new List<NPC>();
            cam = new Camera(c.worldPosition);

            List<Tile> paletteTiles = new List<Tile>();
            Tile grassTile = new Tile(0, new Vector2(0, 0), Content.Load<Texture2D>("grass"));
            Tile waterTile = new Tile(0, new Vector2(0, 32), Content.Load<Texture2D>("water"));
            Tile rockTile = new Tile(0, new Vector2(0, 64), Content.Load<Texture2D>("rock"));

            tilePalette = new List<Texture2D>();
            tilePalette.Add(Content.Load<Texture2D>("water"));
            tilePalette.Add(Content.Load<Texture2D>("grass"));
            tilePalette.Add(Content.Load<Texture2D>("rock"));

            tile = Content.Load<Texture2D>("selectedTile");
            mapMode = false;
            selectedTile = 0;
        }