shuffle code around

This commit is contained in:
John Bintz 2024-02-20 08:00:13 -05:00
parent 5ce88d42cf
commit a30af87485
14 changed files with 49 additions and 35 deletions

View File

@ -4,8 +4,8 @@
#include <dos.h> #include <dos.h>
#include "bmpload.h" #include "bmpload.h"
#include "pc_stuff.h" #include "system/pc_stuff.h"
#include "vga.h" #include "system/vga.h"
int readBMPHeader(FILE *fh, struct BMPImage *info) { int readBMPHeader(FILE *fh, struct BMPImage *info) {
int sizeOfHeader; int sizeOfHeader;

44
game.c
View File

@ -2,10 +2,10 @@
#include <math.h> #include <math.h>
#include <conio.h> #include <conio.h>
#include "vga.h" #include "system/vga.h"
#include "keyboard.h" #include "system/keyboard.h"
#include "mouse_io.h" #include "system/mouse_io.h"
#include "pc_stuff.h" #include "system/pc_stuff.h"
#include "bmpload.h" #include "bmpload.h"
struct BMPImage spritesheetImage; struct BMPImage spritesheetImage;
@ -113,7 +113,6 @@ int rabbitLimits[2][2] = {
signed char rabbitVelocity[2] = { 0, 0 }; signed char rabbitVelocity[2] = { 0, 0 };
struct SpriteBounds bounds;
struct MouseStatus mouseStatus; struct MouseStatus mouseStatus;
char mousePosition[2] = { 0, 0 }; char mousePosition[2] = { 0, 0 };
@ -184,14 +183,18 @@ void handleRabbitMovement() {
} }
} }
#define TILE_SIZE (20)
struct SpriteBounds bounds;
void drawOnlyArena() { void drawOnlyArena() {
int leftTileX, rightTileX, int leftTileX, rightTileX,
topTileY, bottomTileY; topTileY, bottomTileY;
leftTileX = bounds.left / 20; leftTileX = bounds.left / TILE_SIZE;
rightTileX = bounds.right / 20; rightTileX = bounds.right / TILE_SIZE;
topTileY = bounds.top / 20; topTileY = bounds.top / TILE_SIZE;
bottomTileY = bounds.bottom / 20; bottomTileY = bounds.bottom / TILE_SIZE;
renderArenaTile(leftTileX, topTileY); renderArenaTile(leftTileX, topTileY);
if (leftTileX != rightTileX) { if (leftTileX != rightTileX) {
@ -221,28 +224,18 @@ void drawOnlyRabbitArena() {
#define DEG2RAD (3.14159/180) #define DEG2RAD (3.14159/180)
#define MOUSE_DISTANCE (32) #define MOUSE_DISTANCE (32)
void calculateMouseAngle() { void calculateTargetAngle() {
float distanceX, distanceY; float distanceX, distanceY;
float angle; float angle;
char buffer[20];
distanceX = mouseStatus.xPosition - rabbitPosition[0]; distanceX = mouseStatus.xPosition - rabbitPosition[0];
distanceY = mouseStatus.yPosition - rabbitPosition[1]; 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); distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE;
writeString(buffer, 0, 2); distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE;
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;
mousePosition[0] = rabbitPosition[0] + distanceX; mousePosition[0] = rabbitPosition[0] + distanceX;
mousePosition[1] = rabbitPosition[1] + distanceY; mousePosition[1] = rabbitPosition[1] + distanceY;
@ -276,7 +269,7 @@ int main(void) {
readMouse(&mouseStatus); readMouse(&mouseStatus);
populateKeyboardKeydownState(); populateKeyboardKeydownState();
handleRabbitMovement(); handleRabbitMovement();
calculateMouseAngle(); calculateTargetAngle();
waitStartVbl(); waitStartVbl();
@ -287,7 +280,6 @@ int main(void) {
renderRabbit(); renderRabbit();
renderMouse(); renderMouse();
copyDrawBufferToDisplay(); copyDrawBufferToDisplay();
calculateMouseAngle();
waitEndVbl(); waitEndVbl();

View File

@ -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: .c.o:
wcc386 -q -bt=dos -q $< wcc386 -q -bt=dos $<
game.exe: $(obj) 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

3
run Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
dosbox-x game.exe -exit

View File

@ -1,7 +1,7 @@
#ifndef __KEYBOARD_H__ #ifndef __KEYBOARD_H__
#define __KEYBOARD_H__ 1 #define __KEYBOARD_H__ 1
#include "types.h" #include "../types.h"
extern unsigned char keystateBits[]; extern unsigned char keystateBits[];

7
system/makefile Normal file
View File

@ -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:%=+%)

View File

@ -4,7 +4,7 @@
#include <conio.h> #include <conio.h>
#include <dos.h> #include <dos.h>
#include "types.h" #include "../types.h"
extern byte *VGA; extern byte *VGA;

BIN
system/system.lib Normal file

Binary file not shown.

View File

View File

@ -3,8 +3,8 @@
#include <time.h> #include <time.h>
#include "types.h" #include "../types.h"
#include "bmpload.h" #include "../bmpload.h"
#define VGA_DISPLAY_WIDTH (320) #define VGA_DISPLAY_WIDTH (320)
#define VGA_DISPLAY_HEIGHT (200) #define VGA_DISPLAY_HEIGHT (200)