private void ConvertBobToDisk(string name, BobDefinition bob, LevelDefinition definition, Bitmap bobPalette)
        {
            var offset = _writer.GetCurrentOffset(ObjectType.Chip);

            _bobConverter.ConvertBob(name, bob, definition.BobPlaneCount, bobPalette.Palette,
                                     _definition.BobPaletteFlip0AndLast ? BobMode.ColorFlip : BobMode.NoColorFlip, Destination.Disk);

            _items.Add(ItemTypes.Bob, name, offset);
        }
        private void ProcessPanel(GamePanelDefinition panel)
        {
            _writer.WriteCode(Code.Normal, $"LIVES_X\tequ\t{panel.Lives.X}");
            _writer.WriteCode(Code.Normal, $"LIVES_Y\tequ\t{panel.Lives.Y}");
            _writer.WriteCode(Code.Normal, $"LIVES_MAX\tequ\t{panel.Lives.Max}");
            _writer.WriteCode(Code.Normal, $"LIVES_START\tequ\t{panel.Lives.Start}");
            _writer.WriteCode(Code.Normal, $"LIVES_PIXEL_WIDTH\tequ\t{panel.Lives.Bob.Width}");
            _writer.WriteCode(Code.Normal, $"LIVES_PIXEL_HEIGHT\tequ\t{panel.Lives.Bob.Height}");

            var bobPalette = panel.Palette.FromInputFolder().LoadIndexedBitmap();

            _bobConverter.ConvertBob(
                "life",
                panel.Lives.Bob,
                panel.PlaneCount,
                bobPalette.Palette,
                BobMode.NoColorFlip,
                Destination.Executable);
        }
Esempio n. 3
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();
        }