From c1a514133ea541c906a68d83de77e1e2c6ea0c68 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 20 Feb 2024 12:39:28 -0500 Subject: [PATCH] more stuff --- .gitignore | 3 +++ game.c | 46 +++++++++++++++++++++++++++------------------- makefile | 2 +- system/keyboard.c | 1 + system/keyboard.h | 1 + system/mouse_io.c | 26 ++++++++++++++++---------- system/mouse_io.h | 1 + system/system.lib | Bin 8192 -> 8192 bytes system/vga.c | 4 ++++ system/vga.h | 2 ++ 10 files changed, 56 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 75783d7..9e6d52f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ *.LNK *.o *.exe +*.err +*.bak +*.lib diff --git a/game.c b/game.c index 18d0118..03ce7d8 100644 --- a/game.c +++ b/game.c @@ -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 oldRabbitPosition[2] = { 60, 60 }; int rabbitLimits[2][2] = { @@ -108,31 +112,27 @@ int rabbitLimits[2][2] = { { 180, 180 } }; -#define RABBIT_MOTION_DRAG (2) -#define RABBIT_MOTION_ACCELERATION (5) -#define RABBIT_MOTION_MAX_SPEED (12) - signed char rabbitVelocity[2] = { 0, 0 }; struct MouseStatus mouseStatus; char mousePosition[2] = { 0, 0 }; char oldMousePosition[2] = { 0, 0 }; -void setupRabbitDrawing() { - rabbit.x = rabbitPosition[0]; - rabbit.y = rabbitPosition[1]; -} - -void setupMouseDrawing() { - mouse.x = mousePosition[0]; - mouse.y = mousePosition[1]; -} +char mouseDotPosition[2] = { 0, 0 }; +char oldMouseDotPosition[2] = { 0, 0 }; void renderMouse() { + mouse.x = mousePosition[0]; + mouse.y = mousePosition[1]; + drawSprite(&mouse); + drawPixel(mouseDotPosition[0], mouseDotPosition[1], 2); } void renderRabbit() { + rabbit.x = rabbitPosition[0]; + rabbit.y = rabbitPosition[1]; + drawSprite(&rabbit); } @@ -196,8 +196,6 @@ void drawOnlyArena() { int leftTileX, rightTileX, topTileY, bottomTileY; - char buffer[20]; - leftTileX = bounds.left / TILE_SIZE; rightTileX = bounds.right / TILE_SIZE; topTileY = bounds.top / TILE_SIZE; @@ -214,6 +212,12 @@ void drawOnlyMouseArena() { mouse.y = oldMousePosition[1]; getSpriteBounds(&mouse, &bounds); drawOnlyArena(); + + bounds.top = oldMouseDotPosition[1]; + bounds.bottom = oldMouseDotPosition[1]; + bounds.left = oldMouseDotPosition[0]; + bounds.right = oldMouseDotPosition[0]; + drawOnlyArena(); } void drawOnlyRabbitArena() { @@ -231,6 +235,12 @@ 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]; @@ -268,6 +278,7 @@ int main(void) { setVGAColors(vgaColors, 256); activateMouse(&mouseStatus); + limitMouseArea(0, 0, 199, 199); buildArena(); @@ -279,8 +290,6 @@ int main(void) { drawOnlyRabbitArena(); drawOnlyMouseArena(); - setupRabbitDrawing(); - setupMouseDrawing(); renderRabbit(); renderMouse(); @@ -290,8 +299,7 @@ int main(void) { waitEndVbl(); - - if (mouseStatus.leftButtonDown) { keepRunning = 0; } + if (keyboardKeydownState.KEY_ESC) { keepRunning = 0; } } // states: diff --git a/makefile b/makefile index 20a1c59..9f4b54a 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ system/system.lib: .SYMBOLIC .c.o: wcc386 -q -bt=dos $< -game.exe: $(obj) +game.exe: $(obj) system/system.lib wcl386 -q -bt=dos -l=dos4g $(obj) system/system.lib clean: .SYMBOLIC diff --git a/system/keyboard.c b/system/keyboard.c index 2581197..b419678 100644 --- a/system/keyboard.c +++ b/system/keyboard.c @@ -13,6 +13,7 @@ void populateKeyboardKeydownState() { keyboardKeydownState.KEY_A = keystateBits[3] & 0x40; keyboardKeydownState.KEY_S = keystateBits[3] & 0x80; keyboardKeydownState.KEY_D = keystateBits[4] & 0x01; + keyboardKeydownState.KEY_ESC = keystateBits[0] & 0x02; } void far interrupt keyboardHandler(void) { diff --git a/system/keyboard.h b/system/keyboard.h index 956fd53..e6e2f2f 100644 --- a/system/keyboard.h +++ b/system/keyboard.h @@ -10,6 +10,7 @@ struct KeyboardKeydownState { byte KEY_A; byte KEY_S; byte KEY_D; + byte KEY_ESC; }; extern struct KeyboardKeydownState keyboardKeydownState; diff --git a/system/mouse_io.c b/system/mouse_io.c index cd82551..cdffb4f 100644 --- a/system/mouse_io.c +++ b/system/mouse_io.c @@ -6,6 +6,21 @@ 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, ®s, ®s); + + regs.w.ax = 0x08; + regs.w.cx = sy; + regs.w.dx = ey; + int386(MOUSE_DRIVER_INTERRUPT, ®s, ®s); +} + /** * 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->buttonCount = regs.w.bx; - // set horiz and vert range - regs.w.ax = 0x07; - regs.w.cx = 0; - regs.w.dx = VGA_DISPLAY_WIDTH - 1; - int386(MOUSE_DRIVER_INTERRUPT, ®s, ®s); - - regs.w.ax = 0x08; - regs.w.cx = 0; - regs.w.dx = VGA_DISPLAY_HEIGHT - 1; - int386(MOUSE_DRIVER_INTERRUPT, ®s, ®s); + limitMouseArea(0, 0, VGA_DISPLAY_WIDTH - 1, VGA_DISPLAY_HEIGHT - 1); } _status = status; diff --git a/system/mouse_io.h b/system/mouse_io.h index 7c43583..914fbc9 100644 --- a/system/mouse_io.h +++ b/system/mouse_io.h @@ -15,4 +15,5 @@ struct MouseStatus { #define MOUSE_DRIVER_READ_STATE (0x03); int activateMouse(struct MouseStatus *); +int limitMouseArea(int sx, int sy, int ex, int ey); void readMouse(struct MouseStatus *); diff --git a/system/system.lib b/system/system.lib index 15c2e60c28661edbc361ba946c7ed01c7a529ad0..cf4d46f0825c0fe209c3a8850ceb442939e05445 100644 GIT binary patch delta 1297 zcmZXUUu;ul6u{5@`tSB`tZUcZ5-6RSWtj#I1)MPJ>^kPAL&6*mBy%@ice`ELA82nG zJS^0aCA}aC+xMnv*vO54q6@=4OvNa1L}Gj)WKm;+LAi;NXnZq1IO{oGzzrXI@|{25 zIbVP0oSTc~V)K1Y7Ekh`|5wKlUWuZYF z5+WagFb4qVa+P)fBkosvzZ78*&+se$K)V&gE5gll)uiQvY>6+rCn8maO_j-b${ zZUPhdd`RX+X}Ck`PbbC>XeZSnig2>oH#)rkt zn6=z47<}3Dj(dh`gxMuKAFI@C7Yg0{kIE+>v!0O|v*JYW6`9%19+^4Jl+2vwSrTs( zoc9P0k9uFMx(LFDnB~vbzjL~GzF7Z#euS& zxh>2tS%_J(5;7|@kIJmvJVl+GAX^@VIgK`H>LfK`TTO`PeX`KTFZzPQFZ?rK$XP=y zr}-V<#tOHhjp%#25+~G3wDEsD0jG=yI8{P;`R=mHO9-dDg=znQ!=8LV(2oRfmk6%( z{b!WKI}eZSq8M03=|hy6)7!wIC@t+B;KIr~cQ+{D8PbL|{iV@tMr}^32?a!j8mebA zV9nxS(|ZQPC`zN;edf2I@onmcJ?w&%u{SKHjGl10ao70y-qRR! z=6bMqX>iy5=&sI}yAM&;uOin{hCRGKmuE2=o-FEHj3&?G-mu+x-u}rAym|FGd{^XF zKO2vKpoEp zTKhT+HDJ0a6c>_NJ21$Kk-*N|tzHzlsVKJff5@nOMIxzdClb0^LaB6;O+ujktNLZq z_wkj$u63)C5iV_F&M|WC=FVV79Dp=q!H(5)W0gjGiiN;T%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->transparentColor = spritesheetImage->transparentColor; } +void drawPixel(int x, int y, int color) { + drawBuffer[y * VGA_DISPLAY_WIDTH + x] = color; +} + void drawSprite(struct SpriteRender* sprite) { int x, y; byte pixel; diff --git a/system/vga.h b/system/vga.h index b376481..29db2bd 100644 --- a/system/vga.h +++ b/system/vga.h @@ -35,6 +35,8 @@ struct SpriteBounds { int left; }; +void drawPixel(int x, int y, int color); + void drawSprite(struct SpriteRender *sprite); void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int); void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds);