finish spritesheet handling, hook up to makefile
This commit is contained in:
parent
b1554fda84
commit
35d7ba95b9
15
arena.c
15
arena.c
|
@ -25,19 +25,28 @@ void setupWallSprites() {
|
||||||
buildCompiledSprite(
|
buildCompiledSprite(
|
||||||
&sprite_arenaWallTop,
|
&sprite_arenaWallTop,
|
||||||
&arenaWallTop,
|
&arenaWallTop,
|
||||||
20, 20
|
SPRITE_ARENAWALLTOP_WIDTH,
|
||||||
|
SPRITE_ARENAWALLTOP_HEIGHT,
|
||||||
|
SPRITE_ARENAWALLTOP_OFFSET_X,
|
||||||
|
SPRITE_ARENAWALLTOP_OFFSET_Y
|
||||||
);
|
);
|
||||||
|
|
||||||
buildCompiledSprite(
|
buildCompiledSprite(
|
||||||
&sprite_arenaWallSide,
|
&sprite_arenaWallSide,
|
||||||
&arenaWallSide,
|
&arenaWallSide,
|
||||||
20, 20
|
SPRITE_ARENAWALLSIDE_WIDTH,
|
||||||
|
SPRITE_ARENAWALLSIDE_HEIGHT,
|
||||||
|
SPRITE_ARENAWALLSIDE_OFFSET_X,
|
||||||
|
SPRITE_ARENAWALLSIDE_OFFSET_Y
|
||||||
);
|
);
|
||||||
|
|
||||||
buildCompiledSprite(
|
buildCompiledSprite(
|
||||||
&sprite_arenaFloor,
|
&sprite_arenaFloor,
|
||||||
&arenaFloor,
|
&arenaFloor,
|
||||||
20, 20
|
SPRITE_ARENAFLOOR_WIDTH,
|
||||||
|
SPRITE_ARENAFLOOR_HEIGHT,
|
||||||
|
SPRITE_ARENAFLOOR_OFFSET_X,
|
||||||
|
SPRITE_ARENAFLOOR_OFFSET_Y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,10 @@ C_TEMPLATE = <<~C
|
||||||
|
|
||||||
<% sprites.each do |sprite| %>
|
<% sprites.each do |sprite| %>
|
||||||
extern void <%= sprite.function_name %>(byte *);
|
extern void <%= sprite.function_name %>(byte *);
|
||||||
|
<% sprite.constants.each do |constant, value| %>
|
||||||
|
#define <%= constant %> (<%= value %>)
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
// TODO: something with bounds checking here
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
C
|
C
|
||||||
|
@ -102,6 +103,17 @@ class AssemblerSprite
|
||||||
"#{@prefix}_#{@name}"
|
"#{@prefix}_#{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def constants
|
||||||
|
[
|
||||||
|
['WIDTH', @pixel_data[0].length],
|
||||||
|
['HEIGHT', @pixel_data.length],
|
||||||
|
['OFFSET_X', @offset_x],
|
||||||
|
['OFFSET_Y', @offset_y]
|
||||||
|
].map do |suffix, value|
|
||||||
|
["#{function_name.upcase}_#{suffix}", value]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def bytes
|
def bytes
|
||||||
return @bytes if defined?(@bytes)
|
return @bytes if defined?(@bytes)
|
||||||
|
|
||||||
|
|
55
game.c
55
game.c
|
@ -18,7 +18,7 @@
|
||||||
struct BMPImage spritesheetImage;
|
struct BMPImage spritesheetImage;
|
||||||
struct VGAColor vgaColors[256];
|
struct VGAColor vgaColors[256];
|
||||||
|
|
||||||
struct SpriteRender rabbit, mouse, bullet, enemy;
|
struct CompiledSpriteRender rabbit, mouse, bullet, enemy;
|
||||||
struct RabbitPosition rabbitPosition = {
|
struct RabbitPosition rabbitPosition = {
|
||||||
.rabbitPosition = { 60, 60 },
|
.rabbitPosition = { 60, 60 },
|
||||||
.rabbitLimits = { { 20, 20 }, { 180, 180 } },
|
.rabbitLimits = { { 20, 20 }, { 180, 180 } },
|
||||||
|
@ -162,40 +162,43 @@ void maybeSpawnEnemy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupEnemySprites() {
|
void setupEnemySprites() {
|
||||||
buildSpriteFromSpritesheet(
|
buildCompiledSprite(
|
||||||
&spritesheetImage,
|
&sprite_enemy,
|
||||||
&enemy,
|
&enemy,
|
||||||
0, 20, 16, 16
|
SPRITE_ENEMY_WIDTH,
|
||||||
|
SPRITE_ENEMY_HEIGHT,
|
||||||
|
SPRITE_ENEMY_OFFSET_X,
|
||||||
|
SPRITE_ENEMY_OFFSET_Y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupRabbitSprites() {
|
void setupRabbitSprites() {
|
||||||
buildSpriteFromSpritesheet(
|
buildCompiledSprite(
|
||||||
&spritesheetImage,
|
&sprite_rabbit,
|
||||||
&rabbit,
|
&rabbit,
|
||||||
0, 20, 16, 16
|
SPRITE_RABBIT_WIDTH,
|
||||||
|
SPRITE_RABBIT_HEIGHT,
|
||||||
|
SPRITE_RABBIT_OFFSET_X,
|
||||||
|
SPRITE_RABBIT_OFFSET_Y
|
||||||
);
|
);
|
||||||
|
|
||||||
rabbit.offsetX = 8;
|
buildCompiledSprite(
|
||||||
rabbit.offsetY = 15;
|
&sprite_mouse,
|
||||||
|
|
||||||
buildSpriteFromSpritesheet(
|
|
||||||
&spritesheetImage,
|
|
||||||
&mouse,
|
&mouse,
|
||||||
16, 20, 8, 8
|
SPRITE_MOUSE_WIDTH,
|
||||||
|
SPRITE_MOUSE_HEIGHT,
|
||||||
|
SPRITE_MOUSE_OFFSET_X,
|
||||||
|
SPRITE_MOUSE_OFFSET_Y
|
||||||
);
|
);
|
||||||
|
|
||||||
mouse.offsetX = 4;
|
buildCompiledSprite(
|
||||||
mouse.offsetY = 4;
|
&sprite_bullet,
|
||||||
|
|
||||||
buildSpriteFromSpritesheet(
|
|
||||||
&spritesheetImage,
|
|
||||||
&bullet,
|
&bullet,
|
||||||
16, 28, 4, 4
|
SPRITE_BULLET_WIDTH,
|
||||||
|
SPRITE_BULLET_HEIGHT,
|
||||||
|
SPRITE_BULLET_OFFSET_X,
|
||||||
|
SPRITE_BULLET_OFFSET_Y
|
||||||
);
|
);
|
||||||
|
|
||||||
bullet.offsetX = 1;
|
|
||||||
bullet.offsetY = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MouseStatus mouseStatus;
|
struct MouseStatus mouseStatus;
|
||||||
|
@ -204,7 +207,7 @@ void renderMouse() {
|
||||||
mouse.x = rabbitPosition.mousePosition[0];
|
mouse.x = rabbitPosition.mousePosition[0];
|
||||||
mouse.y = rabbitPosition.mousePosition[1];
|
mouse.y = rabbitPosition.mousePosition[1];
|
||||||
|
|
||||||
drawSprite(&mouse);
|
drawCompiledSprite(&mouse);
|
||||||
drawPixel(rabbitPosition.mouseDotPosition[0], rabbitPosition.mouseDotPosition[1], 2);
|
drawPixel(rabbitPosition.mouseDotPosition[0], rabbitPosition.mouseDotPosition[1], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +215,7 @@ void renderRabbit() {
|
||||||
rabbit.x = rabbitPosition.rabbitPosition[0];
|
rabbit.x = rabbitPosition.rabbitPosition[0];
|
||||||
rabbit.y = rabbitPosition.rabbitPosition[1];
|
rabbit.y = rabbitPosition.rabbitPosition[1];
|
||||||
|
|
||||||
drawSprite(&rabbit);
|
drawCompiledSprite(&rabbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderEnemies() {
|
void renderEnemies() {
|
||||||
|
@ -224,7 +227,7 @@ void renderEnemies() {
|
||||||
enemy.x = enemyPosition[i].enemyPosition[0];
|
enemy.x = enemyPosition[i].enemyPosition[0];
|
||||||
enemy.y = enemyPosition[i].enemyPosition[1];
|
enemy.y = enemyPosition[i].enemyPosition[1];
|
||||||
|
|
||||||
drawSprite(&enemy);
|
drawCompiledSprite(&enemy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +240,7 @@ void renderRabbitBullets() {
|
||||||
bullet.x = rabbitBulletPosition[i].x;
|
bullet.x = rabbitBulletPosition[i].x;
|
||||||
bullet.y = rabbitBulletPosition[i].y;
|
bullet.y = rabbitBulletPosition[i].y;
|
||||||
|
|
||||||
drawSprite(&bullet);
|
drawCompiledSprite(&bullet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
makefile
3
makefile
|
@ -13,6 +13,9 @@ system/system.lib: .SYMBOLIC
|
||||||
.asm.o:
|
.asm.o:
|
||||||
wasm $<
|
wasm $<
|
||||||
|
|
||||||
|
sprites.asm: sprtsht.bmp spritesheet.yml
|
||||||
|
bin/build_spritesheet_asm.rb
|
||||||
|
|
||||||
game.exe: $(obj) system/system.lib
|
game.exe: $(obj) system/system.lib
|
||||||
wcl386 -q -bt=dos -l=dos4g $(obj) system/system.lib
|
wcl386 -q -bt=dos -l=dos4g $(obj) system/system.lib
|
||||||
|
|
||||||
|
|
16
sprites.asm
16
sprites.asm
|
@ -1251,12 +1251,12 @@ sprite_rabbit_:
|
||||||
mov BYTE PTR [eax + -1921], 1
|
mov BYTE PTR [eax + -1921], 1
|
||||||
mov BYTE PTR [eax + -1920], 1
|
mov BYTE PTR [eax + -1920], 1
|
||||||
mov BYTE PTR [eax + -1602], 1
|
mov BYTE PTR [eax + -1602], 1
|
||||||
mov BYTE PTR [eax + -1601], 1
|
mov BYTE PTR [eax + -1601], 2
|
||||||
mov BYTE PTR [eax + -1600], 1
|
mov BYTE PTR [eax + -1600], 2
|
||||||
mov BYTE PTR [eax + -1599], 1
|
mov BYTE PTR [eax + -1599], 1
|
||||||
mov BYTE PTR [eax + -1282], 1
|
mov BYTE PTR [eax + -1282], 1
|
||||||
mov BYTE PTR [eax + -1281], 1
|
mov BYTE PTR [eax + -1281], 2
|
||||||
mov BYTE PTR [eax + -1280], 1
|
mov BYTE PTR [eax + -1280], 2
|
||||||
mov BYTE PTR [eax + -1279], 1
|
mov BYTE PTR [eax + -1279], 1
|
||||||
mov BYTE PTR [eax + -961], 1
|
mov BYTE PTR [eax + -961], 1
|
||||||
mov BYTE PTR [eax + -960], 1
|
mov BYTE PTR [eax + -960], 1
|
||||||
|
@ -1351,12 +1351,12 @@ sprite_enemy_:
|
||||||
mov BYTE PTR [eax + -1921], 1
|
mov BYTE PTR [eax + -1921], 1
|
||||||
mov BYTE PTR [eax + -1920], 1
|
mov BYTE PTR [eax + -1920], 1
|
||||||
mov BYTE PTR [eax + -1602], 1
|
mov BYTE PTR [eax + -1602], 1
|
||||||
mov BYTE PTR [eax + -1601], 1
|
mov BYTE PTR [eax + -1601], 2
|
||||||
mov BYTE PTR [eax + -1600], 1
|
mov BYTE PTR [eax + -1600], 2
|
||||||
mov BYTE PTR [eax + -1599], 1
|
mov BYTE PTR [eax + -1599], 1
|
||||||
mov BYTE PTR [eax + -1282], 1
|
mov BYTE PTR [eax + -1282], 1
|
||||||
mov BYTE PTR [eax + -1281], 1
|
mov BYTE PTR [eax + -1281], 2
|
||||||
mov BYTE PTR [eax + -1280], 1
|
mov BYTE PTR [eax + -1280], 2
|
||||||
mov BYTE PTR [eax + -1279], 1
|
mov BYTE PTR [eax + -1279], 1
|
||||||
mov BYTE PTR [eax + -961], 1
|
mov BYTE PTR [eax + -961], 1
|
||||||
mov BYTE PTR [eax + -960], 1
|
mov BYTE PTR [eax + -960], 1
|
||||||
|
|
63
sprites.h
63
sprites.h
|
@ -6,19 +6,80 @@
|
||||||
|
|
||||||
extern void sprite_arenaWallTop(byte *);
|
extern void sprite_arenaWallTop(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLTOP_WIDTH (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLTOP_HEIGHT (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLTOP_OFFSET_X (0)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLTOP_OFFSET_Y (0)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_arenaWallSide(byte *);
|
extern void sprite_arenaWallSide(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLSIDE_WIDTH (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLSIDE_HEIGHT (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLSIDE_OFFSET_X (0)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAWALLSIDE_OFFSET_Y (0)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_arenaFloor(byte *);
|
extern void sprite_arenaFloor(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_ARENAFLOOR_WIDTH (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAFLOOR_HEIGHT (20)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAFLOOR_OFFSET_X (0)
|
||||||
|
|
||||||
|
#define SPRITE_ARENAFLOOR_OFFSET_Y (0)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_rabbit(byte *);
|
extern void sprite_rabbit(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_RABBIT_WIDTH (16)
|
||||||
|
|
||||||
|
#define SPRITE_RABBIT_HEIGHT (16)
|
||||||
|
|
||||||
|
#define SPRITE_RABBIT_OFFSET_X (8)
|
||||||
|
|
||||||
|
#define SPRITE_RABBIT_OFFSET_Y (8)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_mouse(byte *);
|
extern void sprite_mouse(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_MOUSE_WIDTH (8)
|
||||||
|
|
||||||
|
#define SPRITE_MOUSE_HEIGHT (8)
|
||||||
|
|
||||||
|
#define SPRITE_MOUSE_OFFSET_X (4)
|
||||||
|
|
||||||
|
#define SPRITE_MOUSE_OFFSET_Y (4)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_bullet(byte *);
|
extern void sprite_bullet(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_BULLET_WIDTH (4)
|
||||||
|
|
||||||
|
#define SPRITE_BULLET_HEIGHT (4)
|
||||||
|
|
||||||
|
#define SPRITE_BULLET_OFFSET_X (1)
|
||||||
|
|
||||||
|
#define SPRITE_BULLET_OFFSET_Y (1)
|
||||||
|
|
||||||
|
|
||||||
extern void sprite_enemy(byte *);
|
extern void sprite_enemy(byte *);
|
||||||
|
|
||||||
|
#define SPRITE_ENEMY_WIDTH (16)
|
||||||
|
|
||||||
|
#define SPRITE_ENEMY_HEIGHT (16)
|
||||||
|
|
||||||
|
#define SPRITE_ENEMY_OFFSET_X (8)
|
||||||
|
|
||||||
|
#define SPRITE_ENEMY_OFFSET_Y (8)
|
||||||
|
|
||||||
|
|
||||||
// TODO: something with bounds checking here
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
BIN
spritesheet.xcf
BIN
spritesheet.xcf
Binary file not shown.
BIN
sprtsht.bmp
BIN
sprtsht.bmp
Binary file not shown.
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
@ -54,11 +54,15 @@ void buildCompiledSprite(
|
||||||
void (*code)(byte *),
|
void (*code)(byte *),
|
||||||
struct CompiledSpriteRender *compiledSpriteRender,
|
struct CompiledSpriteRender *compiledSpriteRender,
|
||||||
int width,
|
int width,
|
||||||
int height
|
int height,
|
||||||
|
int offsetX,
|
||||||
|
int offsetY
|
||||||
) {
|
) {
|
||||||
compiledSpriteRender->code = code;
|
compiledSpriteRender->code = code;
|
||||||
compiledSpriteRender->width = width;
|
compiledSpriteRender->width = width;
|
||||||
compiledSpriteRender->height = height;
|
compiledSpriteRender->height = height;
|
||||||
|
compiledSpriteRender->offsetX = offsetX;
|
||||||
|
compiledSpriteRender->offsetY = offsetY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPixel(int x, int y, int color) {
|
void drawPixel(int x, int y, int color) {
|
||||||
|
@ -101,7 +105,7 @@ void drawCompiledSprite(struct CompiledSpriteRender* compiledSprite) {
|
||||||
compiledSprite->code(drawBufferPos);
|
compiledSprite->code(drawBufferPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds) {
|
void getSpriteBounds(struct CompiledSpriteRender *sprite, struct SpriteBounds *bounds) {
|
||||||
bounds->top = sprite->y - sprite->offsetY;
|
bounds->top = sprite->y - sprite->offsetY;
|
||||||
bounds->bottom = bounds->top + sprite->height;
|
bounds->bottom = bounds->top + sprite->height;
|
||||||
|
|
||||||
|
|
11
system/vga.h
11
system/vga.h
|
@ -34,6 +34,8 @@ struct CompiledSpriteRender {
|
||||||
int y;
|
int y;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
int offsetX;
|
||||||
|
int offsetY;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SpriteBounds {
|
struct SpriteBounds {
|
||||||
|
@ -48,8 +50,13 @@ void drawPixel(int x, int y, int color);
|
||||||
void drawSprite(struct SpriteRender *sprite);
|
void drawSprite(struct SpriteRender *sprite);
|
||||||
void drawCompiledSprite(struct CompiledSpriteRender *compiledSprite);
|
void drawCompiledSprite(struct CompiledSpriteRender *compiledSprite);
|
||||||
void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int);
|
void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int);
|
||||||
void buildCompiledSprite(void (*)(byte *), struct CompiledSpriteRender*, int width, int height);
|
void buildCompiledSprite(
|
||||||
void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds);
|
void (*)(byte *),
|
||||||
|
struct CompiledSpriteRender*,
|
||||||
|
int width, int height,
|
||||||
|
int offsetX, int offsetY
|
||||||
|
);
|
||||||
|
void getSpriteBounds(struct CompiledSpriteRender *sprite, struct SpriteBounds *bounds);
|
||||||
|
|
||||||
byte *initializeDrawBuffer();
|
byte *initializeDrawBuffer();
|
||||||
byte *getDrawBuffer();
|
byte *getDrawBuffer();
|
||||||
|
|
Loading…
Reference in New Issue