more stuff

This commit is contained in:
John Bintz 2024-02-20 12:39:28 -05:00
parent 8cebf1d3f2
commit c1a514133e
10 changed files with 56 additions and 30 deletions

3
.gitignore vendored
View File

@ -6,3 +6,6 @@
*.LNK *.LNK
*.o *.o
*.exe *.exe
*.err
*.bak
*.lib

46
game.c
View File

@ -101,6 +101,10 @@ void buildArena() {
} }
} }
#define RABBIT_MOTION_DRAG (2)
#define RABBIT_MOTION_ACCELERATION (5)
#define RABBIT_MOTION_MAX_SPEED (12)
int rabbitPosition[2] = { 60, 60 }; int rabbitPosition[2] = { 60, 60 };
int oldRabbitPosition[2] = { 60, 60 }; int oldRabbitPosition[2] = { 60, 60 };
int rabbitLimits[2][2] = { int rabbitLimits[2][2] = {
@ -108,31 +112,27 @@ int rabbitLimits[2][2] = {
{ 180, 180 } { 180, 180 }
}; };
#define RABBIT_MOTION_DRAG (2)
#define RABBIT_MOTION_ACCELERATION (5)
#define RABBIT_MOTION_MAX_SPEED (12)
signed char rabbitVelocity[2] = { 0, 0 }; signed char rabbitVelocity[2] = { 0, 0 };
struct MouseStatus mouseStatus; struct MouseStatus mouseStatus;
char mousePosition[2] = { 0, 0 }; char mousePosition[2] = { 0, 0 };
char oldMousePosition[2] = { 0, 0 }; char oldMousePosition[2] = { 0, 0 };
void setupRabbitDrawing() { char mouseDotPosition[2] = { 0, 0 };
rabbit.x = rabbitPosition[0]; char oldMouseDotPosition[2] = { 0, 0 };
rabbit.y = rabbitPosition[1];
}
void setupMouseDrawing() {
mouse.x = mousePosition[0];
mouse.y = mousePosition[1];
}
void renderMouse() { void renderMouse() {
mouse.x = mousePosition[0];
mouse.y = mousePosition[1];
drawSprite(&mouse); drawSprite(&mouse);
drawPixel(mouseDotPosition[0], mouseDotPosition[1], 2);
} }
void renderRabbit() { void renderRabbit() {
rabbit.x = rabbitPosition[0];
rabbit.y = rabbitPosition[1];
drawSprite(&rabbit); drawSprite(&rabbit);
} }
@ -196,8 +196,6 @@ void drawOnlyArena() {
int leftTileX, rightTileX, int leftTileX, rightTileX,
topTileY, bottomTileY; topTileY, bottomTileY;
char buffer[20];
leftTileX = bounds.left / TILE_SIZE; leftTileX = bounds.left / TILE_SIZE;
rightTileX = bounds.right / TILE_SIZE; rightTileX = bounds.right / TILE_SIZE;
topTileY = bounds.top / TILE_SIZE; topTileY = bounds.top / TILE_SIZE;
@ -214,6 +212,12 @@ void drawOnlyMouseArena() {
mouse.y = oldMousePosition[1]; mouse.y = oldMousePosition[1];
getSpriteBounds(&mouse, &bounds); getSpriteBounds(&mouse, &bounds);
drawOnlyArena(); drawOnlyArena();
bounds.top = oldMouseDotPosition[1];
bounds.bottom = oldMouseDotPosition[1];
bounds.left = oldMouseDotPosition[0];
bounds.right = oldMouseDotPosition[0];
drawOnlyArena();
} }
void drawOnlyRabbitArena() { void drawOnlyRabbitArena() {
@ -231,6 +235,12 @@ void calculateTargetAngle() {
float distanceX, distanceY; float distanceX, distanceY;
float angle; float angle;
oldMouseDotPosition[0] = mouseDotPosition[0];
oldMouseDotPosition[1] = mouseDotPosition[1];
mouseDotPosition[0] = mouseStatus.xPosition;
mouseDotPosition[1] = mouseStatus.yPosition;
distanceX = mouseStatus.xPosition - rabbitPosition[0]; distanceX = mouseStatus.xPosition - rabbitPosition[0];
distanceY = mouseStatus.yPosition - rabbitPosition[1]; distanceY = mouseStatus.yPosition - rabbitPosition[1];
@ -268,6 +278,7 @@ int main(void) {
setVGAColors(vgaColors, 256); setVGAColors(vgaColors, 256);
activateMouse(&mouseStatus); activateMouse(&mouseStatus);
limitMouseArea(0, 0, 199, 199);
buildArena(); buildArena();
@ -279,8 +290,6 @@ int main(void) {
drawOnlyRabbitArena(); drawOnlyRabbitArena();
drawOnlyMouseArena(); drawOnlyMouseArena();
setupRabbitDrawing();
setupMouseDrawing();
renderRabbit(); renderRabbit();
renderMouse(); renderMouse();
@ -290,8 +299,7 @@ int main(void) {
waitEndVbl(); waitEndVbl();
if (keyboardKeydownState.KEY_ESC) { keepRunning = 0; }
if (mouseStatus.leftButtonDown) { keepRunning = 0; }
} }
// states: // states:

View File

@ -10,7 +10,7 @@ system/system.lib: .SYMBOLIC
.c.o: .c.o:
wcc386 -q -bt=dos $< wcc386 -q -bt=dos $<
game.exe: $(obj) 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
clean: .SYMBOLIC clean: .SYMBOLIC

View File

@ -13,6 +13,7 @@ void populateKeyboardKeydownState() {
keyboardKeydownState.KEY_A = keystateBits[3] & 0x40; keyboardKeydownState.KEY_A = keystateBits[3] & 0x40;
keyboardKeydownState.KEY_S = keystateBits[3] & 0x80; keyboardKeydownState.KEY_S = keystateBits[3] & 0x80;
keyboardKeydownState.KEY_D = keystateBits[4] & 0x01; keyboardKeydownState.KEY_D = keystateBits[4] & 0x01;
keyboardKeydownState.KEY_ESC = keystateBits[0] & 0x02;
} }
void far interrupt keyboardHandler(void) { void far interrupt keyboardHandler(void) {

View File

@ -10,6 +10,7 @@ struct KeyboardKeydownState {
byte KEY_A; byte KEY_A;
byte KEY_S; byte KEY_S;
byte KEY_D; byte KEY_D;
byte KEY_ESC;
}; };
extern struct KeyboardKeydownState keyboardKeydownState; extern struct KeyboardKeydownState keyboardKeydownState;

View File

@ -6,6 +6,21 @@
struct MouseStatus *_status; struct MouseStatus *_status;
int limitMouseArea(int sx, int sy, int ex, int ey) {
union REGS regs;
// set horiz and vert range
regs.w.ax = 0x07;
regs.w.cx = sx;
regs.w.dx = ex;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
regs.w.ax = 0x08;
regs.w.cx = sy;
regs.w.dx = ey;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
}
/** /**
* Ensure this is called after setting the desired video mode. * Ensure this is called after setting the desired video mode.
*/ */
@ -22,16 +37,7 @@ int activateMouse(struct MouseStatus *status) {
status->isActive = regs.w.ax; status->isActive = regs.w.ax;
status->buttonCount = regs.w.bx; status->buttonCount = regs.w.bx;
// set horiz and vert range limitMouseArea(0, 0, VGA_DISPLAY_WIDTH - 1, VGA_DISPLAY_HEIGHT - 1);
regs.w.ax = 0x07;
regs.w.cx = 0;
regs.w.dx = VGA_DISPLAY_WIDTH - 1;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
regs.w.ax = 0x08;
regs.w.cx = 0;
regs.w.dx = VGA_DISPLAY_HEIGHT - 1;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
} }
_status = status; _status = status;

View File

@ -15,4 +15,5 @@ struct MouseStatus {
#define MOUSE_DRIVER_READ_STATE (0x03); #define MOUSE_DRIVER_READ_STATE (0x03);
int activateMouse(struct MouseStatus *); int activateMouse(struct MouseStatus *);
int limitMouseArea(int sx, int sy, int ex, int ey);
void readMouse(struct MouseStatus *); void readMouse(struct MouseStatus *);

Binary file not shown.

View File

@ -50,6 +50,10 @@ void buildSpriteFromSpritesheet(
spriteRender->transparentColor = spritesheetImage->transparentColor; spriteRender->transparentColor = spritesheetImage->transparentColor;
} }
void drawPixel(int x, int y, int color) {
drawBuffer[y * VGA_DISPLAY_WIDTH + x] = color;
}
void drawSprite(struct SpriteRender* sprite) { void drawSprite(struct SpriteRender* sprite) {
int x, y; int x, y;
byte pixel; byte pixel;

View File

@ -35,6 +35,8 @@ struct SpriteBounds {
int left; int left;
}; };
void drawPixel(int x, int y, int color);
void drawSprite(struct SpriteRender *sprite); void drawSprite(struct SpriteRender *sprite);
void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int); void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int);
void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds); void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds);