public SurfaceTileSheet CreateTileSheet(AssetTileSheet asset) { var tileSheet = new SurfaceTileSheet(); var address = ReserveEmptySprite(tileSheet, asset.Name, asset.Width, asset.Height); tileSheet.Initialize(this.Pixels, address, asset.Width, asset.Height, asset.TileWidth, asset.TileHeight); // Copier les pixels de Asset et les mettre à l'address reservé this.Copy(asset.Pixels, 0, 0, tileSheet.Address); return(tileSheet); }
/// <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; }