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 0000000..15c2e60 Binary files /dev/null and b/system/system.lib differ 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)