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(
|
||||
&sprite_arenaWallTop,
|
||||
&arenaWallTop,
|
||||
20, 20
|
||||
SPRITE_ARENAWALLTOP_WIDTH,
|
||||
SPRITE_ARENAWALLTOP_HEIGHT,
|
||||
SPRITE_ARENAWALLTOP_OFFSET_X,
|
||||
SPRITE_ARENAWALLTOP_OFFSET_Y
|
||||
);
|
||||
|
||||
buildCompiledSprite(
|
||||
&sprite_arenaWallSide,
|
||||
&arenaWallSide,
|
||||
20, 20
|
||||
SPRITE_ARENAWALLSIDE_WIDTH,
|
||||
SPRITE_ARENAWALLSIDE_HEIGHT,
|
||||
SPRITE_ARENAWALLSIDE_OFFSET_X,
|
||||
SPRITE_ARENAWALLSIDE_OFFSET_Y
|
||||
);
|
||||
|
||||
buildCompiledSprite(
|
||||
&sprite_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| %>
|
||||
extern void <%= sprite.function_name %>(byte *);
|
||||
<% sprite.constants.each do |constant, value| %>
|
||||
#define <%= constant %> (<%= value %>)
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
// TODO: something with bounds checking here
|
||||
|
||||
#endif
|
||||
C
|
||||
|
@ -102,6 +103,17 @@ class AssemblerSprite
|
|||
"#{@prefix}_#{@name}"
|
||||
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
|
||||
return @bytes if defined?(@bytes)
|
||||
|
||||
|
|
55
game.c
55
game.c
|
@ -18,7 +18,7 @@
|
|||
struct BMPImage spritesheetImage;
|
||||
struct VGAColor vgaColors[256];
|
||||
|
||||
struct SpriteRender rabbit, mouse, bullet, enemy;
|
||||
struct CompiledSpriteRender rabbit, mouse, bullet, enemy;
|
||||
struct RabbitPosition rabbitPosition = {
|
||||
.rabbitPosition = { 60, 60 },
|
||||
.rabbitLimits = { { 20, 20 }, { 180, 180 } },
|
||||
|
@ -162,40 +162,43 @@ void maybeSpawnEnemy() {
|
|||
}
|
||||
|
||||
void setupEnemySprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
buildCompiledSprite(
|
||||
&sprite_enemy,
|
||||
&enemy,
|
||||
0, 20, 16, 16
|
||||
SPRITE_ENEMY_WIDTH,
|
||||
SPRITE_ENEMY_HEIGHT,
|
||||
SPRITE_ENEMY_OFFSET_X,
|
||||
SPRITE_ENEMY_OFFSET_Y
|
||||
);
|
||||
}
|
||||
|
||||
void setupRabbitSprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
buildCompiledSprite(
|
||||
&sprite_rabbit,
|
||||
&rabbit,
|
||||
0, 20, 16, 16
|
||||
SPRITE_RABBIT_WIDTH,
|
||||
SPRITE_RABBIT_HEIGHT,
|
||||
SPRITE_RABBIT_OFFSET_X,
|
||||
SPRITE_RABBIT_OFFSET_Y
|
||||
);
|
||||
|
||||
rabbit.offsetX = 8;
|
||||
rabbit.offsetY = 15;
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
buildCompiledSprite(
|
||||
&sprite_mouse,
|
||||
&mouse,
|
||||
16, 20, 8, 8
|
||||
SPRITE_MOUSE_WIDTH,
|
||||
SPRITE_MOUSE_HEIGHT,
|
||||
SPRITE_MOUSE_OFFSET_X,
|
||||
SPRITE_MOUSE_OFFSET_Y
|
||||
);
|
||||
|
||||
mouse.offsetX = 4;
|
||||
mouse.offsetY = 4;
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
buildCompiledSprite(
|
||||
&sprite_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;
|
||||
|
@ -204,7 +207,7 @@ void renderMouse() {
|
|||
mouse.x = rabbitPosition.mousePosition[0];
|
||||
mouse.y = rabbitPosition.mousePosition[1];
|
||||
|
||||
drawSprite(&mouse);
|
||||
drawCompiledSprite(&mouse);
|
||||
drawPixel(rabbitPosition.mouseDotPosition[0], rabbitPosition.mouseDotPosition[1], 2);
|
||||
}
|
||||
|
||||
|
@ -212,7 +215,7 @@ void renderRabbit() {
|
|||
rabbit.x = rabbitPosition.rabbitPosition[0];
|
||||
rabbit.y = rabbitPosition.rabbitPosition[1];
|
||||
|
||||
drawSprite(&rabbit);
|
||||
drawCompiledSprite(&rabbit);
|
||||
}
|
||||
|
||||
void renderEnemies() {
|
||||
|
@ -224,7 +227,7 @@ void renderEnemies() {
|
|||
enemy.x = enemyPosition[i].enemyPosition[0];
|
||||
enemy.y = enemyPosition[i].enemyPosition[1];
|
||||
|
||||
drawSprite(&enemy);
|
||||
drawCompiledSprite(&enemy);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +240,7 @@ void renderRabbitBullets() {
|
|||
bullet.x = rabbitBulletPosition[i].x;
|
||||
bullet.y = rabbitBulletPosition[i].y;
|
||||
|
||||
drawSprite(&bullet);
|
||||
drawCompiledSprite(&bullet);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
makefile
3
makefile
|
@ -13,6 +13,9 @@ system/system.lib: .SYMBOLIC
|
|||
.asm.o:
|
||||
wasm $<
|
||||
|
||||
sprites.asm: sprtsht.bmp spritesheet.yml
|
||||
bin/build_spritesheet_asm.rb
|
||||
|
||||
game.exe: $(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 + -1920], 1
|
||||
mov BYTE PTR [eax + -1602], 1
|
||||
mov BYTE PTR [eax + -1601], 1
|
||||
mov BYTE PTR [eax + -1600], 1
|
||||
mov BYTE PTR [eax + -1601], 2
|
||||
mov BYTE PTR [eax + -1600], 2
|
||||
mov BYTE PTR [eax + -1599], 1
|
||||
mov BYTE PTR [eax + -1282], 1
|
||||
mov BYTE PTR [eax + -1281], 1
|
||||
mov BYTE PTR [eax + -1280], 1
|
||||
mov BYTE PTR [eax + -1281], 2
|
||||
mov BYTE PTR [eax + -1280], 2
|
||||
mov BYTE PTR [eax + -1279], 1
|
||||
mov BYTE PTR [eax + -961], 1
|
||||
mov BYTE PTR [eax + -960], 1
|
||||
|
@ -1351,12 +1351,12 @@ sprite_enemy_:
|
|||
mov BYTE PTR [eax + -1921], 1
|
||||
mov BYTE PTR [eax + -1920], 1
|
||||
mov BYTE PTR [eax + -1602], 1
|
||||
mov BYTE PTR [eax + -1601], 1
|
||||
mov BYTE PTR [eax + -1600], 1
|
||||
mov BYTE PTR [eax + -1601], 2
|
||||
mov BYTE PTR [eax + -1600], 2
|
||||
mov BYTE PTR [eax + -1599], 1
|
||||
mov BYTE PTR [eax + -1282], 1
|
||||
mov BYTE PTR [eax + -1281], 1
|
||||
mov BYTE PTR [eax + -1280], 1
|
||||
mov BYTE PTR [eax + -1281], 2
|
||||
mov BYTE PTR [eax + -1280], 2
|
||||
mov BYTE PTR [eax + -1279], 1
|
||||
mov BYTE PTR [eax + -961], 1
|
||||
mov BYTE PTR [eax + -960], 1
|
||||
|
|
63
sprites.h
63
sprites.h
|
@ -6,19 +6,80 @@
|
|||
|
||||
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 *);
|
||||
|
||||
#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 *);
|
||||
|
||||
#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 *);
|
||||
|
||||
#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 *);
|
||||
|
||||
#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 *);
|
||||
|
||||
#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 *);
|
||||
|
||||
#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
|
||||
|
|
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 *),
|
||||
struct CompiledSpriteRender *compiledSpriteRender,
|
||||
int width,
|
||||
int height
|
||||
int height,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
compiledSpriteRender->code = code;
|
||||
compiledSpriteRender->width = width;
|
||||
compiledSpriteRender->height = height;
|
||||
compiledSpriteRender->offsetX = offsetX;
|
||||
compiledSpriteRender->offsetY = offsetY;
|
||||
}
|
||||
|
||||
void drawPixel(int x, int y, int color) {
|
||||
|
@ -101,7 +105,7 @@ void drawCompiledSprite(struct CompiledSpriteRender* compiledSprite) {
|
|||
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->bottom = bounds->top + sprite->height;
|
||||
|
||||
|
|
11
system/vga.h
11
system/vga.h
|
@ -34,6 +34,8 @@ struct CompiledSpriteRender {
|
|||
int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
};
|
||||
|
||||
struct SpriteBounds {
|
||||
|
@ -48,8 +50,13 @@ void drawPixel(int x, int y, int color);
|
|||
void drawSprite(struct SpriteRender *sprite);
|
||||
void drawCompiledSprite(struct CompiledSpriteRender *compiledSprite);
|
||||
void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int);
|
||||
void buildCompiledSprite(void (*)(byte *), struct CompiledSpriteRender*, int width, int height);
|
||||
void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds);
|
||||
void buildCompiledSprite(
|
||||
void (*)(byte *),
|
||||
struct CompiledSpriteRender*,
|
||||
int width, int height,
|
||||
int offsetX, int offsetY
|
||||
);
|
||||
void getSpriteBounds(struct CompiledSpriteRender *sprite, struct SpriteBounds *bounds);
|
||||
|
||||
byte *initializeDrawBuffer();
|
||||
byte *getDrawBuffer();
|
||||
|
|
Loading…
Reference in New Issue