📄 mouse.c
字号:
#define MOUSE_SMALL 1
#define MOUSE_NORMAL 0
#define EXIT_X0 26
#define EXIT_Y0 165
#define EXIT_X1 93
#define EXIT_Y1 182
#define NEW_X0 26
#define NEW_Y0 89
#define NEW_X1 93
#define NEW_Y1 105
#define HISCORE_X0 26
#define HISCORE_Y0 140
#define HISCORE_X1 93
#define HISCORE_Y1 156
#define ABOUT_X0 26
#define ABOUT_Y0 114
#define ABOUT_X1 93
#define ABOUT_Y1 131
#define ABOUTUS_X 120
#define ABOUTUS_Y 0
#define GAMEOVER_X 120
#define GAMEOVER_Y 65
int mouse_visible = 0;
int mouse_smallmode = 0;
unsigned mouse_x = 0, mouse_y = 0, mouse_key = 0;
unsigned mouse_lx = 0, mouse_ly = 0;
int mouse_down = 0, mouse_up = 0, mouse_move = 0;
int mouse_left_down = 0, mouse_left_up = 0;
int mouse_right_down = 0, mouse_right_up = 0;
char far *mouse_back = NULL;
bmp_picture mouse_cur;
char mouse_backcolor;
char far *mouse_showcur_tmp;
void mouse_show(){
union REGS r;
struct SREGS s;
r.x.ax = 1;
int86x(0x33, &r, &r, &s);
mouse_visible = 1;
}
void mouse_hide(){
union REGS r;
struct SREGS s;
r.x.ax = 2;
int86x(0x33, &r, &r, &s);
mouse_visible = 0;
}
void mouse_setxy(unsigned x, unsigned y){
union REGS r;
struct SREGS s;
r.x.ax = 4;
r.x.cx = x;
r.x.dx = y;
int86x(0x33, &r, &r, &s);
mouse_x = x;
mouse_y = y;
if (mouse_smallmode) mouse_x/=2;
}
void mouse_get(){
union REGS r;
struct SREGS s;
r.x.ax = 3;
int86x(0x33, &r, &r, &s);
mouse_x = r.x.cx;
mouse_y = r.x.dx;
mouse_key = r.x.bx;
if (mouse_key & 1)
if (!mouse_left_down)
mouse_left_down = 1;
else;
else
if (mouse_left_down){
mouse_left_up = 1;
mouse_left_down = 0;
}
else
mouse_left_up = 0;
if (mouse_key & 2)
if (!mouse_right_down)
mouse_right_down = 1;
else;
else
if (mouse_right_down){
mouse_right_up = 1;
mouse_right_down = 0;
}
else
mouse_right_up = 0;
mouse_down = mouse_left_down + mouse_right_down;
mouse_up = mouse_left_up + mouse_right_up;
if (mouse_smallmode)
if (mouse_y>=200) mouse_setxy(r.x.cx, 199);
else mouse_x/=2;
if ((mouse_x != mouse_lx) || (mouse_y != mouse_ly)) mouse_move = 1;
else mouse_move = 0;
}
void mouse_getback(){
int i, width;
// if (mouse_x + mouse_cur.info.biWidth >= SCREEN_WIDTH)
// width = SCREEN_WIDTH - mouse_x;
for (i = 0; i < mouse_cur.info.biHeight; i++)
if (i + mouse_y < SCREEN_HEIGHT)
_fmemcpy(&mouse_back[i * mouse_cur.info.biWidth], &video_buffer[(mouse_y + i) * SCREEN_WIDTH + mouse_x], mouse_cur.info.biWidth);
else break;
mouse_lx = mouse_x;
mouse_ly = mouse_y;
}
void mouse_showcur(){
int y, x, i;
for (y = mouse_cur.info.biHeight - 1, i = 0; y >= 0; y--, i++){
if (y + mouse_y >= SCREEN_HEIGHT) continue;
_fmemcpy(mouse_showcur_tmp, &mouse_cur.buffer[i * mouse_cur.info.biWidth], mouse_cur.info.biWidth);
for (x = 0; x < mouse_cur.info.biWidth; x++)
if (x + mouse_x >= SCREEN_WIDTH) break;
else
if (mouse_showcur_tmp[x] != mouse_backcolor)
Plot_Pixel_Fast(x + mouse_x, y + mouse_y, mouse_showcur_tmp[x]);
}
}
void mouse_putback(){
int i, width;
// if (mouse_lx + mouse_cur.info.biWidth >= SCREEN_WIDTH)
// width = SCREEN_WIDTH - mouse_lx;
for (i = 0; i < mouse_cur.info.biHeight; i++)
if (i + mouse_ly < SCREEN_HEIGHT)
_fmemcpy(&video_buffer[(mouse_ly + i) * SCREEN_WIDTH + mouse_lx], &mouse_back[i * mouse_cur.info.biWidth], mouse_cur.info.biWidth);
else break;
}
void mouse_init(char *cur, int smallmode, int x, int y){
BMP_Load(cur, &mouse_cur);
BMP_SetPalette(mouse_cur);
mouse_backcolor = mouse_cur.buffer[0];
mouse_smallmode = smallmode;
mouse_setxy(x, y);
if ((mouse_back = farmalloc(mouse_cur.info.biHeight * mouse_cur.info.biWidth)) == NULL){
printf("Low memory for mouse_back!");
getch();
exit(1);
}
if ((mouse_showcur_tmp = farmalloc(mouse_cur.info.biWidth)) == NULL){
printf("Low memory for mouse_showcur_tmp!");
getch();
exit(1);
}
mouse_getback();
mouse_showcur();
}
void mouse_wait(){
unsigned key;
do{
if (kbhit()){
key = getch();
if (key == 0) key = getch();
break;
}
mouse_get();
if ((mouse_x != mouse_lx) || (mouse_y != mouse_ly)){
mouse_putback();
mouse_getback();
mouse_showcur();
}
sound_gdserver();
}while (!mouse_up);
}
void mouse_fresh(){
mouse_putback();
mouse_getback();
mouse_showcur();
}
int on_exit_btn(){
return (mouse_x >= EXIT_X0) && (mouse_x <= EXIT_X1) && (mouse_y >= EXIT_Y0) && (mouse_y <= EXIT_Y1);
}
int on_diamonds(){
return (mouse_x > 123) && (mouse_x < 316) && (mouse_y > 3) && (mouse_y < 196);
}
int on_new_btn(){
return (mouse_x >= NEW_X0) && (mouse_x <= NEW_X1) && (mouse_y >= NEW_Y0) && (mouse_y <= NEW_Y1);
}
int on_about_btn(){
return (mouse_x >= ABOUT_X0) && (mouse_x <= ABOUT_X1) && (mouse_y >= ABOUT_Y0) && (mouse_y <= ABOUT_Y1);
}
int on_hiscore_btn(){
return (mouse_x >= HISCORE_X0) && (mouse_x <= HISCORE_X1) && (mouse_y >= HISCORE_Y0) && (mouse_y <= HISCORE_Y1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -