Skip to content

Commit

Permalink
Generate bitmap with YEAR message
Browse files Browse the repository at this point in the history
  • Loading branch information
tvasenin committed Nov 19, 2017
1 parent bc21085 commit 4d0e74b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Pre2/AssetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hjg.Pngcs.Chunks;
using System;
using System.IO;
using System.Text;
using System.Xml;
using Tilengine;

Expand Down Expand Up @@ -39,6 +40,7 @@ public static class AssetConverter
private static readonly SpriteInfo BackgroundInfo = new SpriteInfo { W = 320, H = 200 };
private static readonly SpriteInfo MapInfo = new SpriteInfo { W = 640, H = 200 };

private static readonly byte[] FontYearDevsCharCodes = Encoding.ASCII.GetBytes("0123456789!?.$_ABCDEFGHIJKLMNOPQRSTUVWXYZ");
private static readonly SpriteInfo FontYearDevsInfo = new SpriteInfo { W = 8, H = 12 };
private static readonly SpriteInfo PanelSpritesInfo = new SpriteInfo { W = 16, H = 12 };
private static readonly SpriteInfo FontUnknownInfo = new SpriteInfo { W = 16, H = 11 };
Expand Down Expand Up @@ -141,6 +143,40 @@ public static Tilemap GetLevelTilemap(int levelIdx)
return GenerateLevelTilemap(rawData, numRows, palette);
}

public static Bitmap GetYearBitmap()
{
int width = BackgroundInfo.W;
int height = BackgroundInfo.H;
byte[] image = new byte[width * height];
int year = DateTime.Now.Year;
if (year >= 1996 && year < 2067) // sic!
{
DrawYearLine(image, 5, 5, "YEAAA . . .");
DrawYearLine(image, 6, 0, "MY GAME IS STILL WORKING IN " + year + " !!");
DrawYearLine(image, 12, 1, "PROGRAMMED IN 1992 ON AT .286 12MHZ.");
DrawYearLine(image, 13, 3, ". . . ENJOY OLDIES!!");
}
Palette palette = GetPalette(File.ReadAllBytes(Path.Combine(ResDir, "year_devs.pal")));
Bitmap bitmap = new Bitmap(width, height, 8) { PixelData = image, Palette = palette };
return bitmap;
}

private static void DrawYearLine(byte[] image, int row, int col, string textLine)
{
byte[] asciiBytes = Encoding.ASCII.GetBytes(textLine);
foreach (byte c in asciiBytes)
{
int idx = Array.IndexOf(FontYearDevsCharCodes, c);
if (idx != -1)
{
int dstX = col * FontYearDevsInfo.W;
int dstY = row * FontYearDevsInfo.H;
CopyPixels(FontYearDevs[idx], FontYearDevsInfo, image, BackgroundInfo.W, dstX, dstY);
}
col++;
}
}

private static void UnpackTrk(string resource)
{
string destFilename = Path.Combine(SoundDir, resource + ".mod");
Expand Down Expand Up @@ -391,10 +427,8 @@ private static Tilemap GenerateLevelTilemap(byte[] rawData, int numRows, Palette

private static void ConvertAllFonts()
{
byte[] palYearDevs = File.ReadAllBytes(Path.Combine(ResDir, "year_devs.pal"));
byte[] palDefault = LevelPalettes[0];

GenerateTileSet(FontYearDevs, palYearDevs, FontYearDevs.Length, FontYearDevsInfo, CacheDir, "FontYearDevs");
WritePng8(Path.Combine(CacheDir, "panel.png"), PanelImage, palDefault, PanelImageInfo);
GenerateTileSet(PanelSprites, palDefault, PanelSprites.Length, PanelSpritesInfo, CacheDir, "PanelSprites");
GenerateTileSet(FontUnknown, palDefault, FontUnknown.Length, FontUnknownInfo, CacheDir, "FontUnknown");
Expand Down

0 comments on commit 4d0e74b

Please sign in to comment.