no more bitmap loading

This commit is contained in:
John Bintz 2024-02-28 21:07:35 -05:00
parent dd52b6da67
commit dd4fdad4be
3 changed files with 56 additions and 11 deletions

View File

@ -60,11 +60,18 @@ ASM_TEMPLATE = <<~ASM
end
ASM
C_TEMPLATE = <<~C
H_TEMPLATE = <<~H
#ifndef __SPRITES_H__
#define __SPRITES_H__
#include "types.h"
#include "system/vga.h"
#define PALETTE_COLOR_COUNT (<%= palette.length %>)
struct VGAColor palette[<%= palette.length %>] = {
<%= palette.map(&:to_struct).join(",\n") %>
};
<% sprites.each do |sprite| %>
extern void <%= sprite.function_name %>(byte *);
@ -74,7 +81,7 @@ C_TEMPLATE = <<~C
<% end %>
#endif
C
H
class AssemblerSprite
def initialize(
@ -144,9 +151,29 @@ screen = Screen.new(
sprite_data = []
palette = nil
VGAColor = Data.define(:red, :green, :blue) do
def to_struct
"{ #{red}, #{green}, #{blue} }"
end
end
data["files"].each do |spritesheet|
image = Magick::Image.read(spritesheet["file"]).first
unless palette
palette = image.colors.times.map do |i|
pixel = Magick::Pixel.from_color(image.colormap(i))
VGAColor.new(
red: pixel.red >> 10,
green: pixel.green >> 10,
blue: pixel.blue >> 10
)
end
end
spritesheet["sprites"].each do |name, details|
sprite_data << SpriteData.new(
image:,
@ -179,12 +206,13 @@ sprites = sprite_data.map do |sd|
)
end
File.open('sprites.asm', 'w') do |fh|
fh.puts ERB.new(ASM_TEMPLATE).result_with_hash(sprites:)
end
File.open('sprites.h', 'w') do |fh|
fh.puts ERB.new(C_TEMPLATE).result_with_hash(sprites:)
fh.puts ERB.new(H_TEMPLATE).result_with_hash(sprites:, palette:)
end
puts "sprites.{asm,h} written"

10
game.c
View File

@ -368,12 +368,6 @@ int setupGame() {
installKeyboardHandler();
initializeDrawBuffer();
fh = fopen("sprtsht.bmp", "rb");
if (readBMPIntoNewMemory(fh, &spritesheetImage)) return 1;
fclose(fh);
spritesheetImage.transparentColor = 0;
setupWallSprites();
setupRabbitSprites();
setupRabbitBullets();
@ -384,8 +378,8 @@ int setupGame() {
setupPowerupSprites();
setVideoMode(VIDEO_MODE_VGA_256);
bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors);
setVGAColors(vgaColors, 256);
setVGAColors(palette, PALETTE_COLOR_COUNT);
activateMouse(&mouseStatus);

View File

@ -2,6 +2,29 @@
#define __SPRITES_H__
#include "types.h"
#include "system/vga.h"
#define PALETTE_COLOR_COUNT (17)
struct VGAColor palette[17] = {
{ 63, 0, 63 },
{ 0, 0, 0 },
{ 15, 16, 49 },
{ 16, 16, 33 },
{ 16, 16, 16 },
{ 63, 63, 63 },
{ 38, 31, 12 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 }
};
extern void sprite_arenaWallTop(byte *);