public void ConvertAll(string name, TiledTileDefinition definition)
        {
            var tiled      = TiledDefinition.Load(definition.TiledFile);
            int tileWidth  = tiled.TileSet.TileWidth;
            int tileHeight = tiled.TileSet.TileHeight;

            var tileSet = tiled.TileSet;

            if (tileSet.TileHeight != tileHeight)
            {
                throw new ConversionException("All tiles sets must have tiles of the same height.");
            }

            if (tileSet.TileWidth != tileWidth)
            {
                throw new ConversionException("All tiles sets must have tiles of the same width.");
            }

            var image   = tileSet.ImageFileName.FromInputFolder().LoadIndexedBitmap();
            var palette = new PaletteTransformer(name, image.Palette, definition.PlaneCount.PowerOfTwo());

            _paletteRenderer.Render(palette, false);
            _tileRenderer.Render(name, image, tileWidth, tileHeight, definition.PlaneCount);

            var layer = tiled.Layer;

            _layerRenderer.Render(name, layer, definition.PlaneCount, tileWidth, tileHeight);
        }
        private void RenderBobPalette(ColorPalette bitmapPalette)
        {
            var palette = new PaletteTransformer("BobPalette", bitmapPalette, _definition.BobPlaneCount.PowerOfTwo());

            if (_definition.BobPaletteFlip0AndLast)
            {
                palette.Flip(0, palette.Length - 1);
            }

            _paletteRenderer.Render(palette, true);
        }
示例#3
0
        public ImageInfo ConvertAll(string name, ImageDefinition definition, Destination destination = Destination.Executable)
        {
            var fileName = definition.ImageFile;
            var image    = fileName.FromInputFolder().LoadIndexedBitmap();

            _bitplaneRenderer.Render(name, image, definition.PlaneCount, destination);
            var palette = new PaletteTransformer(name, image.Palette, definition.PlaneCount.PowerOfTwo());

            _paletteRenderer.Render(palette, false);
            return(new ImageInfo {
                Height = image.Height,
            });
        }
        // Renders the palette in one file with each color as a word formatted in bigendian.
        // 0x0RGB
        public void Render(PaletteTransformer palette, bool disk)
        {
            if (disk)
            {
                _writer.StartObject(ObjectType.Fast, palette.Name);
            }
            else
            {
                _writer.StartObject(ObjectType.Palette, palette.Name);
            }


            foreach (var color in palette.Colors)
            {
                _writer.WriteWord(color);
            }
            _writer.EndObject();
        }
示例#5
0
        public void Process(LevelDefinition definition)
        {
            _definition = definition;

            if (_definition.Tiles != null)
            {
                ConvertTiles(_definition);
            }

            var bobPalette = _definition.BobPaletteFile.FromInputFolder().LoadIndexedBitmap();

            if (_definition.SpritePaletteFile != null)
            {
                var paletteBitmap = _definition.SpritePaletteFile.FromInputFolder().LoadIndexedBitmap();

                var palette = new PaletteTransformer("sprite", paletteBitmap.Palette, 16);
                _paletteRenderer.Render(palette, false);

                if (_definition.Player != null)
                {
                    if (_definition.Player.Shots == null)
                    {
                        throw new ConversionException("Must define 'shots' for 'player'");
                    }

                    if (_definition.Player.Shots.Count != 6)
                    {
                        throw new ConversionException("Must define exactly 2 'shots' for 'player'");
                    }

                    WriteShotStructure();
                    int i = 0;
                    foreach (var shot in _definition.Player.Shots)
                    {
                        if (shot.Bob == null)
                        {
                            throw new ConversionException("Must define 'bob' for each of the 'player.shots'");
                        }
                        _bobConverter.ConvertBob($"shot{i}", shot.Bob, definition.BobPlaneCount, bobPalette.Palette,
                                                 _definition.BobPaletteFlip0AndLast ? BobMode.ColorFlip : BobMode.NoColorFlip, Destination.Executable);
                        i++;
                    }

                    int maxCount = 0;
                    i = 0;
                    _writer.WriteCode(Code.Data, "\tsection data");
                    _writer.WriteCode(Code.Data, "shots:");
                    foreach (var shot in _definition.Player.Shots)
                    {
                        _writer.WriteCode(Code.Data, $"shot{i}:");
                        _writer.WriteCode(Code.Data, $"\tdc.l\tshot{i}Bob");
                        _writer.WriteCode(Code.Data,
                                          $"\tdc.w\t{shot.Vx}, {shot.Hit}, {shot.MaxCount}, {shot.Cooldown}\t;vx,hit,maxCount,cooldDown");


                        var soundOffset = _items.Get(ItemTypes.Sound, shot.Sound, "Player shots").Offset;

                        _writer.WriteCode(Code.Data, $"\tdc.w\t{soundOffset}\t; sound Offset");
                        if (shot.MaxCount > maxCount)
                        {
                            maxCount = shot.MaxCount;
                        }
                        i++;
                    }

                    _writer.WriteCode(Code.Normal, $"MAX_BULLETS\t\tequ\t{maxCount}");

                    var playerVx  = _definition.Player.Vx;
                    var playerVy  = _definition.Player.Vy;
                    var playerVxy = Math.Sin(Math.PI / 4) * (playerVx + playerVy) / 2;
                    _writer.WriteCode(Code.Normal, $"PLAYER_VX\t\tequ\t{playerVx}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_VY\t\tequ\t{playerVy}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_VD\t\tequ\t{(int) playerVxy}");

                    _writer.WriteCode(Code.Normal,
                                      $"PLAYER_RAYDURATION\t\tequ\t{_definition.Player.Death.RayDuration}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_SPAWNDELAY\t\tequ\t{_definition.Player.Death.SpawnDelay}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_SPAWNX\t\tequ\t{_definition.Player.Death.Spawn.X}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_SPAWNY\t\tequ\t{_definition.Player.Death.Spawn.Y}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_SPAWNCELH\t\tequ\t{_definition.Player.Death.SpawnCelH}");
                    _writer.WriteCode(Code.Normal, $"PLAYER_SPAWNCELV\t\tequ\t{_definition.Player.Death.SpawnCelV}");
                    _writer.WriteCode(Code.Normal,
                                      $"PLAYER_INVULNDURATION\t\tequ\t{_definition.Player.Death.InvulnerabilityDuration}");
                }
            }
            else if (_definition.Player != null)
            {
                throw new ConversionException("You must specify a SpritePaletteFile to have a sprite.");
            }

            if (_definition.Images != null)
            {
                foreach (var imageDefinition in _definition.Images)
                {
                    _imageConverter.ConvertAll(imageDefinition.Key, imageDefinition.Value);
                }
            }

            if (_definition.Panel != null)
            {
                _imageConverter.ConvertAll("ScoreFont", _definition.Panel.Font);
                _writer.WriteCode(Code.Normal, $"; Score location");
                _writer.WriteCode(Code.Normal, $"SCORE_X\t\tequ\t{_definition.Panel.X}");
                _writer.WriteCode(Code.Normal, $"SCORE_Y\t\tequ\t{_definition.Panel.Y}");

                var scoreboardInfo = _imageConverter.ConvertAll("Scoreboard", _definition.Panel.Scoreboard);
                _scoreboardHeight = scoreboardInfo.Height;
            }

            _writer.WriteCode(Code.Normal, $"LEVEL_WIDTH\t\tequ\t\t{_definition.Level.Width}");
            _writer.WriteCode(Code.Normal,
                              $"FXP_SHIFT\t\tequ\t\t{_definition.FixedPointBits}\t; Amount to shift a levelwide X coordinates before using the MapXLookup");


            WriteMapLookup();
            WriteMainLookup();
            WriteBobList();
        }