Example #1
0
        public SurfaceFontSheet CreateFontSheet(AssetFontSheet asset)
        {
            switch (asset.FontType)
            {
            case FontTypes.PolychromeStatic:
                return(CreateFontSheetPolyChromeStatic(asset));

            case FontTypes.MonochromeDynamic:
                return(CreateFontSheetMonoChromeDynamic(asset));
            }

            throw new Exception("The fontType is unknown !");
        }
Example #2
0
        public SurfaceFontSheet CreateFontSheetPolyChromeStatic(AssetFontSheet asset)
        {
            if (asset.FontType != FontTypes.PolychromeStatic)
            {
                throw new Exception("The asset is not of type PolyChromeStatic!");
            }

            var font = new SurfaceFontSheet();

            var address = ReserveEmptySprite(font, asset.Name, asset.Width, asset.Height);

            font.Initialize(this.Pixels, address, asset.FontType, asset.Width, asset.Height, asset.TileWidth, asset.TileHeight, asset.MapHeightBank, asset.BankCount);
            // Copier les pixels de Asset et les mettre à l'address reservé
            this.Copy(asset.Pixels, 0, 0, font.AddressBank0);

            return(font);
        }
Example #3
0
        public SurfaceFontSheet CreateFontSheetMonoChromeDynamic(AssetFontSheet asset, params Argb32[] monoChromeDynamicFontColors)
        {
            if (asset.FontType != FontTypes.MonochromeDynamic)
            {
                throw new Exception("The asset is not of type MonoChromeDynamic!");
            }

            if (monoChromeDynamicFontColors.Length == 0)
            {
                monoChromeDynamicFontColors = asset.BankColors;
            }

            var font = new SurfaceFontSheet();

            var address            = ReserveEmptySprite(font, asset.Name, asset.Width, asset.Height * monoChromeDynamicFontColors.Length);
            var addressDestination = address;

            for (int bankNumber = 0; bankNumber < monoChromeDynamicFontColors.Length; bankNumber++)
            {
                var color = monoChromeDynamicFontColors[bankNumber];

                for (int index = 0; index < asset.Pixels.Length; index++)
                {
                    var pixel = asset.Pixels[index];

                    if (pixel.IsTransparent)
                    {
                        this.Pixels[addressDestination] = pixel;
                    }
                    else
                    {
                        this.Pixels[addressDestination] = color;
                    }

                    addressDestination++;
                }
            }

            font.Initialize(this.Pixels, address, asset.FontType, asset.Width, asset.Height * monoChromeDynamicFontColors.Length, asset.TileWidth, asset.TileHeight, asset.MapHeightBank, monoChromeDynamicFontColors.Length);

            return(font);
        }
Example #4
0
        /// <summary>
        /// Start the console
        /// </summary>
        /// <param name="machine"></param>
        /// <returns></returns>

        public override async Task StartAsync(Machine machine)
        {
            this.machine = machine;

            // loading some assets and put them in the video memory of the console
            var assetSprite = AssetSprite.Import(this, "sprite", await LoadContentFile("Game/Sprite.png"));

            this.sprite = this.machine.VideoMemory.CreateSprite(assetSprite);

            // tilesheet is composed of tiles of 8x8 pixels
            // tilesheet is a sprite too

            var assetTileSheet = AssetTileSheet.Import(this, "tilesheet", await LoadContentFile("Game/TileSheet.png"), 8, 8);

            this.tileSheet = this.machine.VideoMemory.CreateTileSheet(assetTileSheet);

            // Read the font file and create an AssetFontSheet
            var assetFont = AssetFontSheet.Import(this, "font", await LoadContentFile("Game/Font.png"), 8, 8, FontTypes.PolychromeStatic);
            // Copy the AssetFontSheet to the VideMemory
            var surfaceFont = machine.VideoMemory.CreateFontSheet(assetFont);

            // Get the mapping of the font based on FontSheet/surfaceFont
            Font font = new Font
            {
                FontSheet = surfaceFont
            };

            font.AddCharacters(CharactersGroups.AlphaUpperAndLower);
            font.AddCharacters(CharactersGroups.Numeric);
            font.AddCharacters(".,\"'?!@*#$%: ");
            font.CharacterIndex += 5;                         // Jump blank characters
            font.AddCharacters("()+-/=©<>~§");                //~ correspond to the save icon (disk), § to the heart icon
            font.UnknownTileNumber = font.GetTileNumber('$'); // by default an unknown character will be represent by a $

            // set the default font of the Screen
            this.machine.Screen.Font = font;

            // create map of a coin
            this.mapCoin = new Map();
            this.mapCoin.Create("mapCoin", 2, 2, tileSheet);
            this.mapCoin.SetTiles(110, 111, 120, 121);

            // create map of the slice of a coin
            this.mapCoinSlice = new Map();
            this.mapCoinSlice.Create("mapCoinSlice", 2, 2, tileSheet);
            this.mapCoinSlice.SetTiles(112, 113, 122, 123);

            // animator
            this.animatorCoin = new Animator();
            this.animatorCoin.Initialize(
                new MapAnimationFrame(mapCoin, 10),     // change every 10 frames
                new MapAnimationFrame(mapCoinSlice, 10) // change every 10 frames
                );
            // launch the animator
            this.animatorCoin.Play();

            // small screen
            this.smallScreen      = this.machine.VideoMemory.CreateEmptySprite("smallScreen", 50, 50);
            this.smallScreen.Font = font;

            machine.UpdatingCallback = Updating;
            machine.UpdatedCallback  = Updated;
            // Method where the game renders one frame
            machine.DrawCallback = Draw;
        }