more stuff
This commit is contained in:
parent
8cebf1d3f2
commit
c1a514133e
|
@ -6,3 +6,6 @@
|
|||
*.LNK
|
||||
*.o
|
||||
*.exe
|
||||
*.err
|
||||
*.bak
|
||||
*.lib
|
||||
|
|
46
game.c
46
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:
|
||||
|
|
2
makefile
2
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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -10,6 +10,7 @@ struct KeyboardKeydownState {
|
|||
byte KEY_A;
|
||||
byte KEY_S;
|
||||
byte KEY_D;
|
||||
byte KEY_ESC;
|
||||
};
|
||||
|
||||
extern struct KeyboardKeydownState keyboardKeydownState;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 *);
|
||||
|
|
Binary file not shown.
|
@ -50,6 +50,10 @@ void buildSpriteFromSpritesheet(
|
|||
spriteRender->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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue