From a30af8748542daf98a61b73a2ac5664824ad8668 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 20 Feb 2024 08:00:13 -0500 Subject: [PATCH] shuffle code around --- bmpload.c | 4 +-- game.c | 44 +++++++++++++------------------- makefile | 18 ++++++++++--- run | 3 +++ keyboard.c => system/keyboard.c | 0 keyboard.h => system/keyboard.h | 2 +- system/makefile | 7 +++++ mouse_io.c => system/mouse_io.c | 0 mouse_io.h => system/mouse_io.h | 0 pc_stuff.c => system/pc_stuff.c | 0 pc_stuff.h => system/pc_stuff.h | 2 +- system/system.lib | Bin 0 -> 8192 bytes vga.c => system/vga.c | 0 vga.h => system/vga.h | 4 +-- 14 files changed, 49 insertions(+), 35 deletions(-) create mode 100755 run rename keyboard.c => system/keyboard.c (100%) rename keyboard.h => system/keyboard.h (94%) create mode 100644 system/makefile rename mouse_io.c => system/mouse_io.c (100%) rename mouse_io.h => system/mouse_io.h (100%) rename pc_stuff.c => system/pc_stuff.c (100%) rename pc_stuff.h => system/pc_stuff.h (96%) create mode 100644 system/system.lib rename vga.c => system/vga.c (100%) rename vga.h => system/vga.h (94%) diff --git a/bmpload.c b/bmpload.c index b2f8194..d9f8b50 100644 --- a/bmpload.c +++ b/bmpload.c @@ -4,8 +4,8 @@ #include #include "bmpload.h" -#include "pc_stuff.h" -#include "vga.h" +#include "system/pc_stuff.h" +#include "system/vga.h" int readBMPHeader(FILE *fh, struct BMPImage *info) { int sizeOfHeader; diff --git a/game.c b/game.c index 6aa4c5d..7c88567 100644 --- a/game.c +++ b/game.c @@ -2,10 +2,10 @@ #include #include -#include "vga.h" -#include "keyboard.h" -#include "mouse_io.h" -#include "pc_stuff.h" +#include "system/vga.h" +#include "system/keyboard.h" +#include "system/mouse_io.h" +#include "system/pc_stuff.h" #include "bmpload.h" struct BMPImage spritesheetImage; @@ -113,7 +113,6 @@ int rabbitLimits[2][2] = { signed char rabbitVelocity[2] = { 0, 0 }; -struct SpriteBounds bounds; struct MouseStatus mouseStatus; char mousePosition[2] = { 0, 0 }; @@ -184,14 +183,18 @@ void handleRabbitMovement() { } } +#define TILE_SIZE (20) + +struct SpriteBounds bounds; + void drawOnlyArena() { int leftTileX, rightTileX, topTileY, bottomTileY; - leftTileX = bounds.left / 20; - rightTileX = bounds.right / 20; - topTileY = bounds.top / 20; - bottomTileY = bounds.bottom / 20; + leftTileX = bounds.left / TILE_SIZE; + rightTileX = bounds.right / TILE_SIZE; + topTileY = bounds.top / TILE_SIZE; + bottomTileY = bounds.bottom / TILE_SIZE; renderArenaTile(leftTileX, topTileY); if (leftTileX != rightTileX) { @@ -221,28 +224,18 @@ void drawOnlyRabbitArena() { #define DEG2RAD (3.14159/180) #define MOUSE_DISTANCE (32) -void calculateMouseAngle() { +void calculateTargetAngle() { float distanceX, distanceY; float angle; - char buffer[20]; - distanceX = mouseStatus.xPosition - rabbitPosition[0]; distanceY = mouseStatus.yPosition - rabbitPosition[1]; - angle = atan2(distanceY, distanceX) * 180 / 3.14159; + angle = atan2(distanceY, distanceX) * 180 / 3.14159 + 90; + if (angle < 0) angle += 360; - sprintf(buffer, "%f", angle); - writeString(buffer, 0, 2); - - sprintf(buffer, "%f", distanceX); - writeString(buffer, 0, 3); - - sprintf(buffer, "%d", mouseStatus.xPosition); - writeString(buffer, 0, 4); - - distanceX = cos(angle * DEG2RAD) * MOUSE_DISTANCE; - distanceY = sin(angle * DEG2RAD) * MOUSE_DISTANCE; + distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE; + distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE; mousePosition[0] = rabbitPosition[0] + distanceX; mousePosition[1] = rabbitPosition[1] + distanceY; @@ -276,7 +269,7 @@ int main(void) { readMouse(&mouseStatus); populateKeyboardKeydownState(); handleRabbitMovement(); - calculateMouseAngle(); + calculateTargetAngle(); waitStartVbl(); @@ -287,7 +280,6 @@ int main(void) { renderRabbit(); renderMouse(); copyDrawBufferToDisplay(); - calculateMouseAngle(); waitEndVbl(); diff --git a/makefile b/makefile index 4531711..20a1c59 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,19 @@ -obj = game.o bmpload.o mouse_io.o pc_stuff.o vga.o keyboard.o +obj = game.o bmpload.o + +all: system/system.lib game.exe .SYMBOLIC + +system/system.lib: .SYMBOLIC + cd system + wmake + cd .. .c.o: - wcc386 -q -bt=dos -q $< + wcc386 -q -bt=dos $< game.exe: $(obj) - wcl386 -q -bt=dos -l=dos4g $(obj) + wcl386 -q -bt=dos -l=dos4g $(obj) system/system.lib + +clean: .SYMBOLIC + rm *.o + rm system/*.o + rm system/*.lib diff --git a/run b/run new file mode 100755 index 0000000..d200ad0 --- /dev/null +++ b/run @@ -0,0 +1,3 @@ +#!/bin/sh + +dosbox-x game.exe -exit diff --git a/keyboard.c b/system/keyboard.c similarity index 100% rename from keyboard.c rename to system/keyboard.c diff --git a/keyboard.h b/system/keyboard.h similarity index 94% rename from keyboard.h rename to system/keyboard.h index 28e145e..956fd53 100644 --- a/keyboard.h +++ b/system/keyboard.h @@ -1,7 +1,7 @@ #ifndef __KEYBOARD_H__ #define __KEYBOARD_H__ 1 -#include "types.h" +#include "../types.h" extern unsigned char keystateBits[]; diff --git a/system/makefile b/system/makefile new file mode 100644 index 0000000..45b7fba --- /dev/null +++ b/system/makefile @@ -0,0 +1,7 @@ +obj = pc_stuff.o vga.o keyboard.o mouse_io.o + +.c.o: + wcc386 -q -bt=dos $< + +system.lib: $(obj) + wlib -n system.lib $(obj:%=+%) diff --git a/mouse_io.c b/system/mouse_io.c similarity index 100% rename from mouse_io.c rename to system/mouse_io.c diff --git a/mouse_io.h b/system/mouse_io.h similarity index 100% rename from mouse_io.h rename to system/mouse_io.h diff --git a/pc_stuff.c b/system/pc_stuff.c similarity index 100% rename from pc_stuff.c rename to system/pc_stuff.c diff --git a/pc_stuff.h b/system/pc_stuff.h similarity index 96% rename from pc_stuff.h rename to system/pc_stuff.h index ee3100d..1f23e58 100644 --- a/pc_stuff.h +++ b/system/pc_stuff.h @@ -4,7 +4,7 @@ #include #include -#include "types.h" +#include "../types.h" extern byte *VGA; diff --git a/system/system.lib b/system/system.lib new file mode 100644 index 0000000000000000000000000000000000000000..15c2e60c28661edbc361ba946c7ed01c7a529ad0 GIT binary patch literal 8192 zcmeHMeQZqG?>q0_-|wE|%l~E|8$baMuLsftU1d;GXmdM-!X0j#tFX@N-XWMp zU!l{t+~W2v7riFC%kF9|G#A!2)YcTXx0(ulojy@;7JAIQPi(VV3(QVG2VF;N4J%eW zkwMiTt+dv9EC>87bls>r?$<-tg`-CdO|u^7nrzBdY@D?z+pGR>;;ibwQQfp=nr|<5 zdIVpAZOpGk1M0pn1F+?_6_sp7sj*a9W-us?8x3sL#!_Q)MRh~%mbxU~SlMKJ?m!CU z{|#3dr(nwcN$8kb=BIrsNGh-0Y%qR+y|2^qOHndM`Z!3Ir7I3c#i>f>XQa&2ARm#G zMddUlGjNat)r4X~IlU_9-}tfZ`7vaJqPdV$%B(#3U+DznOdC_^<=Gg8e=wI5^e;^2BA z#_bM%8Hv(JROzyipn?SI4zFDl45AnJ4gWMrtiedmA=TG56;0D$+npYV+hi%Qy>~D1Yx?kW z823NI&x`jEe)^JueHFcCB ze+XW*L7PG46r5&HCl5(huYmh)Y4Ah@vN*IX<50s8{3}vDO#47L9GFk{)2sqY)=}T? zPl6<99sV3w5{Tm~QH3xxYJPRRedC9^;rrw)R3h}3h^Yf zP_I2pksR_-a~Czcu{J?Y_&Lri(3OD$OJ$jS%kMa_;h8P+cJ&R7Tesj;R@3a29(I{0 zJ5a|htIM&El`uHfE4sfI+cJFlx~qX*>a{m~b9xqO20t$?-jyjT{EN$~E`I!5(#yZW zTv6&5R$d%?nr~^|hUg#jdVN68Ez{>nsY*S*As5iI%k9!p(#$GR+>M9D-IcfF&G4+hcri|kGe0h*JTq+RPt@;8SIv8QswoY%In$}dNy6}`itrW zGj?7xIDG0erGIqD6w^7S?$QjNjSDn`@5dWgE3bEnbB<5sedr%K9i`^+G@|CYM8gZH zCiC-`sP&9ph&n z9f$GPT7#)wfQ+b%^(L3aA$WNR>tb{f)-4L|2j&>Qk7jT*=M}ue#T2Y^a`o3a*p|-9 z?g;zjlIC?yP_@+bo-G!y8R{E`QczD;uuAjE&4=*^d(X&36YrFnJ$^K*w+7NlIq(>1 z$JLNdU+S-h@g#CZ1{R@gdTk8CxX@~1^Rg^O$~d|wb$l}wTe1{sbdXVpoW%O=B-@Qe z=tY#h*}Dq~_%V;$)8@d{g)8lr6&EJrTRc@vvsz$x;evHIqR&O$c#b+3wPAW<%IcAYH~BSU3*Ki;gEJ%*cT9 zrbmwUYa=lqkw|DO6`h2fFA$0BC%im{%>}^?z#KOwebheRJ4cQfqW&k@CwD`;d_=qE|5dc3H+*;{df-$1|L5WLfO|j}e*Y~1Ejs~n z!296c<_o*JA4?HvTVKi2nh1mzxCu literal 0 HcmV?d00001 diff --git a/vga.c b/system/vga.c similarity index 100% rename from vga.c rename to system/vga.c diff --git a/vga.h b/system/vga.h similarity index 94% rename from vga.h rename to system/vga.h index 2c353a6..b376481 100644 --- a/vga.h +++ b/system/vga.h @@ -3,8 +3,8 @@ #include -#include "types.h" -#include "bmpload.h" +#include "../types.h" +#include "../bmpload.h" #define VGA_DISPLAY_WIDTH (320) #define VGA_DISPLAY_HEIGHT (200)