public Bitmap Decode(RoomBlock roomBlock, int objectIndex, int imageIndex) { var obj = roomBlock.GetOBIMs()[objectIndex]; if (obj.GetIMxx()[imageIndex].GetSMAP() == null) { return(new Bitmap(1, 1)); } var IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _transparency = roomBlock.GetTRNS().Value; _strips = obj.GetIMxx()[imageIndex].GetSMAP().Strips; if (PaletteIndex == 0) { _pallete = roomBlock.GetDefaultPalette(); } else { _pallete = roomBlock.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Decode(); return(_resultBitmap); }
public async Task <IActionResult> PostRoomBlock(RoomBlock block) { _context.RoomBlocks.Add(block); await _context.SaveChangesAsync(); return(NoContent()); }
public RoomBlockImageControl(RoomBlock roomBlock, Costume costume, ImageType imageType, int objectIndex, int imageIndex, int zPlaneIndex) { InitializeComponent(); _roomBlock = roomBlock; _costume = costume; _imageType = imageType; _imageIndex = imageIndex; _zPlaneIndex = zPlaneIndex; _objectIndex = objectIndex; CompressionMethod.Items.Add("Auto Detect"); CompressionMethod.Items.Add("Uncompressed"); CompressionMethod.Items.Add("Method 1 Vertical"); CompressionMethod.Items.Add("Method 1 Horizontal"); CompressionMethod.Items.Add("Method 2"); CompressionMethod.Items.Add("Method 2 Alternate Code"); CompressionMethod.SelectedIndex = 0; if (imageType == ImageType.Background || (imageType == ImageType.Object && _roomBlock.GetOBIMs()[_objectIndex].GetIMxx()[_imageIndex].GetSMAP() != null)) { CompressionMethodLabel.Visible = true; CompressionMethod.Visible = true; } else { pictureScroll.Top = CompressionMethod.Top; } }
private bool tryConstructRoom(Room room, int targetBlocksCount, int firstBlockX, int firstBlockY) { // добавили первый блок createAndAddBlockToRoomAndMap(firstBlockX, firstBlockY, room); // добавляем остальные блоки в комнату for (int i = 1; i < targetBlocksCount; i++) { // берём все сводобные стены у комнаты Side[] freeSidesOnRoom = getFreeSidesOnRoom(room); // если свободных стен нет, значит комнату невозможно достроить // и нужно отчистить её и вернуть результат о неудаче if (freeSidesOnRoom.Length == 0) { //Console.WriteLine("no free side on room"); //отчистить комнату и начать с другой стены на карте foreach (RoomBlock roomBlock in room.Blocks) { _map.Remove(roomBlock.Position); } room.Blocks.Clear(); return(false); } // создание нового блока комнаты возле случайной свободной стены у комнаты Side randSide = freeSidesOnRoom[_rand.Next(freeSidesOnRoom.Length)]; Vector2 blockPos = randSide.ToPosition(); RoomBlock newBlock = createAndAddBlockToRoomAndMap(blockPos.X, blockPos.Y, room); } return(true); }
private IEnumerator GenrateLevel() { //Need a way to control number of rooms //currently will only go along a single chain of doors, //need a way to go back along the chain until there is a free door while (numDoors > 0) { if (lastRoom != currentRoom) { currentRoom.parentRoom = lastRoom; } currentRoom.ConstructRoom(ref numDoors); if (PlaceRoom()) { numDoors--; placedRooms.Add(currentRoom); } else { currentRoom = currentRoom.parentRoom; } yield return(new WaitForSecondsRealtime(0.1f)); } for (int i = placedRooms.Count; i > 0; i++) { placedRooms[i].FillOutRoom(); yield return(new WaitForSecondsRealtime(0.1f)); } }
// расставляет внутри комнаты случайные перегородки private void constructPartitionWalls(Room room) { setInnerSidesTo(room, SideState.Wall); var randFirstBlock = room.Blocks[_rand.Next(room.Blocks.Count)]; var addedBlocks = new List <RoomBlock>(); addedBlocks.Add(randFirstBlock); while (addedBlocks.Count < room.Blocks.Count) { var block = addedBlocks[_rand.Next(addedBlocks.Count)]; // найти все соседние блоки этой же комнаты, исключая уже добавленные блоки var shuffledSides = block.Sides.OrderBy(_ => _rand.Next()).ToArray(); for (int j = 0; j < shuffledSides.Length; j++) { Side currentSide = shuffledSides[j]; Vector2 neighbourPos = currentSide.ToPosition(); RoomBlock neighbourBlock = room.Blocks.FirstOrDefault(b => b.Position == neighbourPos); if (neighbourBlock != null && !addedBlocks.Contains(neighbourBlock)) { currentSide.State = SideState.None; neighbourBlock.GetSideByDirection(currentSide.Direction.GetOpposite()).State = SideState.None; addedBlocks.Add(neighbourBlock); break; } } } }
//place new room private bool PlaceRoom() { int northSpace = 1; int eastSpace = 1; int southSpace = 1; int westSpace = 1; RoomBlock tmpRm = lastRoom; lastRoom = currentRoom; //need to randomise which door is chosen //Place a room at the next door in clockwise order if (currentRoom.northNode != null) { if (currentRoom.northNode.myType == Node.Type.doorNode) { //detect collisions in a 3x3 room block size RoomBlock newRoom = GetRandomRoom(northSpace, eastSpace, southSpace, westSpace, RoomBlock.Direction.s); newRoom.distFromCore = currentRoom.distFromCore++; currentRoom = newRoom; return(true); } } if (currentRoom.eastNode != null) { if (currentRoom.eastNode.myType == Node.Type.doorNode) { RoomBlock newRoom = GetRandomRoom(northSpace, eastSpace, southSpace, westSpace, RoomBlock.Direction.w); newRoom.distFromCore = currentRoom.distFromCore++; currentRoom = newRoom; return(true); } } if (currentRoom.southNode != null) { if (currentRoom.southNode.myType == Node.Type.doorNode) { RoomBlock newRoom = GetRandomRoom(northSpace, eastSpace, southSpace, westSpace, RoomBlock.Direction.n); newRoom.distFromCore = currentRoom.distFromCore++; currentRoom = newRoom; return(true); } } if (currentRoom.westNode != null) { if (currentRoom.westNode.myType == Node.Type.doorNode) { RoomBlock newRoom = GetRandomRoom(northSpace, eastSpace, southSpace, westSpace, RoomBlock.Direction.e); newRoom.distFromCore = currentRoom.distFromCore++; currentRoom = newRoom; return(true); } } lastRoom = tmpRm; return(false); }
public Bitmap Decode(RoomBlock roomBlock, int objectIndex, int imageIndex) { ObjectImage obj = roomBlock.GetOBIMs()[objectIndex]; if (obj.GetIMxx()[imageIndex].GetBOMP() == null) { return(new Bitmap(1, 1)); } var IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _imageData = obj.GetIMxx()[imageIndex].GetBOMP(); if (PaletteIndex == 0) { _pallete = roomBlock.GetDefaultPalette(); } else { _pallete = roomBlock.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Decode(); return(_resultBitmap); }
//place a core room private void PlaceCore() { coreRoom = Instantiate(cores[Random.Range(0, cores.Count)], Vector3.zero, Quaternion.identity); coreRoom.createdFrom = RoomBlock.Direction.NULL; coreRoom.ConstructRoom(ref numDoors); currentRoom = coreRoom; currentRoom.distFromCore = 0; placedRooms.Add(coreRoom); }
private RoomBlock createAndAddBlockToRoomAndMap(int x, int y, Room room) { RoomBlock newBlock = new RoomBlock(x, y, room); room.Blocks.Add(newBlock); _map.Add(newBlock.Position, newBlock); return(newBlock); }
public Bitmap Decode(RoomBlock roomBlock, int zPlaneIndex) { var RMHD = roomBlock.GetRMHD(); _width = RMHD.Width; _height = RMHD.Height; _zPlane = roomBlock.GetRMIM().GetIM00().GetZPlanes()[zPlaneIndex]; Decode(); return(_resultBitmap); }
public void Encode(RoomBlock blockToEncode, Bitmap imageToEncode, int zPlaneIndex) { _imageToEncode = imageToEncode; var RMHD = blockToEncode.GetRMHD(); _width = RMHD.Width; _height = RMHD.Height; _zPlane = blockToEncode.GetRMIM().GetIM00().GetZPlanes()[zPlaneIndex]; Encode(); }
public Bitmap Decode(RoomBlock roomBlock, int objectIndex, int imageIndex, int zPlaneIndex) { var obj = roomBlock.GetOBIMs()[objectIndex]; ObjectImageHeader IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _zPlane = obj.GetIMxx()[imageIndex].GetZPlanes()[zPlaneIndex]; Decode(); return(_resultBitmap); }
public void Encode(RoomBlock blockToEncode, int objectIndex, int imageIndex, Bitmap imageToEncode, int zPlaneIndex) { var obj = blockToEncode.GetOBIMs()[objectIndex]; _imageToEncode = imageToEncode; ObjectImageHeader IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _zPlane = obj.GetIMxx()[imageIndex].GetZPlanes()[zPlaneIndex]; Encode(); }
private RoomBlock GetRandomRoom(int northSpace, int eastSpace, int southSpace, int westSpace, RoomBlock.Direction d) { RoomBlock roomBlock = new RoomBlock(); int rng; bool boss = false; //need a way to say stop generating along this chain when it gets too long //also need a way to check if you are generating next to a room //so the rooms can generate with appropriate doors and also tell //the adjacent room that this one is now next to it if (!placedBossRoom && currentRoom.distFromCore == bossRoomDistFromCore - 1) { rng = Random.Range(0, bossRooms.Count); roomBlock = bossRooms[rng]; boss = true; } //randomly chooses a room from this areas list of rooms else { rng = Random.Range(0, rooms.Count); roomBlock = rooms[rng]; } //Quadratically probes the list of rooms if the one selected does not meet the requirments for the space int n = 0; while ((roomBlock.Dimentions.n > northSpace || roomBlock.Dimentions.e > eastSpace || //checks if the room can fit roomBlock.Dimentions.s > southSpace || roomBlock.Dimentions.w > westSpace) && //within the avalible space and roomBlock.HasDoorHere(d)) //it has a door that can connect { n++; if (boss) { int nRNG = rng + (n * n); //if this is checking for boss rooms while (nRNG > bossRooms.Count) { nRNG -= bossRooms.Count; } //it will loop through the boss rooms quadratically roomBlock = bossRooms[nRNG]; //looking for a suitable room placedBossRoom = true; } else { int newRNG = rng + (n * n); while (newRNG > rooms.Count) { newRNG -= rooms.Count; } roomBlock = rooms[newRNG]; } } return(roomBlock); }
//place treasure in empty room private void PlaceTreasure() { int rng = Random.Range(0, rooms.Count); RoomBlock tRoom = rooms[rng]; int n = 0; //Quadratic probing if the selected room is inadiquet to avoid clumping (selecting the same set of rooms) while (tRoom.enemySpawnSpots.Count > 0) { n++; int newRNG = rng + (n * n); while (newRNG > rooms.Count) { newRNG -= rooms.Count; } tRoom = rooms[newRNG]; } }
public void Encode(RoomBlock roomBlock, Costume costume, int frameIndex, Bitmap imageToEncode) { _costume = costume; _pictureData = costume.Pictures[frameIndex]; _imageToEncode = imageToEncode; if (PaletteIndex == 0) { _palette = roomBlock.GetDefaultPalette(); } else { _palette = roomBlock.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Encode(); }
private void constructPartitionWallsAsMaze(Room room) { setInnerSidesTo(room, SideState.Wall); var randFirstBlock = room.Blocks[_rand.Next(room.Blocks.Count)]; Stack <RoomBlock> path = new Stack <RoomBlock>(); path.Push(randFirstBlock); Dictionary <RoomBlock, bool> visitedMap = room.Blocks.ToDictionary(b => b, v => false); visitedMap[randFirstBlock] = true; while (visitedMap.Values.Contains(false)) { var block = path.Peek(); var shuffledSides = block.Sides.OrderBy(_ => _rand.Next()).ToArray(); bool finded = false; for (int j = 0; j < shuffledSides.Length; j++) { Side currentSide = shuffledSides[j]; Vector2 neighbourPos = currentSide.ToPosition(); RoomBlock neighbourBlock = room.Blocks.FirstOrDefault(b => b.Position == neighbourPos); if (neighbourBlock != null && visitedMap[neighbourBlock] == false) { visitedMap[neighbourBlock] = true; path.Push(neighbourBlock); currentSide.State = SideState.None; neighbourBlock.GetSideByDirection(currentSide.Direction.GetOpposite()).State = SideState.None; finded = true; break; } } if (finded == false) { path.Pop(); } } }
public Bitmap Decode(RoomBlock roomBlock, Costume costume, int frameIndex) { _pictureData = costume.Pictures[frameIndex]; _costume = costume; if (PaletteIndex == 0) { _palette = roomBlock.GetDefaultPalette(); } else { _palette = roomBlock.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Decode(); return(_resultBitmap); }
public void Encode(RoomBlock blockToEncode, Bitmap imageToEncode) { _imageToEncode = imageToEncode; RoomHeader RMHD = blockToEncode.GetRMHD(); _width = RMHD.Width; _height = RMHD.Height; _imageBomp = blockToEncode.GetRMIM().GetIM00().GetBOMP(); if (PaletteIndex == 0) { _pallete = blockToEncode.GetDefaultPalette(); } else { _pallete = blockToEncode.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Encode(); }
public void Encode(RoomBlock blockToEncode, Bitmap imageToEncode) { _imageToEncode = imageToEncode; var RMHD = blockToEncode.GetRMHD(); _width = RMHD.Width; _height = RMHD.Height; _transparency = blockToEncode.GetTRNS().Value; _strips = blockToEncode.GetRMIM().GetIM00().GetSMAP(); if (PaletteIndex == 0) { _pallete = blockToEncode.GetDefaultPalette(); } else { _pallete = blockToEncode.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Encode(); }
public void Encode(RoomBlock blockToEncode, int objectIndex, int imageIndex, Bitmap imageToEncode) { var obj = blockToEncode.GetOBIMs()[objectIndex]; _imageToEncode = imageToEncode; ObjectImageHeader IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _transparency = blockToEncode.GetTRNS().Value; _strips = obj.GetIMxx()[imageIndex].GetSMAP(); if (PaletteIndex == 0) { _pallete = blockToEncode.GetDefaultPalette(); } else { _pallete = blockToEncode.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Encode(); }
public void Encode(RoomBlock blockToEncode, int objectIndex, int imageIndex, Bitmap imageToEncode) { ObjectImage obj = blockToEncode.GetOBIMs()[objectIndex]; _imageToEncode = imageToEncode; var IMHD = obj.GetIMHD(); _width = IMHD.Width; _height = IMHD.Height; _imageBomp = obj.GetIMxx()[imageIndex].GetBOMP(); if (PaletteIndex == 0) { _pallete = blockToEncode.GetDefaultPalette(); } else { _pallete = blockToEncode.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Encode(); }
public Bitmap Decode(RoomBlock roomBlock) { var RMHD = roomBlock.GetRMHD(); _width = RMHD.Width; _height = RMHD.Height; _transparency = roomBlock.GetTRNS().Value; _strips = roomBlock.GetRMIM().GetIM00().GetSMAP().Strips; if (PaletteIndex == 0) { _pallete = roomBlock.GetDefaultPalette(); } else { _pallete = roomBlock.GetPALS().GetWRAP().GetAPALs()[PaletteIndex]; } Decode(); return(_resultBitmap); }
public RoomBlockImageControl(RoomBlock roomBlock, ImageType imageType, int objectIndex, int imageIndex, int zPlaneIndex) : this(roomBlock, null, imageType, objectIndex, imageIndex, zPlaneIndex) { }
public RoomBlockImageControl(RoomBlock roomBlock, ImageType imageType, int zPlaneIndex) : this(roomBlock, null, imageType, 0, 0, zPlaneIndex) { }
public RoomBlockImageControl(RoomBlock roomBlock, ImageType imageType) : this(roomBlock, null, imageType, 0, 0, 0) { }
private void OK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ImportLocation.Text)) { return; } if (!Directory.Exists(ImportLocation.Text)) { return; } string location = ImportLocation.Text; Cursor = Cursors.WaitCursor; Cancel.Cursor = Cursors.Default; _cancelImport = false; _importing = true; foreach (Control control in Controls) { if (control.Name != "Cancel" && control.GetType() != typeof(Label) && control.GetType() != typeof(ProgressBar)) { control.Enabled = false; } } List <ImageInfo> files = Directory.GetFiles(location, "*.png").Select(f => new ImageInfo(f)).ToList(); Application.DoEvents(); List <DiskBlock> diskBlocks = _scummFile.DataFile.GetLFLFs(); Progress.Maximum = files.Count - 1; Progress.Value = 0; Progress.Visible = true; FilesFound.Text = files.Count.ToString(); var encoder = new ImageEncoder(); var bompEncoder = new BompImageEncoder(); var costumeEncoder = new CostumeImageEncoder(); var zplaneEncoder = new ZPlaneEncoder(); for (int i = 0; i < files.Count; i++) { ImageInfo currentFile = files[i]; RoomBlock currentRoomBlock = diskBlocks[currentFile.RoomIndex].GetROOM(); Bitmap bitmapToEncode = (Bitmap)Bitmap.FromFile(currentFile.Filename); var preferredIndexes = new int[0]; string indexFile = currentFile.Filename + ".idx"; if (File.Exists(indexFile)) { preferredIndexes = File.ReadAllText(indexFile).Split(';').Select(s => Convert.ToInt32(s)).ToArray(); } try { switch (currentFile.ImageType) { case ImageType.Background: { encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(currentRoomBlock, bitmapToEncode); } break; case ImageType.ZPlane: { zplaneEncoder.Encode(currentRoomBlock, bitmapToEncode, currentFile.ZPlaneIndex); } break; case ImageType.Object: if (currentRoomBlock.GetOBIMs()[currentFile.ObjectIndex].GetIMxx()[currentFile.ImageIndex].GetSMAP() == null) { bompEncoder.PreferredIndexes = new List <int>(preferredIndexes); bompEncoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode); } else { encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode); } break; case ImageType.ObjectsZPlane: { zplaneEncoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode, currentFile.ZPlaneIndex); } break; case ImageType.Costume: { Costume costume = diskBlocks[currentFile.RoomIndex].GetCostumes()[currentFile.CostumeIndex]; costumeEncoder.Encode(currentRoomBlock, costume, currentFile.FrameIndex, bitmapToEncode); } break; } } catch (ImageEncodeException ex) { MessageBox.Show(ex.Message, "Error importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } FilesImported.Text = i.ToString(); Progress.Value = i; Application.DoEvents(); } MessageBox.Show("All images imported"); DialogResult = DialogResult.OK; Close(); }
private void CreateOrShowControl(string id) { splitContainer1.Panel2.Controls.Clear(); RoomBlock roomBlock = (RoomBlock)_diskBlock.Childrens.Single(r => r.GetType() == typeof(RoomBlock)); if (!_roomImages.ContainsKey(id)) { ClassCreateInfo createInfo = CreateInfos[id]; switch (createInfo.ImageType) { case ImageType.Background: var backgroundImageControl = new RoomBlockImageControl(roomBlock, ImageType.Background); backgroundImageControl.Visible = true; backgroundImageControl.Dock = DockStyle.Fill; backgroundImageControl.DecodeTransparent = DecodeTransparent.Checked; backgroundImageControl.PaletteIndex = Palettes.SelectedIndex; backgroundImageControl.Decode(); _roomImages.Add(createInfo.ControlId, backgroundImageControl); break; case ImageType.ZPlane: var zplaneImageControl = new RoomBlockImageControl(roomBlock, ImageType.ZPlane, createInfo.ZPlaneIndex); zplaneImageControl.Visible = true; zplaneImageControl.Dock = DockStyle.Fill; zplaneImageControl.DecodeTransparent = DecodeTransparent.Checked; zplaneImageControl.PaletteIndex = Palettes.SelectedIndex; zplaneImageControl.Decode(); _roomImages.Add(createInfo.ControlId, zplaneImageControl); break; case ImageType.Object: var objectImageControl = new RoomBlockImageControl(roomBlock, ImageType.Object, createInfo.ObjectIndex, createInfo.ImageIndex); objectImageControl.Visible = true; objectImageControl.Dock = DockStyle.Fill; objectImageControl.DecodeTransparent = DecodeTransparent.Checked; objectImageControl.PaletteIndex = Palettes.SelectedIndex; objectImageControl.Decode(); _roomImages.Add(createInfo.ControlId, objectImageControl); break; case ImageType.ObjectsZPlane: var zPlaneImageControl = new RoomBlockImageControl(roomBlock, ImageType.ObjectsZPlane, createInfo.ObjectIndex, createInfo.ImageIndex, createInfo.ZPlaneIndex); zPlaneImageControl.Visible = true; zPlaneImageControl.Dock = DockStyle.Fill; zPlaneImageControl.DecodeTransparent = DecodeTransparent.Checked; zPlaneImageControl.PaletteIndex = Palettes.SelectedIndex; zPlaneImageControl.Decode(); _roomImages.Add(createInfo.ControlId, zPlaneImageControl); break; case ImageType.Costume: var costumeFrameControl = new RoomBlockImageControl(roomBlock, createInfo.Costume, ImageType.Costume, createInfo.ImageIndex); costumeFrameControl.Visible = true; costumeFrameControl.Dock = DockStyle.Fill; costumeFrameControl.DecodeTransparent = DecodeTransparent.Checked; costumeFrameControl.PaletteIndex = Palettes.SelectedIndex; costumeFrameControl.Decode(); _roomImages.Add(createInfo.ControlId, costumeFrameControl); break; } } splitContainer1.Panel2.Controls.Add(_roomImages[id]); }
public RoomBlockImageControl(RoomBlock roomBlock, Costume costume, ImageType imageType, int frameIndex) : this(roomBlock, costume, imageType, 0, frameIndex, 0) { }