public Room(string name) { UndertaleResources.Room rawRoom; if (!UndertaleResrouce.TryGetResource(name, out rawRoom)) { throw new Exception("Cannot find room"); } LoadRoom(rawRoom); }
public Room(int index) { LoadRoom(UndertaleResrouce.RoomAtIndex(index)); obj_writer = this.CreateInstance(100, 100, "OBJ_WRITER"); }
void LoadRoom(UndertaleResources.Room rawRoom) { this.RoomIndex = rawRoom.Index; this.Name = rawRoom.Name; Global.CurrentRoom = this; _position = Vector2.Zero; _size = new Vector2(rawRoom.Width, rawRoom.Height); _backgroundColor = new Color((byte)(rawRoom.Colour >> 16), (byte)(rawRoom.Colour >> 8), (byte)rawRoom.Colour); List <Tile> backgrounds = new List <Tile>(); List <Tile> foregrounds = new List <Tile>(); List <Tile> tiles = new List <Tile>(); foreach (var b in rawRoom.Backgrounds) { if (b.BackgroundIndex < 0) { continue; } var tile = UndertaleResrouce.Backgrounds[b.BackgroundIndex]; Tile t = new Tile(); t.Frame = Sprite.CreateFrameFromFrame(tile.Frame); t.Position = new Vector2(b.X, b.Y); t.Speed = new Vector2(b.SpeedX, b.SpeedY); t.Visiable = b.Visible; if (b.Foreground) { foregrounds.Add(t); t.Depth = -1000001; } else { backgrounds.Add(t); t.Depth = 1000001; } } _backgrounds = backgrounds.ToArray(); _foregrounds = foregrounds.ToArray(); foreach (var rawTile in rawRoom.Tiles) { var bgn = UndertaleResrouce.BackgroundAtIndex(rawTile.BackgroundIndex); Tile t = new Tile(); t.Frame = Sprite.CreateFrameFromFrame(bgn.Frame); Rectangle newOrigin = new Rectangle( t.Frame.Origin.X + rawTile.OffsetX, t.Frame.Origin.Y + rawTile.OffsetY, rawTile.Width, rawTile.Height ); t.Frame.Origin = newOrigin; t.Position = new Vector2(rawTile.X, rawTile.Y); t.Scale = new Vector2(rawTile.ScaleX, rawTile.ScaleY); t.Color = Color.White; if (rawTile.Ocupancy == 0) { System.Diagnostics.Debug.WriteLine("Need Ocupancy"); } if (rawTile.Ocupancy >= 0) { t.Color *= (rawTile.Ocupancy / 256); } else { t.Color = Color.White; } t.Blend.PackedValue = (uint)rawTile.Blend; if (rawTile.Blend != 16777215) { System.Diagnostics.Debug.WriteLine("Need Blend"); } System.Diagnostics.Debug.Assert(rawTile.Depth != 10000000); // wierd? t.Depth = rawTile.Depth; // Global.DepthToMonoDepth( rawTile.Depth); tiles.Add(t); } tiles.Sort(); foreach (var t in tiles) { System.Diagnostics.Debug.WriteLine("Tile Depth: " + t.Depth); } _tiles = tiles.ToArray(); _objects = new List <GameObject>(); foreach (var oo in rawRoom.Objects) { if (oo.Index > 0) { GameObject o = this.CreateInstance(oo.X, oo.Y, oo.ObjectIndex); o.Direction = oo.Rotation; o.ScaleVector = new Vector2(oo.Scale_X, oo.Scale_Y); o.Color.PackedValue = (uint)oo.Colour; if (o.Color != Color.White) { throw new Exception("Humm wierd"); } if (o.Width > 2000 || o.Height > 2000) { throw new Exception("Uhg"); } // oo.Colour hummm } } using (var s = new System.IO.StreamWriter("debug_room_objects.txt")) { foreach (var o in _objects) { s.WriteLine(o.Name); } } }