예제 #1
0
        private void AddTileVertices(Tile tile, Vector2f position)
        {
            vertexArray.Append(new Vertex((new Vector2f(0.0f, 0.0f) + position) * tileWorldDimension,
                new Vector2f(tileTextureDimension * tile.X, tileTextureDimension * tile.Y)));

            vertexArray.Append(new Vertex((new Vector2f(1.0f, 0.0f) + position) * tileWorldDimension
                , new Vector2f(tileTextureDimension * tile.X + tileTextureDimension, tileTextureDimension * tile.Y)));

            vertexArray.Append(new Vertex((new Vector2f(1.0f, 1.0f) + position) * tileWorldDimension,
                new Vector2f(tileTextureDimension * tile.X + tileTextureDimension, tileTextureDimension * tile.Y + tileTextureDimension)));

            vertexArray.Append(new Vertex((new Vector2f(0.0f, 1.0f) + position) * tileWorldDimension,
                new Vector2f(tileTextureDimension * tile.X, tileTextureDimension * tile.Y + tileTextureDimension)));
        }
예제 #2
0
파일: State.cs 프로젝트: shaunfallis/RPG
        //Each line contains a comma delimited tile definition that the tile constructor understands
        private void readTileDefinitions(string tileDescriptionFile)
        {
            using (StreamReader stream = new StreamReader(tileDescriptionFile))
            {
                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    //separate out the elements of the
                    string[] elements = line.Split(',');

                    //And make the tile.
                    Tile tile = new Tile(elements);
                    _tiles.Add(tile.Shortcut, tile);
                }
            }
        }
예제 #3
0
        public Tilemap(Texture tileset, int width, int height, float tileTextureDimension, float tileWorldDimension)
        {
            this.tileset = tileset;

            this.width = width;
            this.height = height;
            this.tileTextureDimension = tileTextureDimension;
            this.tileWorldDimension = tileWorldDimension;

            vertexArray = new VertexArray(PrimitiveType.Quads, (uint)(width * height * 4));

            Tile tile = new Tile(1, 2, Color.White);
            for(int x = 0; x < width; x++)
            {
                for(int y = 0; y < height; y++)
                {
                    AddTileVertices(tile, new Vector2f((float)x, (float)y));
                }
            }
        }
예제 #4
0
        /*public Tile getMonsterTile()
        {
            return monstertile;
        }*/
        public void setMonsterLocation(int index, Tile newloc)
        {
            Tile monstertile = monstertiles[index];
            if (monstertile != null)
            {
                monstertile.setMapX(newloc.getMapX());
                monstertile.setMapY(newloc.getMapY());

                if (playertile != null && monstertile.getMapX() == playertile.getMapX() && monstertile.getMapY() == playertile.getMapY())
                {
                    processEvents(map[playertile.getMapX()][playertile.getMapY()]);
                    /*Event e = new Event();
                    e.setEventType(EventType.BATTLE_TILE);
                    Game1.addToEventQueue();*/
                }
            }
            else
                Console.WriteLine("Monster is null!!");
        }
예제 #5
0
        public void setNPCLocation(String id, Tile newloc)
        {
            Tile npc = null;
            if(npctiles.ContainsKey(id))
                npc = npctiles[id];

            if (npc != null)
            {
                npc.setMapX(newloc.getMapX());
                npc.setMapY(newloc.getMapY());
            }
            else
                Console.WriteLine("NPC is null!!");
        }
예제 #6
0
        public void processEvents(Tile cur)
        {
            if(Game1.DEBUG)
                Console.WriteLine("Processing Events!");

            Event[] ce = cur.getEvents();

            if(Game1.DEBUG)
            Console.WriteLine("Found " + ce.Length + " events!");

            for (int i = 0; i < ce.Length; i++)
            {
                Game1.addToEventQueue(ce[i]);
            }

            for(int i = 0; i < monstertiles.Count; i++)
                if(cur.getMapX() == monstertiles[i].getMapX() && cur.getMapY() == monstertiles[i].getMapY())
                {
                    Event e = new Event();
                    e.setEventType(EventType.BATTLE_TILE);
                    e.addProperty("battlemap", battlemap.GetFilePath());
                    e.addProperty("enemytexture", monstertiles[i].getTexture().Name);
                    e.addProperty("index", Convert.ToString(i));
                    Game1.addToEventQueue(e);
                }
        }
예제 #7
0
 public void removePlayer()
 {
     playertile = null;
 }
예제 #8
0
        private Tile processAStar(Tile player, Tile monster)
        {
            Tile ret = null;

            if (player != null && monster != null)
            {
                if(state == GameState.ASTAR)
                    map.resetPlayers();

                Tile start = map.getTileAt(monster.getMapX(), monster.getMapY());
                Tile goal = map.getTileAt(player.getMapX(), player.getMapY());

                ret = iterateAStar(start, goal);
            }
            return ret;
        }
예제 #9
0
        public bool LoadMap(StreamReader file, String filename, ToolMap toolmap)
        {
            this.filename = filename;
            bool success = false;
            bool gotxandy = false;
            int x = 0;
            int y = 0;
            int playerx = -1;
            int playery = -1;

            using (XmlReader reader = XmlReader.Create(file))
            {
                while (reader.Read() && !gotxandy)
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (reader.Name == "MAP")
                            {
                                x = Convert.ToInt32(reader["x"]);
                                y = Convert.ToInt32(reader["y"]);
                                if(reader["playerx"] != null && reader["playery"] != null)
                                {
                                    playerx = Convert.ToInt32(reader["playerx"]);
                                    playery = Convert.ToInt32(reader["playery"]);
                                }

                                gotxandy = true;
                            }
                            break;
                    }
                }
            }

            xtiles = x;
            ytiles = y;

            map = new Tile[x][];
            for(int i = 0; i < x; i++)
                map[i] = new Tile[y];

            file.BaseStream.Position = 0;
            int tilex = 0;
            int tiley = 0;
            bool inEvent = false;
            Event current = new Event();
            using (XmlReader reader = XmlReader.Create(file))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (reader.Name == "MONSTER")
                            {
                                //file.WriteLine("<MONSTER type=\"" + monstertiles[i].getType() + "\" x=\"" +
                                //    monstertiles[i].getMapX() + "\" y=\"" + monstertiles[i].getMapY() + "\" />");
                                hasmonsters = true;
                                String type = reader["type"];
                                tilex = Convert.ToInt32(reader["x"]);
                                tiley = Convert.ToInt32(reader["y"]);

                                if (Game1.DEBUG)
                                    Console.WriteLine("Adding Monster!!, monstertiles.Count=" + monstertiles.Count);

                                monstertiles.Add(new Tile(tilex, tiley, 0, 0, 0, toolmap.getTool(type)));
                            }
                            if (reader.Name == "TILE")
                            {
                                tilex = Convert.ToInt32(reader["x"]);
                                tiley = Convert.ToInt32(reader["y"]);

                                String type = reader["type"];
                                Tool tiletool = toolmap.getTool(type);
                                map[tilex][tiley] = new Tile(tilex, tiley, tilex, tiley, 0, tiletool);
                            }
                            else if (reader.Name == "EVENT")
                            {
                                String eventtype = reader["type"];
                                current.setEventType((EventType)Enum.Parse(typeof(EventType), eventtype));
                                inEvent = true;
                            }
                            else if (reader.Name == "DATA")
                            {
                                if (inEvent)
                                {
                                    XmlReader tempreader = reader.ReadSubtree();
                                    String propname = "";
                                    while(tempreader.Read())
                                        switch (tempreader.NodeType)
                                        {
                                            case XmlNodeType.Element:
                                                propname = tempreader.Name;
                                                break;
                                            case XmlNodeType.Text:
                                                current.addProperty(propname, tempreader.Value);
                                                break;
                                        }
                                }
                            }
                            break;
                        case XmlNodeType.EndElement:
                            if (reader.Name == "EVENT")
                            {
                                if(Game1.DEBUG)
                                Console.WriteLine("Adding event!");

                                map[tilex][tiley].addEvent(current);
                                inEvent = false;
                                current = new Event();
                            }
                            break;
                    }
                }
            }

            if (playertile == null)
                playertile = toolmap.getPlayerTile();

            if (playerx > 0 && playery > 0)
                setPlayerLocation(map[playerx][playery]);

            success = true;

            return success;
        }
예제 #10
0
 private Tile getNextStep(Tile best)
 {
     Tile cur = best;
     while (cur.getPrevious() != null)
     {
         if (cur.getPrevious().getPrevious() == null)
         {
             return cur;
         }
         cur = cur.getPrevious();
     }
     return cur;
 }
예제 #11
0
        public void Update(ToolMap toolmap, GameTime gameTime)
        {
            Tool selectedTool = toolmap.getSelected();
            MouseState mouseState = Mouse.GetState();
            int mousex = mouseState.X;
            int mousey = mouseState.Y;

            //if mouse is within the map, do mouse over...
            if ((mousex > 10 && mousex < totalmapsize + 10) &&
                (mousey > 10 && mousey < totalmapsize + 10))
            {
                double tempx = (mousex - 10) / pixelsperside;
                int tilex = (int)Math.Floor(tempx);

                double tempy = (mousey - 10) / pixelsperside;
                int tiley = (int)Math.Floor(tempy);

                if (mouseState.LeftButton == ButtonState.Pressed && selectedTool != null)
                {
                    WorldTile selectedType = selectedTool.getType();
                    if (selectedType == WorldTile.PLAYER)
                    {
                        Tile cur = map[tilex][tiley];
                        if (cur.getType() != WorldTile.WALL)
                        {
                            if (playertile == null)
                                playertile = new Tile(tilex, tiley, cur.getX(), cur.getY(), cur.getLength(), selectedTool);
                            else
                            {
                                playerx = tilex;
                                playery = tiley;

                                playertile.setMapX(tilex);
                                playertile.setMapY(tiley);
                            }
                        }
                    }
                    else if (selectedType == WorldTile.MONSTER)
                    {
                        Tile cur = map[tilex][tiley];
                        if (cur.getType() != WorldTile.WALL)
                        {
                                monstertiles.Add(new Tile(tilex, tiley, cur.getX(), cur.getY(), cur.getLength(), selectedTool));
                        }
                    }
                    else
                    {
                        if (selectedTool.getType() == WorldTile.SELECT)
                        {
                            //if (selectedtile != null && selectedtile != map[curxtilemin + tilex][curytilemin + tiley])
                            //    selectedtile.setColor(Color.White);

                            toolmap.setSelectedTile(map[curxtilemin + tilex][curytilemin + tiley]);
                            //selectedtile.setColor(Color.DarkGray);
                        }
                        else
                        {
                            map[curxtilemin + tilex][curytilemin + tiley].applyTool(selectedTool, toolmap);
                        }
                    }

                }
                    if (highlighted != null)
                        highlighted.unhighlight();

                    highlighted = map[curxtilemin + tilex][curytilemin + tiley];
                    highlighted.highlight();
            }
        }
예제 #12
0
 private Tile createAStarHighlight(Tile best)
 {
     Tile start = addToAStarHighlight(best, null);
     Tile cur = best;
     Tile curhl = start;
     while (cur != null)
     {
         Tile next = cur.getPrevious();
         if (next != null)
         {
             curhl = addToAStarHighlight(next, curhl);
         }
         cur = next;
     }
     return curhl;
 }
예제 #13
0
 private int getCumulativeCost(Tile node)
 {
     int ret = 0;
     Tile cur = node;
     if (DEBUG)
     {
         while (cur != null)
         {
             Console.Write("x");
             ret += cur.getCost();
             cur = cur.getPrevious();
         }
     }
     else
     {
         while (cur != null)
         {
             ret += cur.getCost();
             cur = cur.getPrevious();
         }
     }
     return ret;
 }
예제 #14
0
        private bool canAdd(Tile toadd, List<Tile> open, List<Tile> closed)
        {
            bool ret = false;
            if (DEBUG)
                Console.WriteLine("entered canAdd");

            if (toadd != null && !toadd.isObstacle() && !closed.Contains(toadd) && !open.Contains(toadd))
            {
                if(DEBUG)
                    Console.WriteLine("Can add (" + toadd.getMapX() + "," + toadd.getMapY() + ")");

                ret = true;
            }

            if (DEBUG)
                Console.WriteLine("exiting canAdd");

            return ret;
        }
예제 #15
0
        private Tile addToAStarHighlight(Tile toadd, Tile prev)
        {
            int x = toadd.getX();
            int y = toadd.getY();
            int mapx = toadd.getMapX();
            int mapy = toadd.getMapY();
            int len = toadd.getLength();

            if(DEBUG)
                Console.WriteLine("Adding tile at (" + mapx + "," + mapy + ") to bestpath! Cost is " + toadd.getTotalCost());

            Tile newadd = new Tile(mapx, mapy, x, y, len, new Tool(WorldTile.BLACK, astarwaypoint));
            newadd.setPrevious(prev);
            return newadd;
        }
예제 #16
0
        private void addTile(Tile toadd, Tile prev, List<Tile> open, Tile goal)
        {
            if (DEBUG)
            {
                Console.WriteLine("Adding node (" + toadd.getMapX() + "," + toadd.getMapY() + "), with cost " + toadd.getTotalCost() + " to open list, open count is = " + open.Count);
                if (prev != null)
                    Console.WriteLine("Previous is (" + prev.getMapX() + "," + prev.getMapY() + ")");
                else
                    Console.WriteLine("Previous is null!");
            }
            toadd.setPrevious(prev);
            int distance = getCumulativeCost(toadd);
            //int distance = 0;
            toadd.addToTotalCost(distance + Math.Abs(toadd.getMapX() - goal.getMapX()) + Math.Abs(toadd.getMapY() - goal.getMapY()));

            open.Add(toadd);
            if (DEBUG)
                Console.WriteLine("Node added.");
        }
예제 #17
0
        public void setPlayerLocation(Tile newloc)
        {
            if (playertile == null)
                playertile = toolmap.getPlayerTile();

            playertile.setMapX(newloc.getMapX());
            playertile.setMapY(newloc.getMapY());
            playerx = playertile.getMapX();
            playery = playertile.getMapY();
            curxtilemin = Math.Max(Math.Min(playerx - 8,xtiles - 17), 0);
            curytilemin = Math.Max(Math.Min(playery - 8,ytiles - 17), 0);
        }
예제 #18
0
 public void setSelectedTile(Tile selected)
 {
     this.selectedtile = selected;
 }
예제 #19
0
        public TileMap(int x, int y, int size, int xtiles, int ytiles, Texture2D pixel, ToolMap tools, SpriteFont font, String filename)
        {
            this.hasmonsters = false;
            this.lastspawnedmonster = 0;
            this.filename = filename;
            this.toolmap = tools;
            this.size = size;
            this.xtiles = xtiles;
            this.ytiles = ytiles;
            this.font = font;
            double tss = VIEW_HEIGHT / size;
            int tilesidesize = (int)Math.Floor(tss);
            totalmapsize = tilesidesize * size;
            curxtilemin = 0;
            curytilemin = 0;
            battlemap = Map.BATTLE_GENERIC;

            //int curtoolx = tools.Length-1;
            //int curtooly = tools[0].Length-1;

            pixelsperside = tilesidesize;
            center = (int)Math.Ceiling(size / 2.0);
            displaytiles = new Rectangle[size][];
            monstertiles = new List<Tile>();
            npctiles = new Dictionary<String, Tile>();
            for (int i = 0; i < size; i++)
            {
                displaytiles[i] = new Rectangle[size];
                for (int j = 0; j < size; j++)
                {
                    displaytiles[i][j] = new Rectangle(x + i*tilesidesize, y + j*tilesidesize, pixelsperside, pixelsperside);
                }
            }

            //Random randval = new Random();

            map = new Tile[xtiles][];

            for (int i = 0; i < xtiles; i++)
            {
                map[i] = new Tile[ytiles];
                for (int j = 0; j < ytiles; j++)
                {
                    //int currandx = randval.Next(0, 2);
                    //int currandy = randval.Next(0, 3);
                    map[i][j] = new Tile(i, j, (x + i * tilesidesize), (y + j * tilesidesize), tilesidesize, toolmap.getDefaultTool());
                }
            }
        }
예제 #20
0
        public Rectangle getDisplayRectangleFor(Tile cur)
        {
            Rectangle ret = Rectangle.Empty;

            int curx = cur.getMapX();
            int cury = cur.getMapY();

            if (curx >= curxtilemin && curx <= (curxtilemin + size) && cury >= curytilemin && cury <= (curytilemin + size))
            {
                int dispx = curx - curxtilemin;
                int dispy = cury - curytilemin;

                ret = displaytiles[dispx][dispy];
            }

            return ret;
        }
예제 #21
0
        private Tile iterateAStar(Tile start, Tile goal)
        {
            if(DEBUG)
                Console.WriteLine("Called iterateAStar!, goal is at (" + goal.getMapX() + "," + goal.getMapY() + ")");

            Tile ret = null;
            List<Tile> bestpath = new List<Tile>();
            List<Tile> closed = new List<Tile>();
            start.addToTotalCost(Math.Abs(start.getMapX() - goal.getMapX()) + Math.Abs(start.getMapY() - goal.getMapY()));
            List<Tile> open = new List<Tile>();
            open.Add(start);
            while (open.Count > 0)
            {
                //get the lowest cost node...
                Tile cur = open.Min();
                if(DEBUG)
                    Console.WriteLine("Min retrieved node (" + cur.getMapX() + "," + cur.getMapY() + ") with " + cur.getTotalCost() + " from the open list");

                if (cur.getMapX() == goal.getMapX() && cur.getMapY() == goal.getMapY())
                {
                    if(DEBUG)
                        Console.WriteLine("Found goal! cur is (" + cur.getMapX() + "," + cur.getMapY() + ")");

                    return cur;
                    //return addToBestPath(bestpath, cur, last);
                }
                else
                {
                    int curx = cur.getMapX();
                    int cury = cur.getMapY();
                    open.Remove(cur);
                    closed.Add(cur);
                    Tile up = map.getTileAt(curx, cury - 1);
                    Tile down = map.getTileAt(curx, cury + 1);
                    Tile left = map.getTileAt(curx - 1, cury);
                    Tile right = map.getTileAt(curx + 1, cury);

                    if (canAdd(up, open, closed))
                        addTile(up, cur, open, goal);

                    if (canAdd(down, open, closed))
                        addTile(down, cur, open, goal);

                    if (canAdd(left, open, closed))
                        addTile(left, cur, open, goal);

                    if (canAdd(right, open, closed))
                        addTile(right, cur, open, goal);
                }

            }
            if(DEBUG)
                Console.WriteLine("Failed to find a path!");

            return ret;
        }
예제 #22
0
        private void processAddEvent(Tile thetile)
        {
            Event e = new Event();
            Form1 form = new Form1(e);
            form.ShowDialog();

            /*
            String map = e.getProperty("mapfile");
            String x = e.getProperty("x");
            String y = e.getProperty("y");
            */
            if(e.getEventType() != EventType.CANCELED)
                thetile.addEvent(e);

            //Console.WriteLine("map=>" + map + "<, x=>" + x + "<, y=>" + y + "<");
        }