start on rabbit positioning

This commit is contained in:
John Bintz 2024-02-20 12:51:59 -05:00
parent ba0a52db3a
commit 129b1f7566
8 changed files with 136 additions and 121 deletions

87
arena.c Normal file
View File

@ -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);
}
}
}

6
arena.h Normal file
View File

@ -0,0 +1,6 @@
#include "bmpload.h"
#include "system/vga.h"
void drawOnlyArena(struct SpriteBounds *bounds);
void buildArena();
void setupWallSprites(struct BMPImage *);

View File

@ -0,0 +1,5 @@
#define TILE_SIZE (20)
#define RAD2DEG (180/3.14159)
#define DEG2RAD (3.14159/180)
#define MOUSE_DISTANCE (32)

126
game.c
View File

@ -7,33 +7,14 @@
#include "system/mouse_io.h" #include "system/mouse_io.h"
#include "system/pc_stuff.h" #include "system/pc_stuff.h"
#include "bmpload.h" #include "bmpload.h"
#include "const.h"
#include "arena.h"
struct BMPImage spritesheetImage; struct BMPImage spritesheetImage;
struct VGAColor vgaColors[256]; struct VGAColor vgaColors[256];
struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor;
struct SpriteRender rabbit, mouse; 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() { void setupRabbitSprites() {
buildSpriteFromSpritesheet( buildSpriteFromSpritesheet(
&spritesheetImage, &spritesheetImage,
@ -54,52 +35,6 @@ void setupRabbitSprites() {
mouse.offsetY = 4; 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_DRAG (2)
#define RABBIT_MOTION_ACCELERATION (5) #define RABBIT_MOTION_ACCELERATION (5)
@ -186,75 +121,26 @@ void handleRabbitMovement() {
} }
} }
#define TILE_SIZE (20)
struct SpriteBounds bounds; 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() { void drawOnlyMouseArena() {
mouse.x = oldMousePosition[0]; mouse.x = oldMousePosition[0];
mouse.y = oldMousePosition[1]; mouse.y = oldMousePosition[1];
getSpriteBounds(&mouse, &bounds); getSpriteBounds(&mouse, &bounds);
drawOnlyArena(); drawOnlyArena(&bounds);
bounds.top = oldMouseDotPosition[1]; bounds.top = oldMouseDotPosition[1];
bounds.bottom = oldMouseDotPosition[1]; bounds.bottom = oldMouseDotPosition[1];
bounds.left = oldMouseDotPosition[0]; bounds.left = oldMouseDotPosition[0];
bounds.right = oldMouseDotPosition[0]; bounds.right = oldMouseDotPosition[0];
drawOnlyArena(); drawOnlyArena(&bounds);
} }
void drawOnlyRabbitArena() { void drawOnlyRabbitArena() {
rabbit.x = oldRabbitPosition[0]; rabbit.x = oldRabbitPosition[0];
rabbit.y = oldRabbitPosition[1]; rabbit.y = oldRabbitPosition[1];
getSpriteBounds(&rabbit, &bounds); getSpriteBounds(&rabbit, &bounds);
drawOnlyArena(); drawOnlyArena(&bounds);
}
#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;
} }
int main(void) { int main(void) {
@ -270,7 +156,7 @@ int main(void) {
spritesheetImage.transparentColor = 0; spritesheetImage.transparentColor = 0;
setupWallSprites(); setupWallSprites(&spritesheetImage);
setupRabbitSprites(); setupRabbitSprites();
setVideoMode(VIDEO_MODE_VGA_256); setVideoMode(VIDEO_MODE_VGA_256);

View File

@ -1,4 +1,4 @@
obj = game.o bmpload.o obj = game.o bmpload.o arena.o
all: system/system.lib game.exe .SYMBOLIC all: system/system.lib game.exe .SYMBOLIC

28
movement.c Normal file
View File

@ -0,0 +1,28 @@
#include "const.h"
#include <math.h>
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;
}

3
movement.h Normal file
View File

@ -0,0 +1,3 @@
struct RabbitPositioning {
};