diff --git a/arena.c b/arena.c new file mode 100644 index 0000000..5f4efd2 --- /dev/null +++ b/arena.c @@ -0,0 +1,87 @@ +#include "bmpload.h" +#include "const.h" +#include "arena.h" + +char arenaLayout[10][10] = { + { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }, + { 1, 2, 2, 2, 0, 0, 2, 2, 2, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 2, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, + { 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 } +}; + +struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor; + +void setupWallSprites(struct BMPImage *spritesheetImage) { + buildSpriteFromSpritesheet( + spritesheetImage, + &arenaWallTop, + 0, 0, 20, 20 + ); + + buildSpriteFromSpritesheet( + spritesheetImage, + &arenaWallSide, + 20, 0, 20, 20 + ); + + buildSpriteFromSpritesheet( + spritesheetImage, + &arenaFloor, + 40, 0, 20, 20 + ); +} + +void renderArenaTile(int x, int y) { + char tile; + struct SpriteRender *target; + + tile = arenaLayout[y][x]; + + switch (tile) { + case 0: + target = &arenaFloor; + break; + case 1: + target = &arenaWallTop; + break; + case 2: + target = &arenaWallSide; + break; + } + + target->x = x * 20; + target->y = y * 20; + + drawSprite(target); +} + +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; + + renderArenaTile(leftTileX, topTileY); + renderArenaTile(rightTileX, topTileY); + renderArenaTile(rightTileX, bottomTileY); + renderArenaTile(leftTileX, bottomTileY); +} + +void buildArena() { + int x, y; + + for (y = 0; y < 10; ++y) { + for (x = 0; x < 10; ++x) { + renderArenaTile(x, y); + } + } +} diff --git a/arena.h b/arena.h new file mode 100644 index 0000000..1fd49ff --- /dev/null +++ b/arena.h @@ -0,0 +1,6 @@ +#include "bmpload.h" +#include "system/vga.h" + +void drawOnlyArena(struct SpriteBounds *bounds); +void buildArena(); +void setupWallSprites(struct BMPImage *); diff --git a/const.h b/const.h index e69de29..6224111 100644 --- a/const.h +++ b/const.h @@ -0,0 +1,5 @@ +#define TILE_SIZE (20) +#define RAD2DEG (180/3.14159) +#define DEG2RAD (3.14159/180) +#define MOUSE_DISTANCE (32) + diff --git a/game.c b/game.c index 03ce7d8..9f742a4 100644 --- a/game.c +++ b/game.c @@ -7,33 +7,14 @@ #include "system/mouse_io.h" #include "system/pc_stuff.h" #include "bmpload.h" +#include "const.h" +#include "arena.h" struct BMPImage spritesheetImage; struct VGAColor vgaColors[256]; -struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor; struct SpriteRender rabbit, mouse; -void setupWallSprites() { - buildSpriteFromSpritesheet( - &spritesheetImage, - &arenaWallTop, - 0, 0, 20, 20 - ); - - buildSpriteFromSpritesheet( - &spritesheetImage, - &arenaWallSide, - 20, 0, 20, 20 - ); - - buildSpriteFromSpritesheet( - &spritesheetImage, - &arenaFloor, - 40, 0, 20, 20 - ); -} - void setupRabbitSprites() { buildSpriteFromSpritesheet( &spritesheetImage, @@ -54,52 +35,6 @@ void setupRabbitSprites() { mouse.offsetY = 4; } -char arenaLayout[10][10] = { - { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }, - { 1, 2, 2, 2, 0, 0, 2, 2, 2, 1 }, - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, - { 2, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, - { 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 } -}; - -void renderArenaTile(int x, int y) { - char tile; - struct SpriteRender *target; - - tile = arenaLayout[y][x]; - - switch (tile) { - case 0: - target = &arenaFloor; - break; - case 1: - target = &arenaWallTop; - break; - case 2: - target = &arenaWallSide; - break; - } - - target->x = x * 20; - target->y = y * 20; - - drawSprite(target); -} - -void buildArena() { - int x, y; - - for (y = 0; y < 10; ++y) { - for (x = 0; x < 10; ++x) { - renderArenaTile(x, y); - } - } -} #define RABBIT_MOTION_DRAG (2) #define RABBIT_MOTION_ACCELERATION (5) @@ -186,75 +121,26 @@ void handleRabbitMovement() { } } -#define TILE_SIZE (20) - struct SpriteBounds bounds; -char tileRenderQueue[400]; - -void drawOnlyArena() { - 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; - - renderArenaTile(leftTileX, topTileY); - renderArenaTile(rightTileX, topTileY); - renderArenaTile(rightTileX, bottomTileY); - renderArenaTile(leftTileX, bottomTileY); -} - void drawOnlyMouseArena() { mouse.x = oldMousePosition[0]; mouse.y = oldMousePosition[1]; getSpriteBounds(&mouse, &bounds); - drawOnlyArena(); + drawOnlyArena(&bounds); bounds.top = oldMouseDotPosition[1]; bounds.bottom = oldMouseDotPosition[1]; bounds.left = oldMouseDotPosition[0]; bounds.right = oldMouseDotPosition[0]; - drawOnlyArena(); + drawOnlyArena(&bounds); } void drawOnlyRabbitArena() { rabbit.x = oldRabbitPosition[0]; rabbit.y = oldRabbitPosition[1]; getSpriteBounds(&rabbit, &bounds); - drawOnlyArena(); -} - -#define RAD2DEG (180/3.14159) -#define DEG2RAD (3.14159/180) -#define MOUSE_DISTANCE (32) - -void calculateTargetAngle() { - float distanceX, distanceY; - float angle; - - oldMouseDotPosition[0] = mouseDotPosition[0]; - oldMouseDotPosition[1] = mouseDotPosition[1]; - - mouseDotPosition[0] = mouseStatus.xPosition; - mouseDotPosition[1] = mouseStatus.yPosition; - - distanceX = mouseStatus.xPosition - rabbitPosition[0]; - distanceY = mouseStatus.yPosition - rabbitPosition[1]; - - angle = atan2(distanceY, distanceX) * 180 / 3.14159 + 90; - if (angle < 0) angle += 360; - - distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE; - distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE; - - oldMousePosition[0] = mousePosition[0]; - oldMousePosition[1] = mousePosition[1]; - - mousePosition[0] = rabbitPosition[0] + distanceX; - mousePosition[1] = rabbitPosition[1] + distanceY; + drawOnlyArena(&bounds); } int main(void) { @@ -270,7 +156,7 @@ int main(void) { spritesheetImage.transparentColor = 0; - setupWallSprites(); + setupWallSprites(&spritesheetImage); setupRabbitSprites(); setVideoMode(VIDEO_MODE_VGA_256); diff --git a/makefile b/makefile index 9f4b54a..dd9ec39 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -obj = game.o bmpload.o +obj = game.o bmpload.o arena.o all: system/system.lib game.exe .SYMBOLIC diff --git a/movement.c b/movement.c new file mode 100644 index 0000000..8335845 --- /dev/null +++ b/movement.c @@ -0,0 +1,28 @@ +#include "const.h" +#include + +void calculateTargetAngle() { + float distanceX, distanceY; + float angle; + + oldMouseDotPosition[0] = mouseDotPosition[0]; + oldMouseDotPosition[1] = mouseDotPosition[1]; + + mouseDotPosition[0] = mouseStatus.xPosition; + mouseDotPosition[1] = mouseStatus.yPosition; + + distanceX = mouseStatus.xPosition - rabbitPosition[0]; + distanceY = mouseStatus.yPosition - rabbitPosition[1]; + + angle = atan2(distanceY, distanceX) * 180 / 3.14159 + 90; + if (angle < 0) angle += 360; + + distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE; + distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE; + + oldMousePosition[0] = mousePosition[0]; + oldMousePosition[1] = mousePosition[1]; + + mousePosition[0] = rabbitPosition[0] + distanceX; + mousePosition[1] = rabbitPosition[1] + distanceY; +} diff --git a/movement.h b/movement.h new file mode 100644 index 0000000..c8e97cc --- /dev/null +++ b/movement.h @@ -0,0 +1,3 @@ +struct RabbitPositioning { + +}; diff --git a/unch1.c b/old/unch1.c similarity index 100% rename from unch1.c rename to old/unch1.c