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); }
/*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!!"); }
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!!"); }
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; }
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); } }
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; }
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; }
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; }
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."); }
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; }