public static Map FromImage( Image image ) { Bitmap bitmap = new Bitmap(image); Map map = new Map(); Dictionary<Color, Room> RoomIDMap = new Dictionary<Color, Room>(); Surface wall = new Surface(); wall.Texture = "default_wall"; int wallID = 0; map.Surfaces.Add(wallID,wall); Surface floor = new Surface(); floor.Texture = "default_floor"; int floorID = 1; map.Surfaces.Add(floorID,floor); for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { if (PosIsTile(x, y, bitmap)) { Color c = bitmap.GetPixel(x, bitmap.Height - y- 1); Room room = null; if (RoomIDMap.ContainsKey(c)) room = RoomIDMap[c]; else { room = new Room(); RoomIDMap.Add(c, room); } Tile tile = new Tile(); tile.Location = new Point(x,y); if (IsDoor(tile.Location, bitmap)) tile.Type = Tile.TileType.ClosedDoor; else tile.Type = Tile.TileType.Open; tile.Floor = floorID; foreach (Direction dir in FindWallDirections(tile.Location, bitmap)) tile.Walls.Add(dir, wallID); room.Tiles.Add(tile); } } } bitmap.Dispose(); foreach (KeyValuePair<Color, Room> i in RoomIDMap) map.Rooms.Add(i.Value); return map; }
public Map getMap(int mapid) { if (maps.ContainsKey(mapid)) { return maps[mapid]; } else { //map not loaded Map result = new Map(PokeEngine.instance, mapid); maps.Add(mapid, result); return result; } }
public Map[] getCopy() { Map[] copy_ = new Map[w * h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { copy_[x + y * w] = _matrix[x + y * w]; } } return copy_; }
public MapMatrix(Map initializer_) { /* * There is no corner, the offset allows to give the illusion of a corner * U * L M R * D */ w = 3; h = 3; _matrix = new Map[w * h]; _matrix[1 + 1 * w] = initializer_; }
public static bool ToXML( FileInfo file, Map map ) { try { XmlSerializer xml = new XmlSerializer(typeof(Map)); Stream fs = file.OpenWrite(); xml.Serialize(fs, map); fs.Close(); return true; } catch (System.Exception ex) { return false; } }
public MapConnection(PokeEngine engine, Map parent, ConnectionDirection direction, int id, int offset) : base(engine, id) { this.direction = direction; this.parent = parent; this.offset = offset; }
public MapConnection(PokeEngine engine, Map Parent, ConnectionDirection direction, int id) : base(engine, id) { }
public Tile(Map map, int x, int y) { this.map = map; this.x = x; this.y = y; }
public MapConnection createConnectionFromInfo(Map parent) { MapConnection result = new MapConnection(PokeEngine.instance, parent, dir, id, offset); return result; }
public Entity(Map map, int x, int y) { this.map = map; this.x = x; this.y = y; }
public Mob(Map map, int x, int y) : base(map, x, y) { isMoving = false; }