/* * Supply raw keystrokes when keyboard is open in firm event mode. * * Turn the keystroke into an event and put it in the queue. * If the queue is full, the keystroke is lost (sorry!). */ static void kbd_input_event(struct kbd_softc *k, int code) { struct firm_event *fe; int put; #ifdef DIAGNOSTIC if (!k->k_evmode) { printf("%s: kbd_input_event called when not in event mode\n", device_xname(k->k_dev)); return; } #endif put = k->k_events.ev_put; fe = &k->k_events.ev_q[put]; put = (put + 1) % EV_QSIZE; if (put == k->k_events.ev_get) { log(LOG_WARNING, "%s: event queue overflow\n", device_xname(k->k_dev)); return; } fe->id = KEY_CODE(code); fe->value = KEY_UP(code) ? VKEY_UP : VKEY_DOWN; getmicrotime(&fe->time); k->k_events.ev_put = put; EV_WAKEUP(&k->k_events); }
////////////////////////////////////////////////////////////////////////// // 娱乐模式 void CGameCore::GameEntertainment( DWORD inc ) { if (1 == g_MenuStateSub) { NotFinished(inc); if (KEY_UP(27)) { g_GameState = 1; } } if (2 == g_MenuStateSub) { NotFinished(inc); if (KEY_UP(27)) { g_GameState = 1; } } }
/* * Turn keyboard up/down codes into a KEYSYM. * Note that the "kd" driver (on sun3 and sparc64) uses this too! */ int kbd_code_to_keysym(struct kbd_state *ks, int c) { u_short *km; int keysym; /* * Get keymap pointer. One of these: * release, control, shifted, normal, ... */ if (KEY_UP(c)) km = ks->kbd_k.k_release; else if (ks->kbd_modbits & KBMOD_CTRL_MASK) km = ks->kbd_k.k_control; else if (ks->kbd_modbits & KBMOD_SHIFT_MASK) km = ks->kbd_k.k_shifted; else km = ks->kbd_k.k_normal; if (km == NULL) { /* * Do not know how to translate yet. * We will find out when a RESET comes along. */ return KEYSYM_NOP; } keysym = km[KEY_CODE(c)]; /* * Post-processing for Caps-lock */ if ((ks->kbd_modbits & (1 << KBMOD_CAPSLOCK)) && (KEYSYM_CLASS(keysym) == KEYSYM_ASCII) ) { if (('a' <= keysym) && (keysym <= 'z')) keysym -= ('a' - 'A'); } /* * Post-processing for Num-lock. All "function" * keysyms get indirected through another table. * (XXX: Only if numlock on. Want off also!) */ if ((ks->kbd_modbits & (1 << KBMOD_NUMLOCK)) && (KEYSYM_CLASS(keysym) == KEYSYM_FUNC) ) { keysym = kbd_numlock_map[keysym & 0x3F]; } return keysym; }
static void process_key ( int down, int vkey, int repeat, int scancode, int extended, HWND wnd ) { if ( down && KEY_DOWN(vkey) ) return; /* ignore key repeat, bad states */ if ( !down && KEY_UP(vkey) ) return; /* ignore bad states */ if ( g_Input != NULL && g_Input->iInputEnabled || GetForegroundWindow() != wnd //|| 0x90 == *(uint8_t *)0x541DF5 ) { if ( !down && KEY_DOWN(vkey) ) key_table[vkey].count++; return; } key_table[vkey].count++; }
static void kbd_input_wskbd(struct kbd_softc *k, int code) { int type, key; #ifdef WSDISPLAY_COMPAT_RAWKBD if (k->k_wsraw) { u_char buf; buf = code; wskbd_rawinput(k->k_wskbd, &buf, 1); return; } #endif type = KEY_UP(code) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN; key = KEY_CODE(code); wskbd_input(k->k_wskbd, type, key); }
int kbdintr(void *arg) { u_char c, st; struct kbd_softc *sc = arg; struct firm_event *fe; int put; /* clear receiver error if any */ st = mfp_get_rsr(); c = mfp_get_udr(); if ((st & MFP_RSR_BF) == 0) return 0; /* intr caused by an err -- no char received */ /* if not in event mode, deliver straight to ite to process key stroke */ if (!sc->sc_event_mode) { kbdbuf[kbdputoff++ & KBDBUFMASK] = c; softint_schedule(sc->sc_softintr_cookie); return 0; } /* Keyboard is generating events. Turn this keystroke into an event and put it in the queue. If the queue is full, the keystroke is lost (sorry!). */ put = sc->sc_events.ev_put; fe = &sc->sc_events.ev_q[put]; put = (put + 1) % EV_QSIZE; if (put == sc->sc_events.ev_get) { log(LOG_WARNING, "keyboard event queue overflow\n"); /* ??? */ return 0; } fe->id = KEY_CODE(c); fe->value = KEY_UP(c) ? VKEY_UP : VKEY_DOWN; firm_gettime(fe); sc->sc_events.ev_put = put; softint_schedule(sc->sc_softintr_cookie); return 0; }
bool bgDInput::IsKeyUp(DWORD dwKey) { if (m_dwImmediate) { if (m_KeyStateBefore[dwKey] & 0x80) { if (KEY_UP(dwKey)) return true; } } else { for (DWORD i = 0; i < m_dwElements; i++) { if ((m_KeyDOD[i].dwOfs == dwKey) && !(m_KeyDOD[i].dwData & 0x80)) return true; } } return false; }
void updateGameOverState(GameOverState* state, unsigned long scancode) { if (scancode == KEY_UP(KEY_ENTER)) state->done = 1; }
int single_game(){ Audio RRR; openAudioFile(".\\wav\\RRR.wav", &RRR); initializeKeyInput(); Character yg = characterMaking1(".\\pic\\yg.pixel",".\\pic\\yg.color"); int key_val[NUM_KEYS]={VK_A,VK_D,VK_ESCAPE}; int stand=0,score=0,standBrick,pDown1,pDown2; double drop=0,scoreCount=0; Brick bricks[15]; int i,j,k; char scoreStr[4]={'0'}; for(i=0;i<10;i++){ bricks[i].y=-1; bricks[i].w=40; bricks[i].h=2; if(i%2==0)bricks[i].color=15; else if(i<=5)bricks[i].color=8; else if(i>5)bricks[i].color=12; else bricks[i].color=10; } bricks[0].x=0; bricks[0].y=100; Font *large_font=read_font("font.txt"); float lastbrick=0; int hp = 10,second=0; float rate=0.15; while(1){ clearScreen(); srand(clock()); for(i=0;i<10;i++){ if(bricks[i].y>0)bricks[i].y--; else if(bricks[i].y==0)bricks[i].y=-100; for(k=0;k<2;k++){ for(j=0;j<bricks[k].w;j++){ putString(bricks[i].x+j,bricks[i].y+k,"=",bricks[i].color,0); } } } if(score>50){ rate = 0.2; } else if(score>75){ rate = 0.25; } else if(score>100){ rate = 0.3; } if((float)clock()/(float)CLOCKS_PER_SEC-(float)lastbrick>rate&&rand()%10==1){ for(i=0;i<10;i++){ if(bricks[i].y<0){ bricks[i].y=170; bricks[i].x=rand()%185; lastbrick=(float)clock()/(float)CLOCKS_PER_SEC; for(k=0;k<2;k++){ for(j=0;j<bricks[i].w;j++){ putString(bricks[i].x+j,bricks[i].y+k,"=",bricks[i].color,0); } } break; } } } for(k=0;k<10;k++){ if(abs(yg.y+yg.h-bricks[k].y)<=2&&( (yg.x+yg.w>bricks[k].x&&yg.x+yg.w<bricks[k].x+bricks[k].w)|| (yg.x>bricks[k].x&&yg.x<bricks[k].x+bricks[k].w))){ stand=1; standBrick=k; yg.y=bricks[k].y-yg.h; break; } else if(k==9){ stand=0; standBrick=-1; } } if(stand==1){ drop=0; second++; if(bricks[standBrick].color==15&&second==15){ second=0; if(hp<10)hp++; } else if(bricks[standBrick].color==12){ second++; if(second==20){ second=0; hp--; playAudio(&RRR); } } else if(bricks[standBrick].color==8){ if(second==10){ second=0; bricks[standBrick].y=-100; } } } else{ if(drop<2)drop+=0.5; yg.y+=(int)drop; second=0; } if(yg.y<0){ yg.y+=10; drop=3; hp-=4; playAudio(&RRR); } for (k = 0 ; k < NUM_KEYS ; k++){ if(KEY_DOWN(key_val[k])){ switch (key_val[k]){ case VK_A: if(yg.x>=0)yg.x-=5; break; case VK_D: if(yg.x+yg.w<225)yg.x+=5; break; case VK_ESCAPE: return 3; break; } } } show_image(yg.pic,yg.x,yg.y); for(i=0;i<225;i++){ for(j=151;j<=170;j++){ putString(i,j," ",0,0); } } putStringLarge(large_font,159,158,"HP ",15); putStringLarge(large_font,159,152,"STAGE ",15); scoreCount++; score = (pow(scoreCount/300,1.5)); scoreStr[0]=score/100+'0'; scoreStr[1]=score/10%10+'0'; scoreStr[2]=score%10+'0'; putStringLarge(large_font,201,152,scoreStr,15); for(i=0;i<hp;i++){ for(j=1;j<5;j++){ for(k=0;k<=4;k++)putString(180+i*4+j,158+k,"|",12,0); } } for(i=0;i<225;i++)putString(i,0,"V",12,0); for(i=0;i<225;i++){ putString(i,149,"=",12,0); } for(i=0;i<150;i++){ putString(0,i,"|",0,12); putString(224,i,"|",0,12); } drawCmdWindow(); if(yg.y>150||hp<=0){ break; }; if(KEY_UP(VK_P)&&pDown1)pDown1=0; if(KEY_UP(VK_P)&&pDown2)pDown2=0; if(KEY_DOWN(VK_P)&&!pDown1){ pDown1=1; putStringLarge(large_font,45,70,"Press P to continue",12); drawCmdWindow(); Sleep(500); while(1){ if(KEY_DOWN(VK_P)&&!pDown2){ pDown2=1; break; } } } Sleep(20); } pauseAudio(&RRR); Image * jh =read_image(".\\pic\\jh.pixel",".\\pic\\jh.color"); show_image(jh,15,30); putStringLarge(large_font,75,80,"SCORE ",15); putStringLarge(large_font,120,80,scoreStr,15); drawCmdWindow(); Audio *barbar; openAudioFile(".\\wav\\88wav.wav",&barbar); playAudio(&barbar); Sleep(3500); int flagg = 1; putStringLarge(large_font, 45, 90, "Press esc to exit", 15); drawCmdWindow(); while(flagg){ if(KEY_DOWN(VK_ESCAPE))return 3; } clearScreen(); }
static LRESULT CALLBACK wnd_proc ( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lparam ) { if (gta_menu_active()) goto wnd_proc_original; switch ( umsg ) { case WM_LBUTTONDOWN: case WM_LBUTTONUP: process_key( (umsg == WM_LBUTTONDOWN), VK_LBUTTON, 0, 0, 0, wnd ); break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: process_key( (umsg == WM_RBUTTONDOWN), VK_RBUTTON, 0, 0, 0, wnd ); break; case WM_MBUTTONDOWN: case WM_MBUTTONUP: process_key( (umsg == WM_MBUTTONDOWN), VK_MBUTTON, 0, 0, 0, wnd ); break; /* :D */ case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_KEYDOWN: case WM_KEYUP: { unsigned long p = (unsigned long)lparam; int down = ( umsg == WM_KEYDOWN || umsg == WM_SYSKEYDOWN ); int vkey = (int)wparam; key_being_pressed = vkey; unsigned int repeat = ( p >> 0 ) & 0x7FFF; unsigned int scancode = ( p >> 16 ) & 0x00FF; unsigned int extended = ( p >> 24 ) & 0x0001; if ( cheat_state == NULL ) break; /* :D :D :D :D :D */ switch ( vkey ) { case VK_SHIFT: if ( scancode == MapVirtualKey(VK_LSHIFT, 0) ) vkey = VK_LSHIFT; else if ( scancode == MapVirtualKey(VK_RSHIFT, 0) ) vkey = VK_RSHIFT; break; case VK_CONTROL: if ( scancode == MapVirtualKey(VK_LCONTROL, 0) ) vkey = VK_LCONTROL; else if ( scancode == MapVirtualKey(VK_RCONTROL, 0) ) vkey = VK_RCONTROL; break; case VK_MENU: if ( scancode == MapVirtualKey(VK_LMENU, 0) ) vkey = VK_LMENU; else if ( scancode == MapVirtualKey(VK_RMENU, 0) ) vkey = VK_RMENU; break; } /* :D */ if ( KEY_DOWN(VK_LMENU) && vkey == VK_LMENU && down ) break; if ( KEY_UP(VK_LMENU) && vkey == VK_LMENU && !down ) break; process_key( down, vkey, repeat, scancode, extended, wnd ); /* XXX move this */ if ( cheat_state->debug_enabled && ( (vkey >= VK_NUMPAD1 && vkey <= VK_NUMPAD9) || vkey == VK_DIVIDE || vkey == VK_MULTIPLY || vkey == VK_SUBTRACT || vkey == VK_ADD ) ) { return 0; } /* XXX move this */ if ( cheat_state->_generic.menu && ( vkey == set.key_menu_up || vkey == set.key_menu_right || vkey == set.key_menu_down || vkey == set.key_menu_left || vkey == set.key_menu_select ) ) { return 0; } } break; } wnd_proc_original: return CallWindowProc( orig_wndproc, wnd, umsg, wparam, lparam ); }
int keyhook_key_released ( int v ) { return KEY_UP( v ) && key_table[v].pstate; }
//----------------------------------------------------------------- // Name: ProcessInput() // Desc: Handles Keyboard presses //----------------------------------------------------------------- void CTetris::ProcessInput( ) { if( KEY_DOWN(VK_LEFT) ) { for(int i=0; i<BLOCKS_PER_TET; i++) if( !Collision(m_CurrentTet.tet[i].iX - 1, m_CurrentTet.tet[i].iY) ) return; TranslateCurrTet(m_CurrentTet.iX - 1, m_CurrentTet.iY); //m_Replay.KeyStrokeLogger( VK_LEFT, m_nCurrentTetName ); } if( KEY_DOWN(VK_RIGHT) ) { for(int i=0; i<BLOCKS_PER_TET; i++) if( !Collision( m_CurrentTet.tet[i].iX + 1, m_CurrentTet.tet[i].iY ) ) return; TranslateCurrTet(m_CurrentTet.iX + 1, m_CurrentTet.iY); } if( KEY_DOWN(VK_DOWN) ) m_fCurrFallDelay = FAST_FALL; if( KEY_UP(VK_DOWN) ) m_fCurrFallDelay = m_fFallDelay[m_nLevel]; if( KEY_DOWN(VK_ESCAPE) ) { if( !m_bKeyState[VK_ESCAPE] ) m_bExit = true; m_bKeyState[VK_ESCAPE] = true; } if( KEY_UP(VK_ESCAPE) ) m_bKeyState[VK_ESCAPE] = false; if( KEY_DOWN(VK_LSHIFT) ) { if( !m_bKeyState[VK_LSHIFT] ) RotateCurrTet(CW); m_bKeyState[VK_LSHIFT] = true; } if( KEY_UP(VK_LSHIFT) ) { m_bKeyState[VK_LSHIFT] = false; } if( KEY_DOWN(VK_UP) ) { if( !m_bKeyState[VK_UP] ) RotateCurrTet(CW); m_bKeyState[VK_UP] = true; } if( KEY_UP(VK_UP) ) { m_bKeyState[VK_UP] = false; } if( KEY_DOWN(VK_LCONTROL) ) { if( !m_bKeyState[VK_LCONTROL] ) RotateCurrTet(CCW); m_bKeyState[VK_LCONTROL] = true; } if( KEY_UP(VK_LCONTROL) ) m_bKeyState[VK_LCONTROL] = false; if(KEY_DOWN(VK_RETURN)) { if( !m_bKeyState[VK_RETURN] ) m_bPause = !m_bPause; m_bKeyState[VK_RETURN] = true; } if( KEY_UP(VK_RETURN) ) m_bKeyState[VK_RETURN] = false; }
////////////////////////////////////////////////////////////////////////// // 游戏结束 void CGameCore::GameOver( DWORD inc ) { ////////////////////////////////////////////////////////////////////////// // 单人模式 if (1 == g_MenuStateMain) { // 计算得分 TTscore = timeFlash*100+300.0*excellentNum; // 记录高分 switch(g_MenuStateSub) { case 1: // 常规游戏 if (timeFlash > HIGHtime[g_MenuStateSub]) { HIGHtime[g_MenuStateSub] = timeFlash; } if (excellentNum > HIGHexce[g_MenuStateSub]) { HIGHexce[g_MenuStateSub] = excellentNum; } if (TTscore > HIGHscore[g_MenuStateSub]) { HIGHscore[g_MenuStateSub] = TTscore; } break; case 2: // 高速模式 if (timeFlash > HIGHtime[g_MenuStateSub]) { HIGHtime[g_MenuStateSub] = timeFlash; } if (excellentNum > HIGHexce[g_MenuStateSub]) { HIGHexce[g_MenuStateSub] = excellentNum; } if (TTscore > HIGHscore[g_MenuStateSub]) { HIGHscore[g_MenuStateSub] = TTscore; } break; case 3: // 多弹模式 if (timeFlash > HIGHtime[g_MenuStateSub]) { HIGHtime[g_MenuStateSub] = timeFlash; } if (excellentNum > HIGHexce[g_MenuStateSub]) { HIGHexce[g_MenuStateSub] = excellentNum; } if (TTscore > HIGHscore[g_MenuStateSub]) { HIGHscore[g_MenuStateSub] = TTscore; } break; } glColor3f(1,1,1); // 画出游戏模式 g_myModel.TextureSquareTGA(0,5,0,6,2,g_MenuStateSub+5); // 按回车开始游戏 g_myModel.TextureSquareTGA(0,1.5,0,9,1,20); // 时间 g_myModel.TextureSquareTGA(-2.2,-1.5,0,1.3,0.7,21); // 绝妙 g_myModel.TextureSquareTGA(0.5,-1.5,0,1.3,0.7,22); // 得分 g_myModel.TextureSquareTGA(3.0,-1.5,0,1.3,0.7,23); // 本次 g_myModel.TextureSquareTGA(-4.5,-2.65,0,1.3,0.7,24); if (g_MenuStateSub != 4 && g_MenuStateSub != 5) { // 最高 g_myModel.TextureSquareTGA(-4.5,-3.9,0,1.3,0.7,26); } glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,g_Width,0,g_Height,-1,1); // 设置为正投影 glMatrixMode(GL_MODELVIEW); glColor3f(0.0,1.0,0.0); // 当前时间 g_myModel.glPrint(g_Width*300/800, g_Height*190/600,"%.2f",timeFlash); // 当前绝妙 g_myModel.glPrint(g_Width*410/800, g_Height*190/600,"%d",excellentNum); // 当前总分 g_myModel.glPrint(g_Width*490/800, g_Height*190/600,"%d",TTscore); // 低难度模式没有记录 if (g_MenuStateSub != 4 && g_MenuStateSub != 5) { // 最高时间 g_myModel.glPrint(g_Width*300/800, g_Height*140/600,"%.2f",HIGHtime[g_MenuStateSub]); // 最高绝妙 g_myModel.glPrint(g_Width*410/800, g_Height*140/600,"%d",HIGHexce[g_MenuStateSub]); // 最高总分 g_myModel.glPrint(g_Width*490/800, g_Height*140/600,"%d",HIGHscore[g_MenuStateSub]); } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } ////////////////////////////////////////////////////////////////////////// // 双人游戏 if (2 == g_MenuStateMain) { // 画出游戏模式 g_myModel.TextureSquareTGA(0,6,0,6,2,g_MenuStateSub+10); // 按回车开始游戏 g_myModel.TextureSquareTGA(0,-2.5,0,8,0.7,20); // 时间 g_myModel.TextureSquareTGA(-0.5,-4.5,0,1.3,0.7,21); // 绝妙 玩家1 g_myModel.TextureSquareTGA(-6,-3.5,0,1.3,0.7,22); // 绝妙 玩家2 g_myModel.TextureSquareTGA(6,-3.5,0,1.3,0.7,22); switch(win) { case 0: // 平局 g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 29); g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 29); break; case 1: // 玩家1 胜 g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 28); g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 27); break; case 2: // 玩家2 胜 g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 27); g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 28); break; } } // 开始游戏 if ( KEY_UP(13) || KEY_UP(32) ) { gameOver = false; InitGame(); } // 返回上级菜单 if (KEY_UP(27)) { g_GameState = 1; initGame = false; } }
////////////////////////////////////////////////////////////////////////// // 双人游戏 void CGameCore::GameDoublePlayer( DWORD inc ) { if (true == gameOver) { GameOver(inc); } else { // 玩家1 —— P1 if (KEY_DOWN(87)) { Player1MoveUp(inc); } if (KEY_DOWN(83)) { Player1MoveDown(inc); } if (KEY_DOWN(65)) { Player1MoveLeft(inc); } if (KEY_DOWN(68)) { Player1MoveRight(inc); } // 玩家2 —— P2 if (KEY_DOWN(38)) { Player2MoveUp(inc); } if (KEY_DOWN(40)) { Player2MoveDown(inc); } if (KEY_DOWN(37)) { Player2MoveLeft(inc); } if (KEY_DOWN(39)) { Player2MoveRight(inc); } // 检测绝妙的临时变量 int tmpI = -1,tmpI2 = -1; // 画出子弹 for (int i = 0; i<nowBullet; i++) { m_Bullet->DrawBullet(m_Bullet[i].x, m_Bullet[i].y, BULLET_R, -1); m_Bullet[i].x += float(nowSpeed*inc) * m_Bullet[i].v_x; m_Bullet[i].y += float(nowSpeed*inc) * m_Bullet[i].v_y; // 检测越界 if (m_Bullet[i].y < BOUNDARY_BOTTOM-0.1 || m_Bullet[i].y > BOUNDARY_TOP+0.1 || m_Bullet[i].x > BOUNDARY_RIGHT+0.1 || m_Bullet[i].x < BOUNDARY_LEFT-0.1) { m_Bullet[i].InitBullet((m_Player1.x + m_Player2.x)/2 , (m_Player1.y+m_Player2.y)/2); } ////////////////////////////////////////////////////////////////////////// // 碰撞检测——玩家1 与 子弹 float tmpX = m_Bullet[i].x - m_Player1.x; float tmpY = m_Bullet[i].y - m_Player1.y; if (sqrt(tmpX*tmpX+tmpY*tmpY) < PLAYER_R + BULLET_R -0.1) { gameOver = true; win = 2; } // 检测 玩家1 绝妙 if(false == m_Player1.b_excl) { if (sqrt(tmpX*tmpX+tmpY*tmpY) < PLAYER_R + BULLET_R + 0.3) { // 本次循环所有点,第一次找到满足条件 if (tmpI == -1) { tmpI = i; } // 两个不同的点,并且角力大于玩家与子弹距离的总和 else if ((i != tmpI)&&(sqrt((m_Bullet[i].x-m_Bullet[tmpI].x)*(m_Bullet[i].x-m_Bullet[tmpI].x)+(m_Bullet[i].y-m_Bullet[tmpI].y)*(m_Bullet[i].y-m_Bullet[tmpI].y))>PLAYER_R + BULLET_R)) { excl_x = m_Player1.x; excl_y = m_Player1.y; m_Player1.b_excl = true; maybeExcl = true; excl_time = timeCount; } } } ////////////////////////////////////////////////////////////////////////// // 碰撞检测——玩家2 与 子弹 tmpX = m_Bullet[i].x - m_Player2.x; tmpY = m_Bullet[i].y - m_Player2.y; if (sqrt(tmpX*tmpX+tmpY*tmpY) < PLAYER_R + BULLET_R -0.1) { gameOver = true; win = 1; } // 检测 玩家2 绝妙 if(false == m_Player2.b_excl) { if (sqrt(tmpX*tmpX+tmpY*tmpY) < PLAYER_R + BULLET_R + 0.3) { // 本次循环所有点,第一次找到满足条件 if (tmpI2 == -1) { tmpI2 = i; } // 两个不同的点,并且角力大于玩家与子弹距离的总和 else if ((i != tmpI2)&&(sqrt((m_Bullet[i].x-m_Bullet[tmpI2].x)*(m_Bullet[i].x-m_Bullet[tmpI2].x)+(m_Bullet[i].y-m_Bullet[tmpI2].y)*(m_Bullet[i].y-m_Bullet[tmpI2].y))>PLAYER_R + BULLET_R)) { excl_x2 = m_Player2.x; excl_y2 = m_Player2.y; m_Player2.b_excl = true; maybeExcl2 = true; excl_time2 = timeCount; } } } ////////////////////////////////////////////////////////////////////////// // 玩家与玩家互撞 tmpX = m_Player1.x - m_Player2.x; tmpY = m_Player1.y - m_Player2.y; if (sqrt(tmpX*tmpX+tmpY*tmpY) < PLAYER_R * 2 -0.05) { gameOver = true; win = 0; } } } // 合作模式连线 if (g_MenuStateSub == 2) { const float dNear = 1.5; const float dFar = 12; const float dMid = dNear + (dFar - dNear)/2; float dplanes = sqrt((m_Player1.x-m_Player2.x)*(m_Player1.x-m_Player2.x)+(m_Player1.y-m_Player2.y)*(m_Player1.y-m_Player2.y)); if (dplanes < dNear || dplanes > dFar) { gameOver = true; } else { glLineWidth(5); glColor3f(abs(dplanes-dMid)/(dMid-dNear),1-abs(dplanes-dMid)/(dMid-dNear),0); glBegin(GL_LINES); glVertex3f(m_Player1.x,m_Player1.y,-0.1); glVertex3f(m_Player2.x,m_Player2.y,-0.1); glEnd(); glColor3f(1,1,1); } } //画出玩家 m_Player1.DrawPlayer(m_Player1.x, m_Player1.y,PLAYER_R,40); m_Player2.DrawPlayer(m_Player2.x, m_Player2.y,PLAYER_R,41); // 画出子弹 for (int i = 0; i<nowBullet; i++) { m_Bullet[i].DrawBullet(m_Bullet[i].x, m_Bullet[i].y, BULLET_R, -1); } // 画出 玩家1 绝妙 if ((true == m_Player1.b_excl)&&(timeCount - excl_time > 220)) { if (maybeExcl) { // 绝妙 excellentNum++; maybeExcl = false; } m_Player1.DrawExcellent(excl_x, excl_y,inc); } // 画出 玩家2 绝妙 if ((true == m_Player2.b_excl)&&(timeCount - excl_time2 > 220)) { if (maybeExcl2) { // 绝妙 excellentP2++; maybeExcl2 = false; } m_Player2.DrawExcellent(excl_x2, excl_y2,inc); } ////////////////////////////////////////////////////////////////////////// // 测试 if (KEY_UP(27)) { gameOver = true; } }