/** * Load a scenario in a safe way, and prepare the game. * @param houseID The House which is going to play the game. * @param scenarioID The Scenario to load. */ void Game_LoadScenario(uint8 houseID, uint16 scenarioID) { Audio_PlayVoice(VOICE_STOP); Game_Init(); g_validateStrictIfZero++; g_scenarioID = scenarioID; if (!Scenario_Load(scenarioID, houseID)) { GUI_DisplayModalMessage("No more scenarios!", 0xFFFF); PrepareEnd(); exit(0); } Game_Prepare(); if (scenarioID < 5) { g_hintsShown1 = 0; g_hintsShown2 = 0; } g_validateStrictIfZero--; }
void init(void) { dumpInfo(); // GL inits glClearColor(1,1,1,0);; glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); printError("GL inits"); // Airplane Dynamics_Init(&forward, &up, &right, &position, &velocity); Airplane_Init(&thrust, &yawRate, &pitchRate, &rollRate, &firstPersonView, &resetFlag); // Camera Camera_Init(firstPersonView, &forward, &up, &position, velocity, &camera_position, &camera_look, camMatrix); // Terrain and skybox World_Init(&camera_position, &camera_look); // Init game Game_Init(); // Projection matrix frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 200.0, projMatrix); printError("init arrays"); }
//-----------------------------------【WinMain( )函数】-------------------------------------- // 描述:Windows应用程序的入口函数,我们的程序从这里开始 //------------------------------------------------------------------------------------------------ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd) { //【1】窗口创建四步曲之一:开始设计一个完整的窗口类 WNDCLASSEX wndClass = { 0 }; //用WINDCLASSEX定义了一个窗口类 wndClass.cbSize = sizeof( WNDCLASSEX ) ; //设置结构体的字节数大小 wndClass.style = CS_HREDRAW | CS_VREDRAW; //设置窗口的样式 wndClass.lpfnWndProc = WndProc; //设置指向窗口过程函数的指针 wndClass.cbClsExtra = 0; //窗口类的附加内存,取0就可以了 wndClass.cbWndExtra = 0; //窗口的附加内存,依然取0就行了 wndClass.hInstance = hInstance; //指定包含窗口过程的程序的实例句柄。 wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //本地加载自定义ico图标 wndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); //指定窗口类的光标句柄。 wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); //为hbrBackground成员指定一个白色画刷句柄 wndClass.lpszMenuName = NULL; //用一个以空终止的字符串,指定菜单资源的名字。 wndClass.lpszClassName = L"ForTheDreamOfGameDevelop"; //用一个以空终止的字符串,指定窗口类的名字。 //【2】窗口创建四步曲之二:注册窗口类 if( !RegisterClassEx( &wndClass ) ) //设计完窗口后,需要对窗口类进行注册,这样才能创建该类型的窗口 return -1; //【3】窗口创建四步曲之三:正式创建窗口 HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE, //喜闻乐见的创建窗口函数CreateWindow WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL ); //【4】窗口创建四步曲之四:窗口的移动、显示与更新 MoveWindow(hwnd,150,20,WINDOW_WIDTH,WINDOW_HEIGHT,true); //调整窗口显示时的位置,使窗口左上角位于(150,20)处 ShowWindow( hwnd, nShowCmd ); //调用ShowWindow函数来显示窗口 UpdateWindow(hwnd); //对窗口进行更新,就像我们买了新房子要装修一样 //游戏资源的初始化,若初始化失败,弹出一个消息框,并返回FALSE if (!Game_Init (hwnd)) { MessageBox(hwnd, L"资源初始化失败", L"消息窗口", 0); //使用MessageBox函数,创建一个消息窗口 return FALSE; } PlaySound(L"君がいるから (Long Version).wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //循环播放背景音乐 //【5】消息循环过程 MSG msg = { 0 }; //定义并初始化msg while( msg.message != WM_QUIT ) //使用while循环,如果消息不是WM_QUIT消息,就继续循环 { if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) //查看应用程序消息队列,有消息时将队列中的消息派发出去。 { TranslateMessage( &msg ); //将虚拟键消息转换为字符消息 DispatchMessage( &msg ); //分发一个消息给窗口程序。 } else { g_tNow = GetTickCount(); //获取当前系统时间 if(g_tNow-g_tPre >= 30) //当此次循环运行与上次绘图时间相差0.03秒时再进行重绘操作 Game_Paint(hwnd); } } //【6】窗口类的注销 UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance); //程序准备结束,注销窗口类 return 0; }
int main(void){ DisableInterrupts(); TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); PF1Init(); //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer ADC0_Init(); Game_Init(); SwitchLed_Init(); Sound_Init(); Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256 GameOverFlag = 0; EnableInterrupts(); while(1){ while(Semaphore==0){}; Semaphore = 0; if(GameOverFlag){ State_GameOver(); } else{ Draw_GameFrame(); // update the LCD } if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over Delay100ms(2);//Delay 200ms GameOverFlag = Check_GameOver(); //SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed } } }
void Game_Update() { // test edit, Game_Init(); Graphics_ClearScreen(); if(Input_Up()) { player.position.y += player.velocity.y; } if(Input_Down()) { player.position.y -= player.velocity.y; } if(Input_Left()) { } if(Input_Right()) { } if(Input_PageUp()) { } if(Input_PageDown()) { } if(Input_Enter()) { } if(Input_Space()) { } player.Draw(1.0f, 0.0f, 0.0f); enemy.Draw(0.0f, 1.0f, 0.0f); enemy.balls.Draw(1.0f, 1.0f, 1.0f); enemy.Move(); enemy.balls.Move(); enemy.boardcoll.Detection(player.position, enemy.balls.position); enemy.boardcoll.Responsex(player.position, enemy.balls.position, enemy.balls.velocity); enemy.boardcoll.Detection(enemy.position, enemy.balls.position); enemy.boardcoll.Responsex(enemy.position, enemy.balls.position, enemy.balls.velocity); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; HWND hWnd; MyRegisterClass(hInstance); DWORD style; if (FULLSCREEN) style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP; else style = WS_OVERLAPPEDWINDOW; hWnd = CreateWindow( APPTITLE, APPTITLE, style, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); if (!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); Init_Direct3D(hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN); Game_Init(hWnd); int done = 0; while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) done = 1; TranslateMessage(&msg); DispatchMessage(&msg); } else { Game_Run(hWnd); } } return msg.wParam; }
//-------------------------------------【 WinMain() 函数 】--------------------------------------------------------------- // 描述:程序的入口 //------------------------------------------------------------------------------------------------------------------------ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { //【1】开始设计一个完整的窗口类 WNDCLASSEX wndClass = { 0 }; //用 WNDCLASSEX 定义一个窗口类 wndClass.cbSize = sizeof(WNDCLASSEX); //设置结构体的字节数大小 wndClass.style = CS_HREDRAW | CS_VREDRAW; //设置窗口的样式 wndClass.lpfnWndProc = WndProc; //设置指向窗口的过程函数指针 wndClass.cbClsExtra = 0; //窗口类的附加内存,取 0就可以了 wndClass.hInstance = hInstance; //指定包含窗体过程的程序的实例句柄 wndClass.hIcon = NULL; // 默认的icon 图标 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); //指定窗体的光标句柄 wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); //指定一个灰色的画刷句柄 wndClass.lpszMenuName = NULL; //指定菜单的资源名字 wndClass.lpszClassName = L"GDIdemoCore"; //指定窗口类的名字 //【2】 注册窗口类 if (!RegisterClassEx(&wndClass)) //设计完窗口需要对其进行注册,这样才能创建该类的窗口 { return -1; } //【3】 正式创建窗体 HWND hwnd = CreateWindow(L"GDIdemoCore", WINDOW_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); //【4】 窗口的移动、显示、更新 MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true); //调整窗口显示时的位置,是窗口的左上角位于(250,80)处 ShowWindow(hwnd, nShowCmd); //调用ShowWindow 函数显示窗口 UpdateWindow(hwnd); //对窗口进行更新 //游戏资源的初始化,若初始化失败弹出一个消息框,并返回FALSE if (!Game_Init(hwnd)) { MessageBox(hwnd, L"资源初始化失败", L"消息窗口", 0); return FALSE; } //【5】 消息循环过程 MSG msg = { 0 }; //定义并初始化msg while (msg.message != WM_QUIT) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) //查看消息队列,有消息时将消息队列中的消息派发出去。 { TranslateMessage(&msg); //将虚拟键消息转换成字符消息。 DispatchMessage(&msg); //分发一个消息给窗口程序 } } //【6】 窗口类的注销 UnregisterClass(L"GDIdemoCore", wndClass.hInstance); return 0; }
//主函数 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nShowCmd) { //1.设计一个完整的窗口类 WNDCLASSEX wndClass = { 0 };//定义一个窗口类 wndClass.cbSize = sizeof(WNDCLASSEX);//设置结构体的大小 wndClass.style = CS_HREDRAW | CS_VREDRAW;//设置窗口样式 wndClass.lpfnWndProc = WndProc;//设置消息处理函数 wndClass.cbClsExtra = 0;//窗口类的附加内存,一般设置为0 wndClass.cbWndExtra = 0;//窗口的附加内存,一般设置为0 wndClass.hInstance = hInstance;//包含窗体实例的程序的句柄 wndClass.hIcon = (HICON)LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);//设置一个图标 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);//指定一个灰色画刷句柄 wndClass.lpszClassName = NULL;//不需要下拉菜单 wndClass.lpszClassName = L"HWWND";//指定窗口类的名字 //2.注册窗口类 if (!RegisterClassEx(&wndClass)) return -1; //3.创建窗体 HWND hwnd = CreateWindow(L"HWWND", WINDOW_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); //4.窗体移动,显示和更新 //MoveWindow(hwnd, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, true); ShowWindow(hwnd, nShowCmd); //UpdateWindow(hwnd); //初始化游戏资源 if (!Game_Init(hwnd)) { MessageBox(hwnd, L"Faild!", L"Message", 0); return FALSE; } PlaySound(L"宝瓶时代1.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); //5.消息分发 MSG msg = { 0 }; while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } //6.注销窗体 UnregisterClass(L"HWWND", hInstance); return 0; }
int main(int argc, char *argv[]) { struct Window window; window.width = 1024; window.height = 768; window.flags = SDL_WINDOW_OPENGL; Window_CreateOpenGLContext(&window, "OpenGL"); Window_SetOpenGLFlags(); Game_Init(); GLfloat const dt = 0.01f; GLfloat t = 0.0f; GLfloat accumulator = 0.0f; GLfloat previous_time = 0.0f; while (Game_HandleInput()) { GLfloat new_time = SDL_GetTicks() / 1000.0f; GLfloat delta_time = new_time - previous_time; if (delta_time <= 0.0f) continue; previous_time = new_time; accumulator += delta_time; while (accumulator >= dt) { Game_FixedUpdate(t, dt); accumulator -= dt; t += dt; } Game_Update(); Game_LateUpdate(); Window_ClearBuffers(); { Game_Render(); } Window_SwapBuffers(&window); } Game_Destroy(); Window_Destroy(&window); return 0; }
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 在此放置代码 // 初始化全局字符串 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_SOFTRENDER, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } Game_Init(); HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOFTRENDER)); MSG msg; // 主消息循环: for (;;) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT)break; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Game_Main(); } return (int) msg.wParam; }
/** * Load a scenario in a safe way, and prepare the game. * @param houseID The House which is going to play the game. * @param scenarioID The Scenario to load. */ bool Game_LoadScenario(const char* scenario) { Audio_PlayVoice(VOICE_STOP); Game_Init(); g_validateStrictIfZero++; g_scenarioID = 0xFFFF; if (!Scenario_Load(scenario, SEARCHDIR_SCENARIO_DIR)) return false; Game_Prepare(); g_hintsShown1 = 0; g_hintsShown2 = 0; g_validateStrictIfZero--; return true; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { HICON IconSmall = LoadIcon(hInstance, "ICON16"); HICON IconMedium = LoadIcon(hInstance, "ICON32"); HICON IconLarge = LoadIcon(hInstance, "ICON48"); WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = IconMedium; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE.c_str(); wc.hIconSm = IconSmall; RegisterClassEx(&wc); DestroyIcon(IconSmall); DestroyIcon(IconMedium); DestroyIcon(IconLarge); HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREENW, SCREENH, NULL, NULL, hInstance, NULL); if (window == 0) return 0; ShowWindow(window, nCmdShow); UpdateWindow(window); if (!Game_Init(window)) return 0; MSG message = { NULL, 0, NULL, NULL, 0, { 0, 0 } }; while (!gameover) { if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&message); DispatchMessage(&message); } Game_Run(window); } Game_End(); return message.wParam; }
/*! * @brief Initialisation thread. runs once. */ void InitThread(void *data) { for (;;) { OS_SemaphoreWait(InitSemaphore, 0); Random_Init(); //Switches mate Switch_Init(S1Callback, (void *) 0, S2Callback, (void *) 0); Toggle_Init(ToggleModeFinished); Game_Init(GameModeFinished); Touch_Init(); //Initialize all the modules LEDs_Init(); I2C_Init(100000, MODULE_CLOCK); Accel_Init(&AccelSetup); PIT_Init(MODULE_CLOCK, &PitCallback, (void *) 0); PIT_Set(500000000, bFALSE); PIT_Enable(bTRUE); Packet_Init(BAUD_RATE, MODULE_CLOCK); Flash_Init(); CMD_Init(); //Best to do this one last //TODO: disabled for yellow RTC_Init((void (*)(void*))OS_SemaphoreSignal, (void *) RtcSemaphore); Timer_Init(); Timer_Set(&PacketTimer); Timer_Set(&AccTimer); CMD_SpecialGetStartupValues(); LEDs_On(LED_ORANGE); } }
bool LoadFile(char *filename) { FILE *fp; char filenameComplete[1024]; bool res; Sound_Output_Feedback(0xFFFE); Game_Init(); snprintf(filenameComplete, sizeof(filenameComplete), "data/%s", filename); fp = fopen(filenameComplete, "rb"); if (fp == NULL) { Error("Failed to open file '%s' for reading.\n", filenameComplete); /* TODO -- Load failures should not result in termination */ exit(0); return false; } Sprites_LoadTiles(); g_validateStrictIfZero++; res = Load_Main(fp); g_validateStrictIfZero--; fclose(fp); if (!res) { Error("Error while loading savegame.\n"); /* TODO -- Load failures should not result in termination */ exit(0); return false; } if (g_gameMode != GM_RESTART) Game_Prepare(); return true; }
int main(int argc, char **argv) { unsigned int time_start, time_end; Game_Init(); FPSCount_Init(); while(game_running) { time_start = SDL_GetTicks(); Game_Update(); Game_Draw(); SDL_GL_SwapBuffers(); time_end = SDL_GetTicks(); FPSCount_Tick(); if(1000/FPS > time_end - time_start) SDL_Delay(1000/FPS - (time_end - time_start)); } Game_Quit(); return 0; }
void SysTick_Handler(void){ // runs at frequency of SysTick interrupts GPIO_PORTF_DATA_R ^= 0x02; // toggle PF1, debugging //Game Engigine methods below if(GameOverFlag){ if(Switch_Fire() || Switch_SpecialFire()){ GameOverFlag = 0; Game_Init(); } } else{ Check_Collisions(); Move_ActiveObjects(); if(Switch_Fire()){ RegMissile_Fire(); Sound_Shoot(); } if(Switch_SpecialFire()){ SpecMissile_Fire(); Sound_Shoot(); } SysTick_Init(Set_Difficulty()); } Semaphore = 1; }
/** * Load a scenario in a safe way, and prepare the game. * @param houseID The House which is going to play the game. * @param scenarioID The Scenario to load. */ void Game_LoadScenario(uint8 houseID, uint16 scenarioID) { Sound_Output_Feedback(0xFFFE); Game_Init(); g_validateStrictIfZero++; if (!Scenario_Load(scenarioID, houseID)) { GUI_DisplayModalMessage("No more scenarios!", 0xFFFF); PrepareEnd(); exit(0); } Game_Prepare(); if (scenarioID < 5) { g_hintsShown1 = 0; g_hintsShown2 = 0; } g_validateStrictIfZero--; }
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { // this is the winmain function WNDCLASS winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message HDC hdc; // generic dc PAINTSTRUCT ps; // generic paintstruct // first fill in the window class stucture winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; // register the window class if (!RegisterClass(&winclass)) return(0); // create the window, note the test to see if WINDOWED_APP is // true to select the appropriate window flags if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class WINDOW_TITLE, // title (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)), 0,0, // x,y WINDOW_WIDTH, // width WINDOW_HEIGHT, // height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return(0); // save the window handle and instance in a global main_window_handle = hwnd; main_instance = hinstance; // resize the window so that client is really width x height if (WINDOWED_APP) { // now resize the window, so the client area is the actual size requested // since there may be borders and controls if this is going to be a windowed app // if the app is not windowed then it won't matter RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1}; // make the call to adjust window_rect AdjustWindowRectEx(&window_rect, GetWindowStyle(main_window_handle), GetMenu(main_window_handle) != NULL, GetWindowExStyle(main_window_handle)); // save the global client offsets, they are needed in DDraw_Flip() window_client_x0 = -window_rect.left; window_client_y0 = -window_rect.top; // now resize the window with a call to MoveWindow() MoveWindow(main_window_handle, 0, // x position 0, // y position window_rect.right - window_rect.left, // width window_rect.bottom - window_rect.top, // height FALSE); // show the window, so there's no garbage on first render ShowWindow(main_window_handle, SW_SHOW); } // end if windowed // perform all game console specific initialization Game_Init(); // disable CTRL-ALT_DEL, ALT_TAB, comment this line out // if it causes your system to crash SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, NULL, 0); // enter main event loop while(1) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while // shutdown game and release all resources Game_Shutdown(); // enable CTRL-ALT_DEL, ALT_TAB, comment this line out // if it causes your system to crash SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, NULL, 0); // return to Windows like this return(msg.wParam); } // end WinMain
// WINMAIN //////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // save hinstance in global ghInstance = hinstance; // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL, // extended style WINDOW_CLASS_NAME, // class WINDOW_TITLE, // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // initial x,y WIDTH,HEIGHT, // initial width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance of this application NULL))) // extra creation parms return(0); // save main window handle ghWnd = hwnd; // initialize game here Game_Init(); // enter main event loop while(TRUE) { // test if there is a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while // closedown game here Game_Shutdown(); // return to Windows like this return(msg.wParam); } // end WinMain
static bool Skirmish_GenerateMapInner(bool generate_houses, SkirmishData* sd) { const MapInfo* mi = &g_mapInfos[0]; if (generate_houses) Skirmish_Prepare(); Game_Init(); Skirmish_GenGeneral(); Sprites_UnloadTiles(); Sprites_LoadTiles(); Tools_RandomLCG_Seed(g_skirmish.seed); Map_CreateLandscape(g_skirmish.seed); if (!generate_houses) return true; /* Create initial island. */ sd->island[0].start = 0; sd->island[0].end = 0; for (int dy = 0; dy < mi->sizeY; dy++) { for (int dx = 0; dx < mi->sizeX; dx++) { const int tx = mi->minX + dx; const int ty = mi->minY + dy; const uint16 packed = Tile_PackXY(tx, ty); sd->buildable[sd->island[0].end].x = tx; sd->buildable[sd->island[0].end].y = ty; sd->buildable[sd->island[0].end].packed = packed; sd->buildable[sd->island[0].end].parent = 0; sd->island[0].end++; } } memset(sd->islandID, 0, MAP_SIZE_MAX * MAP_SIZE_MAX * sizeof(sd->islandID[0])); Skirmish_DivideIsland(HOUSE_INVALID, 0, sd); if (sd->nislands_unused == 0) return false; /* Spawn players. */ for (HouseType houseID = HOUSE_HARKONNEN; houseID < HOUSE_MAX; houseID++) { if (g_skirmish.brain[houseID] == BRAIN_NONE) continue; if (g_skirmish.brain[houseID] == BRAIN_HUMAN) Scenario_Create_House(houseID, g_skirmish.brain[houseID], 2000, 0, 250); else { House* h = Scenario_Create_House(houseID, g_skirmish.brain[houseID], 1000, 0, 250); h->flags.isAIActive = true; if (!Skirmish_GenStructuresAI(houseID, sd)) return false; } } for (HouseType houseID = HOUSE_HARKONNEN; houseID < HOUSE_MAX; houseID++) { if (g_skirmish.brain[houseID] == BRAIN_NONE) continue; if (g_skirmish.brain[houseID] == BRAIN_HUMAN) { if (!Skirmish_GenUnitsHuman(houseID, sd)) return false; } else { Skirmish_GenUnitsAI(houseID); } } Skirmish_GenSpiceBlooms(); Skirmish_GenSandworms(); Skirmish_GenCHOAM(); Game_Prepare(); GUI_ChangeSelectionType(SELECTIONTYPE_STRUCTURE); Scenario_CentreViewport(g_playerHouseID); g_tickScenarioStart = g_timerGame; return true; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow){ int iRetCode = CWOOD_OLOG->Init("WoodFree","C:\\CWLOG",true); if( iRetCode != 0 ){ //W_PRINT_ERROR_MSG_CHAR_INFO(iRetCode,"CWOOD_OLOG->Init Failed ErrMsg:%s",CWOOD_OLOG->GetLastErrMsg()); W_BOX_ALERT_CHAR_INFO(iRetCode,"CWOOD_OLOG->Init Failed ErrMsg:%s",CWOOD_OLOG->GetLastErrMsg()); return iRetCode; } CWOOD_LOG_DEBUG(" "); CWOOD_LOG_DEBUG(" ==================================== Compile Time:%s %s",__DATE__,__TIME__); WNDCLASS stWinclass; // this will hold the class we create HWND hWnd; // generic window handle MSG stMsg; // generic message HDC hDc; // generic dc PAINTSTRUCT stPaint; // generic paintstruct // first fill in the window class stucture stWinclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; stWinclass.lpfnWndProc = WindowProc; stWinclass.cbClsExtra = 0; stWinclass.cbWndExtra = 0; stWinclass.hInstance = hInstance; stWinclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); stWinclass.hCursor = LoadCursor(NULL, IDC_ARROW); stWinclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); stWinclass.lpszMenuName = NULL; stWinclass.lpszClassName = W_WINDOW_CLASS_NAME; // register the window class iRetCode = RegisterClass(&stWinclass); if ( iRetCode == 0 ){ //0 means error. NULL CWOOD_LOG_ERR(iRetCode,"%s","RegisterClass Failed!!"); return iRetCode; } // create the window, note the test to see if WINDOWED_APP is // true to select the appropriate window flags hWnd = CreateWindow(W_WINDOW_CLASS_NAME, // class W_WINDOW_TITLE, // title WS_POPUP | WS_VISIBLE, 0,0, // x,y W_WINDOW_WIDTH, // width W_WINDOW_HEIGHT, // height NULL, // handle to parent NULL, // handle to menu hInstance,// instance from outside. NULL); if( hWnd == NULL ){ iRetCode = -1; CWOOD_LOG_ERR(iRetCode,"%s %d","CreateWindow Failed!!"); return iRetCode; } /* RECT stWindowsRect = {0,0,W_WINDOW_WIDTH-1,W_WINDOW_HEIGHT-1}; // make the call to adjust window_rect AdjustWindowRectEx(&stWindowsRect, GetWindowLong(hWnd, GWL_STYLE), GetMenu( hWnd ) != NULL, GetWindowLong(hWnd, GWL_EXSTYLE)); // save the global client offsets, they are needed in DDraw_Flip() int window_client_x0 = -stWindowsRect.left; int window_client_y0 = -stWindowsRect.top; // now resize the window with a call to MoveWindow() MoveWindow(hWnd, 0, // x position 0, // y position stWindowsRect.right - stWindowsRect.left, // width stWindowsRect.bottom - stWindowsRect.top, // height FALSE); ShowWindow(hWnd, SW_SHOW); */ IDirect3DDevice9* pD3D9Device = NULL; iRetCode = Game_Init(hWnd,&pD3D9Device); if ( iRetCode != 0 ){ CWOOD_LOG_ERR(iRetCode,"%s","Game_Init Failed!!"); return iRetCode; } //============================================================================================ //============================================================================================ while(TRUE) { // test if there is a message in queue, if so get it if (PeekMessage(&stMsg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (stMsg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&stMsg); // send the message to the window proc DispatchMessage(&stMsg); } // end if if (KEYDOWN(VK_ESCAPE)){ SendMessage(hWnd,WM_CLOSE,0,0); } // main game processing goes here Game_Main(hWnd,pD3D9Device); } // end while Game_Shutdown(); return(stMsg.wParam); }
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASS winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message HDC hdc; // generic dc PAINTSTRUCT ps; // generic paintstruct // first fill in the window class stucture winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; // register the window class if (!RegisterClass(&winclass)) return(0); // create the window, note the use of WS_POPUP if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class "DirectSound 100hz Tone Demo", // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // x,y WINDOW_WIDTH, // width WINDOW_HEIGHT, // height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return(0); // save the window handle and instance in a global main_window_handle = hwnd; main_instance = hinstance; // perform all game console specific initialization // start up the directsound sound Game_Init(); // enter main event loop while(1) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while // shutdown game and release all resources Game_Shutdown(); // return to Windows like this return(msg.wParam); } // end WinMain
// // 函数: InitInstance(HINSTANCE, int) // // 目的: 保存实例句柄并创建主窗口 // // 注释: // // 在此函数中,我们在全局变量中保存实例句柄并 // 创建和显示主程序窗口。 // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; MSG msg; // generic message hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow(szWindowClass, szTitle, (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION),//WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } main_window_handle = hWnd; // now resize the window, so the client area is the actual size requested // since there may be borders and controls if this is going to be a windowed app // if the app is not windowed then it won't matter RECT window_rect = { 0, 0, WINDOW_WIDTH - 1, WINDOW_HEIGHT - 1 }; // make the call to adjust window_rect AdjustWindowRectEx(&window_rect, GetWindowStyle(main_window_handle), GetMenu(main_window_handle) != NULL, GetWindowExStyle(main_window_handle)); // save the global client offsets, they are needed in DDraw_Flip() //window_client_x0 = -window_rect.left; //window_client_y0 = -window_rect.top; // now resize the window with a call to MoveWindow() MoveWindow(main_window_handle, 0, // x position 0, // y position window_rect.right - window_rect.left, // width window_rect.bottom - window_rect.top, // height FALSE); // show the window, so there's no garbage on first render ShowWindow(hWnd, nCmdShow); Game_Init(); while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while //UpdateWindow(hWnd); Game_Shutdown(); return msg.wParam; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX wndClass = { 0 }; //用WINDCLASSEX定义了一个窗口类 wndClass.cbSize = sizeof(WNDCLASSEX); //设置结构体的字节数大小 wndClass.style = CS_HREDRAW | CS_VREDRAW; //设置窗口的样式 wndClass.lpfnWndProc = WndProc; //设置指向窗口过程函数的指针 wndClass.cbClsExtra = 0; //窗口类的附加内存,取0就可以了 wndClass.cbWndExtra = 0; //窗口的附加内存,依然取0就行了 wndClass.hInstance = hInstance; //指定包含窗口过程的程序的实例句柄。 wndClass.hIcon = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); //本地加载自定义ico图标 wndClass.hCursor = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); //指定窗口类的光标句柄。 wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //为hbrBackground成员指定一个白色画刷句柄 wndClass.lpszMenuName = NULL; //用一个以空终止的字符串,指定菜单资源的名字。 wndClass.lpszClassName = L"ForTheDreamOfGameDevelop"; //用一个以空终止的字符串,指定窗口类的名字。 if (!RegisterClassEx(&wndClass)) //设计完窗口后,需要对窗口类进行注册,这样才能创建该类型的窗口 return -1; HWND hwnd = CreateWindow(L"ForTheDreamOfGameDevelop", WINDOW_TITLE, //喜闻乐见的创建窗口函数CreateWindow WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true); //调整窗口显示时的位置,使窗口左上角位于(250,80)处 ShowWindow(hwnd, nShowCmd); //调用ShowWindow函数来显示窗口 UpdateWindow(hwnd); //对窗口进行更新,就像我们买了新房子要装修一样 //游戏资源的初始化,若初始化失败,弹出一个消息框,并返回FALSE if (!Game_Init(hwnd)) { MessageBox(hwnd, L"资源初始化失败", L"消息窗口", 0); //使用MessageBox函数,创建一个消息窗口 return FALSE; } PlaySound(L"GameMedia\\梦幻西游原声-战斗1-森林.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); //循环播放背景音乐 hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(123)); SetMenu(hwnd, hMenu); MSG msg = { 0 }; //定义并初始化msg while (msg.message != WM_QUIT) //使用while循环,如果消息不是WM_QUIT消息,就继续循环 { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) //查看应用程序消息队列,有消息时将队列中的消息派发出去。 { TranslateMessage(&msg); //将虚拟键消息转换为字符消息 DispatchMessage(&msg); //分发一个消息给窗口程序。 } else { g_tNow = GetTickCount(); //获取当前系统时间 if (g_tNow - g_tPre >= 60){ if (nowscen == 1) Game_Fight(hwnd); else{ Game_Paint(hwnd); } } } } UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance); //程序准备结束,注销窗口类 return 0; }
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message HDC hdc; // graphics device context // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // save hinstance in global main_instance = hinstance; // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL, // extended style WINDOW_CLASS_NAME, // class "DirectInput Keyboard Demo", // title (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)), 0,0, // initial x,y SCREEN_WIDTH,SCREEN_HEIGHT, // initial width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance of this application NULL))) // extra creation parms return(0); // save main window handle main_window_handle = hwnd; // resize the window so that client is really width x height if (WINDOWED_APP) { // now resize the window, so the client area is the actual size requested // since there may be borders and controls if this is going to be a windowed app // if the app is not windowed then it won't matter RECT window_rect = { 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 }; // make the call to adjust window_rect AdjustWindowRectEx(&window_rect, GetWindowStyle(main_window_handle), GetMenu(main_window_handle) != NULL, GetWindowExStyle(main_window_handle)); // save the global client offsets, they are needed in DDraw_Flip() window_client_x0 = -window_rect.left; window_client_y0 = -window_rect.top; // now resize the window with a call to MoveWindow() MoveWindow(main_window_handle, 0, // x position 0, // y position window_rect.right - window_rect.left, // width window_rect.bottom - window_rect.top, // height FALSE); // show the window, so there's no garbage on first render ShowWindow(main_window_handle, SW_SHOW); } // end if windowed // initialize game here Game_Init(); // enter main event loop while(TRUE) { // test if there is a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while // closedown game here Game_Shutdown(); // return to Windows like this return(msg.wParam); } // end WinMain
// ************* Buttons ************* // this is the major function that handles the button presses // such as movements, attack, and mute, this function will // also check if the game has been won or lost and restart // the input is an int containing buttons that were pressed void Buttons(int keyPressed){ if (gameEnd == WON){ // win DisableInterrupts(); ClearLCDgameStarted(); // displays win banner LCD12864ImageDraw(&display[0],&room[0],&youWin[0],WIN_X,WIN_Y,WIN_WIDTH,WIN_HEIGHT); LCD12864PartUpdate(&display[0],WIN_X,WIN_Y,WIN_WIDTH,WIN_HEIGHT); SysTick_Wait10ms((GAME_RESTART_DELAY)/10); // wait 2 seconds to start game over Game_Init(); keyPressed = 0; EnableInterrupts(); Music_Play(); } else if (gameEnd == LOST){ // lose DisableInterrupts(); ClearLCDgameStarted(); // displays lose banner LCD12864ImageDraw(&display[0],&room[0],&gameOver[0],LOSE_X,LOSE_Y,LOSE_WIDTH,LOSE_HEIGHT); LCD12864PartUpdate(&display[0],LOSE_X,LOSE_Y,LOSE_WIDTH,LOSE_HEIGHT); SysTick_Wait10ms((GAME_RESTART_DELAY)/10); // wait 2 seconds to start game over Game_Init(); keyPressed = 0; EnableInterrupts(); Music_Play(); } // the following handles the inputs from the user // up button moves link up if ((keyPressed&UP) && gameStarted){ MoveUp(); } // down button moves link down if ((keyPressed&DOWN) && gameStarted){ MoveDown(); } // left button moves link to the left if ((keyPressed&LEFT) && gameStarted){ MoveLeft(); } // right button moves link to the right if ((keyPressed&RIGHT) && gameStarted){ MoveRight(); } // "A" button attacks with sword if ((keyPressed&A) && gameStarted){ PressA(); } // starts the game else if((keyPressed&A) && !gameStarted){ LCD12864ImageDraw(&display[0],&room[0],&room[0],0,0,LCD_WIDTH,LCD_HEIGHT); // draw room LCD12864ImageDraw(&display[0],&room[0],Link.Graphic,Link.Xpos,Link.Ypos,Link.Width,Link.Height); // draw link LCD12864Refresh(&display[0]); // display SysTick_Wait10ms(50); LCD12864ImageDraw(&display[0],&room[0],Boss.Graphic,Boss.Xpos,Boss.Ypos,Boss.Width,Boss.Height); // draw boss LCD12864Refresh(&display[0]); Change_Song(1); LCD12864GameStart(); Timer1A_Enable(); gameStarted = 1; } // "B" button mutes the game music if ((keyPressed&B) && gameStarted){ PressB(); ClearB(); } // updates the screen when Link moves if(keyPressed && gameStarted){ LCD12864ImageDraw(&display[0],&room[0],Link.Graphic,Link.Xpos,Link.Ypos,Link.Width,Link.Height); LCD12864PartUpdate(&display[0],Link.Xpos,Link.Ypos,Link.Width,Link.Height); CheckContact(); SysTick_Wait10ms((LINK_SPEED)/10); // time to wait until next movement } }