dos-vga-arena-shooter-game/arena.c

130 lines
2.7 KiB
C
Raw Normal View History

2024-02-20 17:51:59 +00:00
#include "bmpload.h"
#include "const.h"
#include "arena.h"
2024-02-24 02:29:36 +00:00
#include "system/vga.h"
2024-02-20 17:51:59 +00:00
2024-02-24 12:36:18 +00:00
#include "sprites.h"
#include <stdlib.h>
2024-02-20 17:51:59 +00:00
char arenaLayout[10][10] = {
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
2024-02-24 02:29:36 +00:00
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2024-02-20 17:51:59 +00:00
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }
};
2024-02-24 12:36:18 +00:00
struct CompiledSpriteRender arenaWallTop, arenaWallSide, arenaFloor;
2024-02-20 17:51:59 +00:00
2024-02-24 12:36:18 +00:00
void setupWallSprites() {
buildCompiledSprite(
&sprite_arenaWallTop,
2024-02-20 17:51:59 +00:00
&arenaWallTop,
SPRITE_ARENAWALLTOP_WIDTH,
SPRITE_ARENAWALLTOP_HEIGHT,
SPRITE_ARENAWALLTOP_OFFSET_X,
SPRITE_ARENAWALLTOP_OFFSET_Y
2024-02-20 17:51:59 +00:00
);
2024-02-24 12:36:18 +00:00
buildCompiledSprite(
&sprite_arenaWallSide,
2024-02-20 17:51:59 +00:00
&arenaWallSide,
SPRITE_ARENAWALLSIDE_WIDTH,
SPRITE_ARENAWALLSIDE_HEIGHT,
SPRITE_ARENAWALLSIDE_OFFSET_X,
SPRITE_ARENAWALLSIDE_OFFSET_Y
2024-02-20 17:51:59 +00:00
);
2024-02-24 12:36:18 +00:00
buildCompiledSprite(
&sprite_arenaFloor,
2024-02-20 17:51:59 +00:00
&arenaFloor,
SPRITE_ARENAFLOOR_WIDTH,
SPRITE_ARENAFLOOR_HEIGHT,
SPRITE_ARENAFLOOR_OFFSET_X,
SPRITE_ARENAFLOOR_OFFSET_Y
2024-02-20 17:51:59 +00:00
);
}
2024-02-24 12:36:18 +00:00
byte *drawBuffer;
2024-02-24 02:29:36 +00:00
2024-02-20 17:51:59 +00:00
void renderArenaTile(int x, int y) {
char tile;
2024-02-24 12:36:18 +00:00
struct CompiledSpriteRender *target;
drawBuffer = getDrawBuffer();
2024-02-20 17:51:59 +00:00
tile = arenaLayout[y][x];
switch (tile) {
case 0:
target = &arenaFloor;
break;
case 1:
target = &arenaWallTop;
break;
case 2:
target = &arenaWallSide;
break;
}
2024-02-21 21:25:00 +00:00
target->x = x * TILE_SIZE;
target->y = y * TILE_SIZE;
2024-02-20 17:51:59 +00:00
2024-02-24 12:36:18 +00:00
drawCompiledSprite(target);
2024-02-20 17:51:59 +00:00
}
2024-02-21 13:25:55 +00:00
char arenaRedrawRequests[ARENA_HEIGHT_TILES][ARENA_WIDTH_TILES];
void clearArenaRedrawRequests() {
int x, y;
for (y = 0; y < ARENA_HEIGHT_TILES; ++y) {
for (x = 0; x < ARENA_WIDTH_TILES; ++x) {
arenaRedrawRequests[y][x] = 0;
}
}
}
void redrawArena() {
int x, y;
for (y = 0; y < ARENA_HEIGHT_TILES; ++y) {
for (x = 0; x < ARENA_WIDTH_TILES; ++x) {
if (arenaRedrawRequests[y][x]) {
renderArenaTile(x, y);
arenaRedrawRequests[y][x] = 0;
}
}
}
}
2024-02-20 17:51:59 +00:00
void drawOnlyArena(struct SpriteBounds *bounds) {
int leftTileX, rightTileX,
topTileY, bottomTileY;
leftTileX = bounds->left / TILE_SIZE;
rightTileX = bounds->right / TILE_SIZE;
topTileY = bounds->top / TILE_SIZE;
bottomTileY = bounds->bottom / TILE_SIZE;
2024-02-21 13:25:55 +00:00
arenaRedrawRequests[topTileY][leftTileX] = 1;
arenaRedrawRequests[topTileY][rightTileX] = 1;
arenaRedrawRequests[bottomTileY][leftTileX] = 1;
arenaRedrawRequests[bottomTileY][rightTileX] = 1;
2024-02-20 17:51:59 +00:00
}
void buildArena() {
int x, y;
for (y = 0; y < 10; ++y) {
for (x = 0; x < 10; ++x) {
renderArenaTile(x, y);
}
}
}