void BacteroidsState::OnKeyPress(Keyboard::Key key, Keyboard::Scancode scancode, uint32_t mods) { if (key == Keyboard::Key::Escape) TogglePause(); if (m_time.IsPaused()) { if (key == Keyboard::Key::Q) { ChangeState(STATE_MENU); GetWindow().UnGrabMouse(); } } if (key == Keyboard::Key::M) GetAudio().ToggleMute(); if (m_player.IsDead()) { if (key == Keyboard::Key::Space) { m_gameData.m_score = m_score; ChangeState(STATE_HIGH_SCORE); GetWindow().UnGrabMouse(); } } }
void Engine::OnKeyDown(SDLKey key, SDLMod mod) { if(mod & KMOD_LALT) { if(key == SDLK_F4) SetQuit(true); else if(key == SDLK_RETURN) ToggleFullscreen(); } //if(mod & KMOD_CTRL) { if(key == SDLK_F1) ToggleDebugFlag(EDBG_COLLISION_MAP_OVERLAY); else if(key == SDLK_F2) ToggleDebugFlag(EDBG_HIDE_SPRITES); else if(key == SDLK_F3) ToggleDebugFlag(EDBG_HIDE_LAYERS); else if(key == SDLK_F4) ToggleDebugFlag(EDBG_SHOW_BBOXES); } if(key == SDLK_PAUSE) { TogglePause(); } }
void CamStatusView::MessageReceived(BMessage *message) { switch (message->what) { case B_OBSERVER_NOTICE_CHANGE: { int32 what; message->FindInt32("be:observe_change_what", &what); switch (what) { case kMsgControllerCaptureStarted: SetRecording(true); break; case kMsgControllerCaptureStopped: if (fPaused) fPaused = false; SetRecording(false); break; case kMsgControllerCapturePaused: case kMsgControllerCaptureResumed: TogglePause(what == kMsgControllerCapturePaused); break; case kMsgControllerEncodeStarted: fEncodingStringView->SetText(kEncodingString); ((BCardLayout*)GetLayout())->SetVisibleItem(1); break; case kMsgControllerEncodeProgress: { int32 totalFrames = 0; if (message->FindInt32("frames_total", &totalFrames) == B_OK) { fStatusBar->SetMaxValue(float(totalFrames)); } int32 remainingFrames = 0; if (message->FindInt32("frames_remaining", &remainingFrames) == B_OK) { BString string = kEncodingString; string << " (" << remainingFrames << " frames)"; fEncodingStringView->SetText(string); } fStatusBar->Update(1); break; } case kMsgControllerEncodeFinished: { ((BCardLayout*)GetLayout())->SetVisibleItem((int32)0); break; } default: break; } break; } default: BView::MessageReceived(message); break; } }
void GameTable::HandleSDLMouseEvent(SDL_Event& event) { if (state != GameTableState::Running && state != GameTableState::Paused) { ClearBlocks(false); return; } // Clear button state btnAddColumn->highlighted = false; btnPauseGame->highlighted = false; // Mouse position auto mousePos = SDL_Point{ event.button.x, event.button.y }; // Clear highlight state ClearBlocks(false); if (SDL_EnclosePoints(&mousePos, 1, tableDelimiter, nullptr) == SDL_TRUE) { // We are over the table if (state == GameTableState::Running) { ProcessInputOnBlocks(mousePos, event); } } else if (SDL_EnclosePoints(&mousePos, 1, &(btnAddColumn->rect), nullptr) == SDL_TRUE) { // We are over the add new column button btnAddColumn->highlighted = true; // We check if we can add a new column if (event.button.state == SDL_PRESSED && table->size() < colLimit) { // Add the new column AddNewColumn(); // Restart the timer for the new column timer->start(); } } else if (SDL_EnclosePoints(&mousePos, 1, &(btnPauseGame->rect), nullptr) == SDL_TRUE) { // We are over the pause button btnPauseGame->highlighted = true; if (event.button.state == SDL_PRESSED) { // Let's pause the game TogglePause(); } } }
virtual void OnAction(int id) override { switch (id) { case CLEAR: Clear(); break; case RECONNECT: Reconnect(); break; case PAUSE: TogglePause(); break; } }
void Controller::MessageReceived(BMessage *message) { switch (message->what) { case kSelectionWindowClosed: { SendNotices(kMsgControllerSelectionWindowClosed, message); BRect rect; if (message->FindRect("selection", &rect) == B_OK) { SetCaptureArea(rect); } break; } case kMsgGUIStartCapture: case kMsgGUIStopCapture: if (fEncoderThread < 0) ToggleCapture(message->what == kMsgGUIStartCapture); break; case kPauseCapture: case kResumeCapture: TogglePause(message->what == kPauseCapture); break; case kEncodingFinished: { status_t error; message->FindInt32("status", (int32*)&error); _EncodingFinished(error); break; } case B_UPDATE_STATUS_BAR: case B_RESET_STATUS_BAR: SendNotices(message->what, message); break; default: BLooper::MessageReceived(message); break; } }
/**************************************************************************** * Shutdown * * - Cleans up and terminates ASTEROID, returning any error conditions. * * - Receives error code. * ****************************************************************************/ VOID Shutdown(ULONG ulErrLevel) { /* Stop the timer. */ TogglePause(FORCE_PAUSE); /* Destroy the help instance if it was created */ if (hwndHelp != NULLHANDLE) { WinAssociateHelpInstance(NULLHANDLE, hwndFrame); WinDestroyHelpInstance(hwndHelp); } /* Destroy Object and Frame windows. */ if (hwndObject != NULLHANDLE) WinDestroyWindow(hwndObject); if (hwndFrame != NULLHANDLE) WinDestroyWindow(hwndFrame); /* Destroy the message queue and let PM clean up. */ WinDestroyMsgQueue(hmq); WinTerminate(hab); /* Return error code if any. */ DosExit(EXIT_PROCESS, ulErrLevel); }
void HK_Pause(int, bool justPressed) { if(justPressed) TogglePause(); }
void CLife::OnKeyUp( SDLKey sym, SDLMod mod, Uint16 unicode ) { switch ( sym ) { case SDLK_RIGHT: { Pause(); break; } case SDLK_s: { Pause(); Save(); break; } case SDLK_RETURN: { TogglePause(); break; } case SDLK_UP: case SDLK_PLUS: case SDLK_KP_PLUS: case SDLK_PERIOD: { Framerate->raiseFPS(); break; } case SDLK_DOWN: case SDLK_MINUS: case SDLK_KP_MINUS: case SDLK_COMMA: { Framerate->lowerFPS(); break; } case SDLK_e: { ToggleEditMode(); break; } case SDLK_h: { //Pause(); TogglePause(); Stabilize(); ToggleStepping(); TogglePause(); break; } case SDLK_c: { SwitchColours(); break; } case SDLK_r: { Reset(); break; } //Patterns: case SDLK_0: case SDLK_KP0: { Patternify(0); break; } case SDLK_1: case SDLK_KP1: { Patternify(1); break; } case SDLK_2: case SDLK_KP2: { Patternify(2); break; } case SDLK_3: case SDLK_KP3: { Patternify(3); break; } case SDLK_7: case SDLK_KP7: case SDLK_x: { Patternify(7); break; } case SDLK_8: case SDLK_KP8: { Patternify(8); break; } case SDLK_9: case SDLK_KP9: { Patternify(9); break; } default: { break; } } }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; BOOL done = FALSE; if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) fullscreen = FALSE; InitVars(); // Create Our OpenGL Window if (!CreateGLWindow("Arkanoid",640,480,16,fullscreen)) { return 0; } srand(time(NULL)); while(!done) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message == WM_QUIT) { done = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else if (active) { if (keys[VK_ESCAPE]) done = TRUE; if (keys[78] && (gof)) { done = TRUE; gof = false; } // 78 -- n, 89 -- y if (keys[89] && (gof)) { gameOver = TRUE; flag = 0;/*TogglePause();*/ idle(); DrawGLScene(); SwapBuffers(hDC); gof = false; } else { if ( keys[VK_SPACE] ) { bflag = true;} if(bflag){ if (keys[VK_PAUSE]){ TogglePause(); } if(pause) { DrawGLScene(); SwapBuffers(hDC); } else{ idle(); DrawGLScene(); SwapBuffers(hDC); } } else { DrawLoadScreen (); SwapBuffers(hDC); } } if (!ProcessKeys()) return 0; } } // Shutdown KillGLWindow(); glDeleteTextures(4,texture); return (msg.wParam); }
int main(int argc, char *argv[]) { int size; int curarg; uint8 *buf; Interface = SexyAL_Init(0); DriverTypes = Interface->EnumerateTypes(Interface); puts("\n*** Festalon v"FESTALON_VERSION); if(argc<=1) { printf("\tUsage: %s [options] file1.nsf file2.nsf ... fileN.nsf\n\n",argv[0]); puts("\tExample Options:"); puts("\t -rate 44100\t\tSet playback rate to 44100Hz(default: 48000Hz)."); puts("\t -quality 1\t\tSet quality to 1, the highest(the lowestis 0; default: 0)."); puts("\t -volume 200\t\tSet volume to 200%(default: 100%)."); puts("\t -buffering 100\t\tSet desired buffering level to 100 milliseconds(default: 100)."); puts("\t -lowpass 1\t\tTurn on lowpass filter(default: 0)."); puts("\t -lowpasscorner 8000\tSet lowpass corner frequency(at which the response is about -3dB) to 8000Hz(default: 10000Hz)."); puts("\t -lowpassorder 2\tSet lowpass filter order to 2(default: 2)."); puts("\t -record filename.wav\tRecords audio in MS PCM format. An existing file won't be overwritten."); puts("\t\t\t\tWhen playing multiple files, only the first opened file will have its music recorded."); puts("\t -ao x\t\t\tSelect output type/driver. Valid choices are:"); { int x = 0; while(DriverTypes[x].name) { printf("\t\t\t\t %s - %s",DriverTypes[x].short_name,DriverTypes[x].name); if(!x) printf("\t(*Default*)"); puts(""); x++; } } puts("\t -aodevice id\t\tSelect output device by id. The default is \"NULL\", which opens the default/preferred device."); puts("\t\t\t\t Try \"-aodevice help\" to see the list of devices."); Interface->Destroy(Interface); return(-1); } curarg = ParseArguments(argc, argv, TODArgs); if(-1 == (CurDriverIndex = FindCurDriver(DriverTypes, Config.ao))) return(-1); if(Config.aodevice) { if(!strcmp(Config.aodevice,"help")) { SexyAL_enumdevice *devices = Interface->EnumerateDevices(Interface, DriverTypes[CurDriverIndex].type); if(!devices) { printf("\tNo predefined output devices are available with this driver type.\n"); return(-1); } printf("\tOutput devices(ID, name) for \"%s\":\n",DriverTypes[CurDriverIndex].name); while(devices->next) { printf("\t %s, %s\n",devices->id,devices->name); devices = devices->next; } return(-1); } } if(Config.quality != 0 && Config.quality != 1) Config.quality = 0; tcgetattr(0,&oldtio); newtio=oldtio; newtio.c_lflag&=~(ICANON|ECHO); signal(SIGTERM,siggo); signal(SIGINT,siggo); tcsetattr(0,TCSANOW,&newtio); sa = fcntl(fileno(stdin), F_GETFL); fcntl(fileno(stdin), F_SETFL, O_NONBLOCK); for(;curarg < argc && !eexit; curarg++) //while(argc-->1 && !eexit) { FILE *fp; printf("\nLoading %s... ",argv[curarg]); if(!(fp=fopen(argv[curarg],"rb"))) {printf("Error opening file: %s\n",strerror(errno));continue;} fseek(fp,0,SEEK_END); size=ftell(fp); fseek(fp,0,SEEK_SET); buf=malloc(size); fread(buf,1,size,fp); fclose(fp); if(!(Player=FESTAI_Load(buf,size) )) { puts("Error loading file!"); free(buf); continue; } free(buf); puts(""); memset(&format, 0, sizeof(format)); memset(&buffering, 0, sizeof(buffering)); format.sampformat = SEXYAL_FMT_PCMFLOAT; format.channels = Player->OutChannels; format.rate = Config.rate; buffering.fragsizems = 10; // Granularity. buffering.ms = Config.buffering; printf(" Using \"%s\" audio driver:",DriverTypes[CurDriverIndex].name); if(!(Output=Interface->Open(Interface,Config.aodevice,&format,&buffering, DriverTypes[CurDriverIndex].type))) { puts("Error opening sound device."); continue; //return(-1); } putchar('\n'); printf(" Playback Rate:\t%dHz\n",format.rate); printf(" Output Channels:\t%d\n",format.channels); printf(" Output Format:\t"); if(format.sampformat == SEXYAL_FMT_PCMFLOAT) puts("\t32-bit Floating Point"); else { if(format.sampformat&0x1) printf("Signed, "); else printf("Unsigned, "); printf("%d bits\n",(format.sampformat >> 4) << 3); } printf(" Estimated Latency:\t%d ms\n",buffering.latency * 1000 / format.rate); FESTAI_SetSound(Player, format.rate, Config.quality); if(WRFilename) { if(!FCEUI_BeginWaveRecord(format.rate,Player->OutChannels,WRFilename)) { free(WRFilename); WRFilename = 0; } } //printf("%d:%d\n",buffering.fragsize, buffering.fragcount); format.sampformat=SEXYAL_FMT_PCMFLOAT; format.channels=Player->OutChannels; format.byteorder=0; Output->SetConvert(Output,&format); Config.volume = FESTAI_SetVolume(Player, Config.volume); FESTAI_Disable(Player, disabled); poosh(); puts(""); ShowInfo(); if(!FESTAI_SetLowpass(Player, Config.lowpass, Config.lowpasscorner, Config.lowpassorder)) { puts(" Error activating lowpass filter!"); } else if(Config.lowpass) printf(" Lowpass filter on. Corner frequency: %dHz, Order: %d\n",Config.lowpasscorner,Config.lowpassorder); current=FESTAI_SongControl(Player,0,0); lastms = ~0; frames_written = 0; puts("\n\n"); ShowStatus(1,1); //#define TICKEROO #ifdef TICKEROO static uint64 last_tick,total_ticks,total; total = 0; total_ticks = 0; #endif while(!eexit) { static char t[3]={0,0,0}; int len; float *buf; ShowStatus(0,0); if(paused) { usleep(10); } else { #ifdef TICKEROO last_tick=getticks(); #endif buf=FESTAI_Emulate(Player, &len); #ifdef TICKEROO total_ticks += getticks() - last_tick; total += len; #endif if(WRFilename) FCEU_WriteWaveData(buf, len); frames_written += len; Output->Write(Output,buf,len); #ifdef TICKEROO if(total >= 100000/2) { printf("%8f\n", (double)total*1000000/total_ticks); rmode(); exit(1); } #endif } while(read(fileno(stdin),&t[0],1)>=0) { static char kcc[20] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')'}; int x; for(x=0; x<20; x++) if(kcc[x] == t[0]) { disabled^=1<<x; FESTAI_Disable(Player,disabled); poosh(); ShowStatus(0,1); break; } if(t[2]==27 && t[1]==91) switch(t[0]) { case 65:current=FESTAI_SongControl(Player,10,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case 66:current=FESTAI_SongControl(Player,-10,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case 67:current=FESTAI_SongControl(Player,1,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case 68:current=FESTAI_SongControl(Player,-1,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; } else switch(tolower(t[0])) { case 10: lastms = ~0;frames_written=0;poosh();current=FESTAI_SongControl(Player, 0,0);ShowStatus(1,1);break; case '`': poosh();break; case 'a': Config.volume-=25; Config.volume = FESTAI_SetVolume(Player, Config.volume);poosh();ShowStatus(0,1);break; case 's': Config.volume+=25; Config.volume = FESTAI_SetVolume(Player, Config.volume);poosh();ShowStatus(0,1);break; case '_': case '-': Config.volume--; FESTAI_SetVolume(Player,Config.volume);poosh();ShowStatus(0,1);break; case '+': case '=': Config.volume++; FESTAI_SetVolume(Player,Config.volume);poosh();ShowStatus(0,1);break; case 'p': TogglePause();break; case 'q': goto exito; /* Alternate song selection keys. Especially needed for DOS port. */ case '\'':current=FESTAI_SongControl(Player,10,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case ';':current=FESTAI_SongControl(Player,-10,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case '.':current=FESTAI_SongControl(Player,1,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; case ',':current=FESTAI_SongControl(Player,-1,0);poosh(); lastms = ~0;frames_written=0;ShowStatus(1,1);break; } t[2]=t[1]; t[1]=t[0]; } } exito: if(WRFilename) { FCEUI_EndWaveRecord(); free(WRFilename); WRFilename = 0; } poosh(); FESTAI_Close(Player); if(Output) Output->Close(Output); Output = 0; } rmode(); free(DriverTypes); if(Interface) Interface->Destroy(Interface); return(0); }
/**************************************************************************** * DoCommand * * - Handles WM_COMMAND messages for client window. * * - Standard client window I/O * ****************************************************************************/ VOID DoCommand(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch (SHORT1FROMMP(mp1)) { case IDM_START1: case IDM_START2: /* Start a new 1 or 2 player game. */ if (iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2) { TogglePause(FORCE_UNPAUSE); StartGame(SHORT1FROMMP(mp1)-IDM_START); } break; case IDM_PAUSE: /* Toggle pause state. */ TogglePause(TOGGLE); break; case IDM_STOP: /* End game, but don't exit */ WinPostMsg(hwnd, WM_INITGAME, (MPARAM) 0L, MPVOID); break; case IDM_3SHIPS: case IDM_4SHIPS: case IDM_5SHIPS: /* Select 3, 4, or 5 ships */ CheckMenuItem(hwndMenu, IDM_SHIPS+prfProfile.iSHIPS, FALSE); prfProfile.iSHIPS = SHORT1FROMMP(mp1) - IDM_SHIPS; CheckMenuItem(hwndMenu, IDM_SHIPS+prfProfile.iSHIPS, TRUE); break; case IDM_3PHOTONS: case IDM_4PHOTONS: case IDM_6PHOTONS: case IDM_8PHOTONS: /* Select 3, 4, 6, or 8 photons */ CheckMenuItem(hwndMenu, IDM_PHOTONS+prfProfile.iPHOTONS, FALSE); prfProfile.iPHOTONS = SHORT1FROMMP(mp1) - IDM_PHOTONS; CheckMenuItem(hwndMenu, IDM_PHOTONS+prfProfile.iPHOTONS, TRUE); break; case IDM_RAPIDFIRE: /* Select rapidfire option */ if (prfProfile.bRAPIDFIRE = !prfProfile.bRAPIDFIRE) { CheckMenuItem(hwndMenu, IDM_RAPIDFIRE, TRUE); EnableMenuItem(hwndMenu, IDM_FIRERATE, TRUE); } else { CheckMenuItem(hwndMenu, IDM_RAPIDFIRE, FALSE); EnableMenuItem(hwndMenu, IDM_FIRERATE, FALSE); } break; case IDM_SLOWRATE: case IDM_MEDRATE: case IDM_FASTRATE: CheckMenuItem(hwndMenu, IDM_FIRERATE+prfProfile.iFIRERATE, FALSE); prfProfile.iFIRERATE = SHORT1FROMMP(mp1) - IDM_FIRERATE; CheckMenuItem(hwndMenu, SHORT1FROMMP(mp1), TRUE); break; case IDM_SHIELD: /* Select shield option */ if (prfProfile.bSHIELD = !prfProfile.bSHIELD) CheckMenuItem(hwndMenu, IDM_SHIELD, TRUE); else CheckMenuItem(hwndMenu, IDM_SHIELD, FALSE); break; case IDM_MOUSE: /* Allow mouse input for ship control */ if (prfProfile.bMOUSECONTROL = !prfProfile.bMOUSECONTROL) { /* Hide the pointer if playing a game */ ShowMouse(FALSE); CheckMenuItem(hwndMenu, IDM_MOUSE, TRUE); } else { /* Show the pointer if it is currently hidden */ ShowMouse(TRUE); CheckMenuItem(hwndMenu, IDM_MOUSE, FALSE); } break; case IDM_KEYS: /* Pop up key definition dialog box */ WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)KeyDlgProc, NULLHANDLE, IDD_KEY, NULL); break; case IDM_FRAME: /* This case does not come from the menu, but instead from the * * accelerator table. */ if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS) ShowFrameControls(); else HideFrameControls(); break; case IDM_BACKGRND: CheckMenuItem(hwndMenu, IDM_BACKGRND, prfProfile.bBACKGRND = !prfProfile.bBACKGRND); break; case IDM_HELPFORHELP: WinSendMsg(hwndHelp, HM_DISPLAY_HELP, MPVOID, MPVOID); break; case IDM_EXTENDEDHELP: WinSendMsg(hwndHelp, HM_EXT_HELP, MPVOID, MPVOID); break; case IDM_KEYSHELP: WinSendMsg(hwndHelp, HM_KEYS_HELP, MPVOID, MPVOID); break; case IDM_HELPINDEX: WinSendMsg(hwndHelp, HM_HELP_INDEX, MPVOID, MPVOID); break; case IDM_EXIT: /* On cancel, tell application to terminate */ WinPostMsg(hwndFrame, WM_QUIT, MPVOID, MPVOID); break; case IDM_ABOUT: /* Pop up about dialog box */ WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); break; } }
/**************************************************************************** * ProcessChar * * Processes WM_CHAR messages for ClientWndProc * * Receives the virtual key and character codes * ****************************************************************************/ VOID ProcessChar(CHAR vkey, BOOL vkv, CHAR chr, BOOL keydown) { BOOL bKeyPress = TRUE; static INT iSpeed = 0, iPos = 0; static CHAR szSpeed[2][8] = { "Windows", "OS/2" }; if (!vkv && !keydown) { if (iSpeed == 0 && chr == szSpeed[0][iPos] || iSpeed == 1 && chr == szSpeed[1][iPos]) { iPos++; } else if (iSpeed == 0 && chr == szSpeed[1][iPos]) { iPos = 1; iSpeed = 1; } else if (iSpeed == 1 && chr == szSpeed[0][iPos]) { iPos = 1; iSpeed = 0; } else { iPos = 0; } if (iSpeed == 0 && iPos == 7) { iPos = 0; if (uiSpeed == SPEED_WINDOWS) { uiSpeed = SPEED_NORMAL; iTickLen = TIMER_TICK_LENGTH; WinStartTimer(hab, hwndClient, ID_TIMER, iTickLen); } else { uiSpeed = SPEED_WINDOWS; iTickLen = TIMER_TICK_LENGTH*4; WinStartTimer(hab, hwndClient, ID_TIMER, iTickLen); } } else if (iSpeed == 1 && iPos == 4) { iPos = 0; if (uiSpeed == SPEED_WINDOWS) { uiSpeed = SPEED_OS2; iTickLen = TIMER_TICK_LENGTH; WinStartTimer(hab, hwndClient, ID_TIMER, iTickLen); } else if (uiSpeed == SPEED_OS2) { uiSpeed = SPEED_NORMAL; } else { uiSpeed = SPEED_OS2; } } } if ((iGameMode == GAME_MODE_HIGH) && !keydown) return; if ((vkv && (vkey == prfProfile.keyDEFS[4].vk)) || (!vkv && (chr == prfProfile.keyDEFS[4].chr))) { if (iShipMode[Player] & FIRERELEASE) { if (!keydown) { iShipMode[Player] &= ~FIRERELEASE; } } else { UPDATE_FIRE(iShipMode[Player], keydown); } } else if ((vkv && (vkey == prfProfile.keyDEFS[0].vk)) || (!vkv && (chr == prfProfile.keyDEFS[0].chr))) { UPDATE_LEFT(iShipMode[Player], keydown); } else if ((vkv && (vkey == prfProfile.keyDEFS[1].vk)) || (!vkv && (chr == prfProfile.keyDEFS[1].chr))) { UPDATE_RIGHT(iShipMode[Player], keydown); } else if ((vkv && (vkey == prfProfile.keyDEFS[2].vk)) || (!vkv && (chr == prfProfile.keyDEFS[2].chr))) { UPDATE_THRUST(iShipMode[Player], keydown); } else if ((vkv && (vkey == prfProfile.keyDEFS[3].vk)) || (!vkv && (chr == prfProfile.keyDEFS[3].chr))) { UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]); } else if ((vkv && (vkey == prfProfile.keyDEFS[5].vk )) || (!vkv && (chr == prfProfile.keyDEFS[5].chr))) { UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]); } else { bKeyPress = FALSE; } if (bKeyPress && TogglePause(CHECK)) TogglePause(TOGGLE); }
/**************************************************************************** * Initialize * * - Performs several application initializations. Reads profile info, * * modifies client window to match it, seeds random number generator, * * initializes game data structures, and starts the timer. * * - No I/O. * ****************************************************************************/ VOID Initialize(VOID) { INT i; ULONG cb; /* Read in the profile data if it exists */ PrfQueryProfileSize(HINI_USERPROFILE, szClientClass, "Data", &cb); if (cb == sizeof(PROFILEREC)) PrfQueryProfileData(HINI_USERPROFILE, szClientClass, "Data", (PVOID)&prfProfile, &cb); /* Make frame size & position match profile information (or initialize) */ if ((prfProfile.ulMINMAX & SWP_MINIMIZE) || (prfProfile.ulMINMAX & SWP_MAXIMIZE)) WinSetWindowPos(hwndFrame, HWND_TOP, prfProfile.x, prfProfile.y, prfProfile.cx, prfProfile.cy, SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE | prfProfile.ulMINMAX); else if ((prfProfile.cx != 0) && (prfProfile.cy != 0)) WinSetWindowPos(hwndFrame,HWND_TOP, prfProfile.x,prfProfile.y,prfProfile.cx,prfProfile.cy, SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE); /* Profile information is new. Rely on PM to size/position the client * * window this first time. */ else WinShowWindow(hwndFrame, TRUE); /* Hide controls if hidden at last save * * Normally this if block should occur prior to the previous one, but * * there appears to be a PM v1.2 bug w/hide before WinSetWindowPos: * * the title bar _looks_ inactive when it is later shown. */ if (!prfProfile.bCONTROLS) HideFrameControls(); /* Create a help instance */ hwndHelp = WinCreateHelpInstance(hab, &hinit); if (hwndHelp == NULLHANDLE) { /* failed to create help instance */ WinAlarm(HWND_DESKTOP, WA_WARNING); WinMessageBox(HWND_DESKTOP, NULLHANDLE, "Please put ASTEROID.HLP in a directory pointed to by the HELP " "environment variable or in the ASTEROID working directory.", "Could not find help file", 0, MB_ICONHAND | MB_OK | MB_APPLMODAL); } else WinAssociateHelpInstance(hwndHelp, hwndFrame); /* Initialize Menu according to profile info */ InitMenu(); /* Seed the random number generator from seed in profile */ srand((unsigned int) prfProfile.uiSEED); prfProfile.uiSEED = (UINT) rand(); /* Initialize game data structures */ WinSendMsg(hwndClient, WM_INITGAME, MPFROMSHORT(0), MPVOID); /* Startup a timer for screen updates */ TogglePause(FORCE_UNPAUSE); if ((prfProfile.ulMINMAX & SWP_MINIMIZE) && (!prfProfile.bBACKGRND)) { /* Set icon */ WinSendMsg(hwndFrame, WM_SETICON, (MPARAM)WinLoadPointer(HWND_DESKTOP, NULLHANDLE, ID_RESOURCE), MPVOID); TogglePause(SUSPEND_ON); } }
/**************************************************************************** * ClientWndProc * * - Typical PM client window procedure. (see below) * * - Standard client window I/O * ****************************************************************************/ MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { RECTL rcl; SWP swp; HPS hpsPaint; static HPS hps; /* Permanent HPS */ static INT cx, cy; /* Client window dimensions */ static BOOL bSlowUpdateNow = FALSE; /* Update toggle for asteroids * * and enemy which are slow. */ static POINTL ptlCenter; /* Center of client window */ switch (msg) { /* Recieved from WinCreateStdWindow */ case WM_CREATE: /* Get permanent PS for entire window */ hps = WinGetPS(hwnd); /* Load private Asteroid fonts from ASTEROID.DLL */ if (GpiLoadFonts(hab, "ASTEROID") != GPI_OK) { WinReleasePS(hps); WinAlarm(HWND_DESKTOP, WA_WARNING); WinMessageBox(HWND_DESKTOP,NULLHANDLE, "Please put ASTEROID.DLL in a directory in your LIBPATH.", "Error reading ASTEROID.DLL", 0,MB_ICONHAND|MB_OK|MB_APPLMODAL); WinPostMsg(hwnd,WM_QUIT,(MPARAM) 0L,(MPARAM) 0L); return (MRESULT) TRUE; } /* Register/create logical fonts for use */ InitFonts(hps); /* Display About dialoge box */ WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); return 0; /* Recieved during attract mode when user starts game */ case WM_STARTGAME: /* Determine the number of players */ cPlayers = (INT)LONGFROMMP(mp1); /* Initialize each player */ for (Player=0;Player<cPlayers;Player++) { Level[Player] = 1; Ships[Player] = prfProfile.iSHIPS; DeletePhotons(); InitAsteroids(); InitEnemy(); } /* Start with player 1 */ Player = 0; iGameMode = GAME_MODE_NEXT; iGameModeCnt = GAME_PAUSE_TIME-1; /* Hide the pointer if mouse controls are enabled */ ShowMouse(FALSE); /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Recieved at startup and at the completion of a game */ case WM_INITGAME: /* Make mouse visible if we hid it before */ ShowMouse(TRUE); /* Fix menu to reflect attract mode */ EnableMenuItem(hwndMenu, IDM_START, TRUE); EnableMenuItem(hwndMenu, IDM_STOP, FALSE); /* Initialize player and enemy data structures */ cPlayers = 0; Level[0] = 1; for (Player=0;Player<2;Player++) { Score[Player] = 0L; Ships[Player] = 0; DeletePhotons(); } Player = 0; /* Initialize asteroids (and enemy) for attract mode */ InitAsteroids(); InitEnemy(); /* Depending on whether ASTEROID was just started or a game just * * completed display the "High Score" or "Press 1 or 2" screen. */ if (SHORT1FROMMP(mp1) == 0) { iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; } else { iGameMode = GAME_MODE_INIT2; iGameModeCnt = GAME_INIT_TIME; } /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Usually recieved from the system, sometime forced by the program to * * ensure the screen is not corrupt. */ case WM_PAINT: /* Clear entire window to insure no "droppings" */ WinQueryWindowRect(hwnd,&rcl); WinFillRect(hps, &rcl, CLR_BLACK); WinInvalidateRect(hwnd, &rcl, FALSE); /* Get the update region and paint it black */ hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rcl); WinFillRect(hpsPaint, &rcl, CLR_BLACK); WinEndPaint(hpsPaint); /* Only in normal play mode should we draw the ship */ if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] != EXPLOSION) && (iShipMode[Player] != HYPERSPACE)) DrawShip(hps, cx, cy, DRAW_INIT); else if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] == EXPLOSION)) ExplodeShip(hps, cx, cy); /* Draw the enemy if it is on the screen */ if (iEnemyMode[Player] != NONE) if (iEnemyMode[Player] != EXPLOSION) DrawEnemy(hps, cx, cy,DRAW_INIT); else ExplodeEnemy(hps, cx, cy); /* Draw photons and asteroids in all modes but the "Enter your * * initials" mode, otherwise draw that screen. */ if (iGameMode != GAME_MODE_HIGH) { DrawPhotons(hps, cx, cy, DRAW_INIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } else DrawHighScore(hps, cx, cy, DRAW_INIT); /* Always draw the score */ DrawScore(hps, cx, cy, DRAW_INIT); return 0; /* Left mouse button down. This simulates the move/track function * * in the system menu. */ case WM_BUTTON1DOWN: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2 && !TogglePause(CHECK)) { UPDATE_FIRE(iShipMode[Player], TRUE); return (MRESULT)TRUE; } return WinSendMsg(hwndFrame, WM_TRACKFRAME, (MPARAM) (SHORT1FROMMP(mp2) | TF_MOVE), MPVOID); case WM_BUTTON1UP: if (prfProfile.bMOUSECONTROL) { UPDATE_FIRE(iShipMode[Player], FALSE); return (MRESULT)TRUE; } return 0; /* Left mouse button double clicked. Toggle frame control display. */ case WM_BUTTON1DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS) ShowFrameControls(); else HideFrameControls(); } return 0; case WM_BUTTON2DOWN: if (prfProfile.bMOUSECONTROL) { UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]); return (MRESULT)TRUE; } return 0; case WM_BUTTON2CLICK: if (prfProfile.bMOUSECONTROL) { UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]); return (MRESULT)TRUE; } return 0; /* Right mouse button double clicked. Display the about dialog box. */ case WM_BUTTON2DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { WinDlgBox(HWND_DESKTOP, hwndClient, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); } return 0; /* User typed a key. Most of this is self explanatory. */ case WM_CHAR: ProcessChar((CHAR) (CHARMSG(&msg)->vkey-1), CHARMSG(&msg)->fs & KC_VIRTUALKEY, (CHAR) (CHARMSG(&msg)->chr), (BOOL) !(CHARMSG(&msg)->fs & KC_KEYUP)); return 0; /* User entered a command via the menu bar. */ case WM_COMMAND: DoCommand(hwnd, msg, mp1, mp2); return 0; /* Suspend/un-suspend game depending on focus */ case WM_SETFOCUS: if ((BOOL) SHORT1FROMMP(mp2)) TogglePause(SUSPEND_OFF); else if (!prfProfile.bBACKGRND) TogglePause(SUSPEND_ON); return 0; /* Keep track of the client window size. Profile information is not * * updated here because there are better places (i.e. at exit) */ case WM_SIZE: cx = (INT)SHORT1FROMMP(mp2); cy = (INT)SHORT2FROMMP(mp2); /* Keep track of client window position. Also updates profile info. */ case WM_MOVE: WinQueryWindowPos(hwndFrame,&swp); if (!(swp.fl & SWP_MAXIMIZE) && !(swp.fl & SWP_MINIMIZE)) { prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } if (swp.fl & SWP_MINIMIZE) if (!prfProfile.bBACKGRND) { /* Set icon */ WinSendMsg(hwndFrame, WM_SETICON, (MPARAM) WinLoadPointer(HWND_DESKTOP, NULLHANDLE, ID_RESOURCE), MPVOID); TogglePause(SUSPEND_ON); } else WinSendMsg(hwndFrame, WM_SETICON, MPVOID, MPVOID); else TogglePause(SUSPEND_OFF); ptlCenter.x = swp.cx / 2; ptlCenter.y = swp.cy / 2; WinMapWindowPoints(hwndClient, HWND_DESKTOP, &ptlCenter, 1L); return 0; /* Recieved approximately 31 times a second. This is the longest and * * ugliest of the messages, partly because there are so many cases * * to keep track of, partly because it must be highly optimized. */ case WM_TIMER: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2) { POINTL ptl; static BOOL bUp, bLeft, bRight; WinQueryPointerPos(HWND_DESKTOP, &ptl); if (bUp || (ptl.y - ptlCenter.y > 0)) UPDATE_THRUST(iShipMode[Player], bUp = (ptl.y - ptlCenter.y > 0)); if (bLeft || (ptlCenter.x - ptl.x > 0)) UPDATE_LEFT(iShipMode[Player], bLeft = (ptlCenter.x - ptl.x > 0)); if (bRight || (ptlCenter.x - ptl.x < 0)) UPDATE_RIGHT(iShipMode[Player], bRight = (ptlCenter.x - ptl.x < 0)); WinSetPointerPos(HWND_DESKTOP, ptlCenter.x, ptlCenter.y); } /* Determine the current game mode */ switch (iGameMode) { /* Either initialization/attract mode screen. */ case GAME_MODE_INIT1: case GAME_MODE_INIT2: /* Switch screens when count expires */ if (--iGameModeCnt == 0) { if (iGameMode == GAME_MODE_INIT1) iGameMode = GAME_MODE_INIT2; else iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; /* Score must be redrawn because the attract mode screens * * draw the score differently. */ DrawScore(hps, cx, cy, DRAW_REINIT); } /* Update photons, asteroids, enemy, and score */ UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Completion of one player's turn or new game */ case GAME_MODE_NEXT: /* Initially, erase and redraw everything for new player */ if (iGameModeCnt-- == GAME_PAUSE_TIME) { if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { DrawAsteroids(hps, cx, cy, DRAW_ERASE); DrawPhotons(hps, cx, cy, DRAW_ERASE); Player = (Player+1) % MAXPLAYERS; } DrawScore(hps, cx, cy, DRAW_REINIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } /* During countdown update score and asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At end of countdown start the player */ else { InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawScore(hps, cx, cy, DRAW_REINIT); } break; /* Normal play mode */ case GAME_MODE_PLAY: /* Update ship, photons, asteroids, enemy, and score */ UpdateShip(hps, cx, cy); UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); /* Erase old and draw new scores if there is a change*/ if (bChangeScore) { bChangeScore = FALSE; DrawScore(hps, cx, cy, DRAW_REINIT); } /* Else just refresh the score */ else DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Game over mode. This is the longest and ugliest case because * * conditions are highly dependent on the number of players, * * multiplayer game status, and the number and order of high * * scores. */ case GAME_MODE_OVER: /* Initially, just update the score and number of ships */ if (iGameModeCnt-- == GAME_PAUSE_TIME) DrawScore(hps, cx, cy, DRAW_REINIT); /* During countdown refresh the score and update the asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At the end of the countdown, if there are any other players, * * continue with them. */ else { /* Countinue on with any remaining players. */ if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* Setup everything for the next player */ Player = (Player+1) % MAXPLAYERS; InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawAsteroids(hps, cx, cy, DRAW_INIT); DrawScore(hps, cx, cy, DRAW_REINIT); } /* Check for new high scores and update table as necessary. */ else { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* The following if/else block is admittedly a kludge, it is * * simple and it does work, however. Ideally it should * * sort the high scores and update the high score table in * * descending order. */ /* If player 1 scored higher than player 2 then check * * player 1 first for a high score. */ if (Score[0] > Score[1]) for (Player=0;Player<cPlayers;Player++) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0; /* Otherwise, check player 2 first */ else for (Player=cPlayers;Player>=0;Player--) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0L; /* If there was no high score, go into attract mode */ if (iGameMode != GAME_MODE_HIGH) WinSendMsg(hwnd,WM_INITGAME,MPFROMSHORT(1),(MPARAM) 0L); /* Else, check for player 1's initials first then 2's * * This is not faithful, in the arcade game the player * * with the higher score always goes first. */ else { if (Score[0] > 0L) Player = 0; else Player = 1; DrawScore(hps, cx, cy, DRAW_REINIT); DrawHighScore(hps, cx, cy, DRAW_INIT); } } } break; /* Mode which prompts players to enter their initials */ case GAME_MODE_HIGH: /* If the player's position is > 0 then refresh the screen */ if (Score[Player] > 0L) DrawHighScore(hps, cx, cy, DRAW_REFRESH); /* Else, the current player is done go to the next */ else if ((cPlayers == MAXPLAYERS) && (Player == 0) && (Score[1] > 0L)) { Player++; DrawHighScore(hps, cx, cy, DRAW_REINIT); } /* If there are no more high scores then go into attract mode */ else WinSendMsg(hwnd, WM_INITGAME, MPFROMSHORT(1), MPVOID); break; } return 0; /* Used by help manager */ case HM_QUERY_KEYS_HELP: return((MRESULT)IDH_CLIENTKEYS); /* Recieved always from the system or in the case of an initialization* * error. Both messages will normally save the profile information.* * Ideally the profile section should be moved to a subroutine and the* * the following should be broken into two distinct cases. */ case WM_SAVEAPPLICATION: case WM_DESTROY: /* If the fonts were not found bApplicationOk will be false, in * * that case the window profile information should not be updated.*/ if (TRUE) { /* Copy window position and size info into profile structure */ WinQueryWindowPos(hwndFrame, &swp); if (swp.fl & SWP_MAXIMIZE) prfProfile.ulMINMAX = SWP_MAXIMIZE; else if (swp.fl & SWP_MINIMIZE) prfProfile.ulMINMAX = SWP_MINIMIZE; else { prfProfile.ulMINMAX = 0; prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } /* Write profile information */ PrfWriteProfileData(HINI_USERPROFILE, szClientClass, "Data", &prfProfile, sizeof(PROFILEREC)); } /* If the application is terminating release the fonts and the hps. */ if (msg == WM_DESTROY) { /* Make sure mouse is visible if we hid it before */ ShowMouse(TRUE); /* Release font identifiers and DLL resource module */ GpiSetCharSet(hps, LCID_DEFAULT); GpiDeleteSetId(hps, LCID_LARGE); GpiDeleteSetId(hps, LCID_SMALL); GpiUnloadFonts(hab, "ASTEROID"); /* Release the "permanent" presentation space */ WinReleasePS(hps); } return 0; } return WinDefWindowProc(hwnd, msg, mp1, mp2); }