//--------------------------------------------------------------------------- //########################################################################### int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass ; HWND hwnd ; MSG msg ; winclass.cbSize=sizeof(WNDCLASSEX); winclass.style =CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra=0; winclass.cbWndExtra=0; 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); if(!RegisterClassEx(&winclass)) return(0); hwnd=CreateWindowEx(NULL,WINDOW_CLASS_NAME, "THE HIVE", WS_POPUP|WS_VISIBLE, 0,0, //- position screen_HEIGHT,screen_WIDTH, //- size NULL,NULL,hinstance,NULL); if(!hwnd)return(0); main_handle = hwnd ; main_hinstance = hinstance ; GameInit(); // INITIALIZING while(true) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message==WM_QUIT)break; TranslateMessage(&msg); DispatchMessage(&msg); } ; GameMain(); // MAIN GAME FUNCTION } ; GameExit(); // RELEASE return(msg.wParam); };
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch (message) { case WM_CREATE: GameInit(hwnd); break; case WM_TIMER: GamePaint(hwnd); break; case WM_DESTROY: GameClearup(hwnd); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
int main() { GameInit(); DrawMap(); // DrawMap(); while(!s3eDeviceCheckQuitRequest()) { s3ePointerUpdate(); s3eKeyboardUpdate(); if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT)) { Go(s3ePointerGetX(),s3ePointerGetY()); } // S3E applications should yield frequently s3eDeviceYield(); } return 0; }
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){ ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定 GameInit(); // 裏画面を表画面に反映, メッセージ処理, 画面クリア while(ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0){// gpUpdateKey(); if(game == start){ GameStart(); }else if(game == playing){ GamePlaying(); }else{ GameOver(); } DrawBox(FieldLeft, FieldTop, FieldRight, FieldBottom, GetColor(255, 255, 255), FALSE); //フィールドの表示 } DxLib_End(); // DXライブラリ終了処理 return 0; }
int GameUpdate(TGAME* Juego){ Juego->GanadorEncontrado = CheckFull(); Keyboard_Update(&(Juego->Teclado)); if(Keyboard_Check(&(Juego->Teclado), eKey_Esc)){ Juego->EstadoActual = Terminado; return 0; } if(Juego->GanadorEncontrado){ Juego->EstadoActual = Lleno; if(Keyboard_Check(&(Juego->Teclado), eKey_Enter)){ GameInit(Juego); } return 0; } if(!(Juego->pos_o_linea)){ CheckForWin(Juego); } if(Keyboard_Check(&(Juego->Teclado), eKey_Enter) && Juego->pos_o_linea==false){ Sleep(200); Juego->pos_o_linea = !(Juego->pos_o_linea); //GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1], ' '); if(pos_cursor[0]<48) Juego->eLinea = Right; else Juego->eLinea = Left; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Enter) && Juego->pos_o_linea==true){ Juego->pos_o_linea = !(Juego->pos_o_linea); // GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1], ' '); } return 0; }
HRESULT CWin::Create() { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = m_hInstance; wcex.hIcon = m_hIcon; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = m_hbrWindowColor; wcex.lpszMenuName = NULL; wcex.lpszClassName = _T("Skeleton"); wcex.hIconSm = NULL; ::RegisterClassEx(&wcex); m_hWnd = ::CreateWindowEx(m_dwExWindowStyle,_T("Skeleton"), m_strWindowTitle, m_dwWindowStyle, m_PosX, m_PosY, m_dwCreationWidth, m_dwCreationHeight, NULL, m_hMenu, m_hInstance, NULL); if (!m_hWnd) { return FALSE; } graphics = ::GetDC(m_hWnd); GameInit(); ::ShowWindow(m_hWnd, m_dwCreationFlags); ::UpdateWindow(m_hWnd); return TRUE; }
Sint32 CGameGunHound::AdvertiseDemo() { //--------------------------------------------- //デモ //--------------------------------------------- if( m_pOpeningDemo == NULL ) { m_pOpeningDemo = new COpeningDemo(); } m_pOpeningDemo->Action(); Sint32 opCode = m_pOpeningDemo->GetOperation(); if( m_pOpeningDemo->IsEnd() ) { delete m_pOpeningDemo; m_pOpeningDemo = NULL; opCode = COpeningDemo::enOperationEnd; } else { m_pOpeningDemo->Draw(); } switch( opCode ){ case COpeningDemo::enOperationInit: //ゲームを初期化 g_StGameInfo.PlayStage = GetDemoStage(); pGame = new CGameManager(); GameInit(); g_StGameInfo.m_bMusic = gxFalse; g_StGameInfo.m_bMessage = gxFalse; g_StGameInfo.m_bReplay = gxTrue; pGame->init(); m_sDemoCount ++; break; case COpeningDemo::enOperationMain: //ゲームを更新 GameMain(); if( CCockpit::GetInstance()->IsGameOver() ) { m_pOpeningDemo->SetStatusGameOver(); } break; case COpeningDemo::enOperationEnd: GameEnd(); if( pGame ) { delete pGame; pGame = NULL; } CCockpit::GetInstance()->ReNew(); return -1; default: break; } return 0; }
/* Initialise SDL and create a window of the correct size. */ int BaseEngine::Initialise( char* strCaption, int iScreenWidth, int iScreenHeight, char* szFontName, int iFontSize ) { m_iScreenWidth = iScreenWidth; m_iScreenHeight = iScreenHeight; // Initialize SDL's subsystems if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); return 1; } // Register SDL_Quit to be called at exit; makes sure things are // cleaned up when we quit. atexit(SDL_Quit); // True type font stuff TTF_Init(); atexit(TTF_Quit); m_oFontManager.LoadFonts(); // Load the default font - used whenever NULL is passed if ( ( szFontName != NULL ) && ( strlen(szFontName) > 0 ) ) g_pMainFont = m_oFontManager.GetFont( szFontName, iFontSize ); // Attempt to create a m_iScreenWidth x m_iScreenHeight window with 32bit pixels. m_pActualScreen = SDL_SetVideoMode(m_iScreenWidth, m_iScreenHeight, 32, SDL_SWSURFACE); // m_pActualScreen = SDL_SetVideoMode(m_iScreenWidth, m_iScreenHeight, 32, SDL_HWSURFACE); // m_pActualScreen = SDL_SetVideoMode(m_iScreenWidth, m_iScreenHeight, 32, SDL_DOUBLEBUF); SDL_WM_SetCaption( strCaption, NULL ); #if defined(_MSC_VER) SDL_SysWMinfo i; SDL_VERSION( &i.version ); if ( SDL_GetWMInfo ( &i ) ) { HWND hwnd = i.window; SetWindowPos( hwnd, HWND_TOP, 0, 0, m_iScreenWidth, m_iScreenHeight, SWP_NOSIZE ); } #endif // WIN32 m_pBackgroundSurface = SDL_AllocSurface( SDL_SWSURFACE/*flags*/, m_iScreenWidth, m_iScreenHeight, 32, 0,0,0,0 ); // If we fail, return error. if (m_pActualScreen == NULL) { fprintf(stderr, "Unable to set up video: %s\n", SDL_GetError()); return 2; } // Retrieve the number of ints per row from the screen information m_iIntsPerScreenRow = m_pActualScreen->pitch/sizeof(unsigned int); //m_puiScreenBuffer = new unsigned int [ m_iIntsPerScreenRow * m_iScreenHeight ]; // Initialise key status m_pKeyStatus = new int[1 + SDLK_LAST - SDLK_FIRST]; memset( m_pKeyStatus, 0, sizeof(int)*(1 + SDLK_LAST - SDLK_FIRST) ); // Call method to allow custom sub-class initialiation. GameInit(); return 0; // success }
LONG T_Engine::GameEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { HDC hdc; switch (msg) { case WM_SETFOCUS: SetSleep(FALSE); return 0; case WM_KILLFOCUS: SetSleep(TRUE); return 0; case WM_CREATE: m_hWnd = hWnd; GameInit(); return 0; case WM_LBUTTONDOWN: GameMouseAction(LOWORD(lParam), HIWORD(lParam), MOUSE_LCLICK); return 0; case WM_MOUSEMOVE: GameMouseAction(LOWORD(lParam), HIWORD(lParam), MOUSE_MOVE); return 0; case WM_KEYDOWN: keys[wParam] = true; GameKeyAction(KEY_DOWN); SubKeyAction(wParam); return 0; case WM_KEYUP: keys[wParam] = false; GameKeyAction(KEY_UP); return 0; case WM_NCLBUTTONDBLCLK: if(HTCAPTION==wParam) { return 0; } case WM_SYSCOMMAND: if(wParam == SC_MAXIMIZE) { m_bFullScreen=!m_bFullScreen; if(m_bFullScreen) { GetWindowRect(hWnd, &m_rcOld); style = GetWindowLong(hWnd,GWL_STYLE); ex_style = GetWindowLong(hWnd, GWL_EXSTYLE); p_disp->SaveMode(); //全屏幕显示 HWND hDesktop; RECT rc; hDesktop = GetDesktopWindow(); GetWindowRect(hDesktop, &rc); p_disp->ChangeMode(wndWidth, wndHeight); SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_WINDOWEDGE); SetWindowLong(hWnd, GWL_STYLE, WS_BORDER); SetWindowPos(hWnd, HWND_TOP, -1, -1, rc.right, rc.bottom, SWP_SHOWWINDOW); } } else if(wParam == SC_CLOSE) { if(IDOK==MessageBox(NULL,L"你确定要退出吗?", wndTitle, MB_OKCANCEL|MB_ICONQUESTION)) { DestroyWindow(hWnd); } } else { return DefWindowProc(hWnd, WM_SYSCOMMAND, wParam,lParam); } return 0; case WM_CLOSE: DestroyWindow(hWnd); return 0; case WM_PAINT: PAINTSTRUCT ps; hdc=BeginPaint(hWnd,&ps); GamePaint(hdc); EndPaint(hWnd,&ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }
cGame::cGame(iLowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars) { GameInit(apGameSetup,aVars); }
void NetworkManager::GameRun() { PacketType type; Network::GameStartData gameStartData; puts("게임 시작 대기중"); network.WaitForStart(&gameStartData); wprintf_s(L"매칭되었습니다. 상대방 이름: %s, 학번: %d\n", gameStartData.oppositionName, gameStartData.oppositionStudentID); bool allOver = false; while (!allOver) { GameInit(); ShipSetting(); try { GameStart(); network.GetPacketType(&type); if (type == PKT_SC_NEXT_GAME) { puts("다음 게임을 준비해주세요."); } else if (type == PKT_SC_ALL_OVER) { Network::FinalResultData finalresult; finalresult = network.GetFinalResult(); puts("모두 종료"); printf_s("승리 횟수: %d, 평균 턴 수: %.1f", finalresult.winCount, finalresult.avgTurns); allOver = true; } else { throw Network::UNEXPECTED_PACKET; } } catch (Network::Exception ex) { switch (ex) { case Network::NETWORK_ERROR: puts("네트워크에 문제가 발생했습니다."); break; case Network::SERVER_CLOSED: puts("서버와의 연결이 끊어졌습니다."); break; case Network::PARAMETER_ERROR: puts("함수의 인수가 잘못되었습니다."); break; case Network::UNEXPECTED_PACKET: puts("서버에서 잘못된 정보가 전송되었습니다."); break; default: break; } } } }
/************************************************************************* SetupWindow Create and show the window *************************************************************************/ bool SetupWindow() { // get our instance handle g_hInstance = GetModuleHandle(NULL); WNDCLASSEX wc; // window class // fill out the window class structure wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon wc.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow wc.hbrBackground = NULL; // no background needed wc.lpszMenuName = NULL; // no menu wc.lpszClassName = WND_CLASS_NAME; // register the windows class if (!RegisterClassEx(&wc)) { MessageBox(NULL,"Unable to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION); // exit and return false return false; } DWORD dwExStyle; DWORD dwStyle; // set the window style appropriately, depending on whether we're in fullscreen mode if (g_isFullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; // simple window with no borders or title bar ShowCursor(FALSE); // hide the cursor for now } else { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; } // set up the window we're rendering to so that the top left corner is at (0,0) // and the bottom right corner is (height,width) RECT windowRect; windowRect.left = 0; windowRect.right = (LONG) g_screenWidth; windowRect.top = 0; windowRect.bottom = (LONG) g_screenHeight; // change the size of the rect to account for borders, etc. set by the style AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); // class registered, so now create our window g_hwnd = CreateWindowEx(dwExStyle, // extended style WND_CLASS_NAME, // class name APP_TITLE, // app name dwStyle | // window style WS_CLIPCHILDREN | // required for WS_CLIPSIBLINGS, // using OpenGL 0, 0, // x,y coordinate windowRect.right - windowRect.left, // width windowRect.bottom - windowRect.top, // height NULL, // handle to parent NULL, // handle to menu g_hInstance, // application instance NULL); // no extra params // see if our window handle is valid if (!g_hwnd) { MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONEXCLAMATION); return false; } // if we're in fullscreen mode, set the display up for it if (g_isFullscreen) { // set up the device mode structure DEVMODE screenSettings; memset(&screenSettings,0,sizeof(screenSettings)); screenSettings.dmSize = sizeof(screenSettings); screenSettings.dmPelsWidth = g_screenWidth; // screen width screenSettings.dmPelsHeight = g_screenHeight; // screen height screenSettings.dmBitsPerPel = COLOR_BITS; // bits per pixel screenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // attempt to switch to the resolution and bit depth we've selected if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { // if we can't get fullscreen, let them choose to quit or try windowed mode if (MessageBox(NULL, "Cannot run in the fullscreen mode at the selected resolution\n" "on your video card. Try windowed mode instead?", "glAucoma", MB_YESNO | MB_ICONEXCLAMATION) == IDYES) { g_isFullscreen = false; } else { return false; } } } // get a device context if (!(g_hdc = GetDC(g_hwnd))) { MessageBox(NULL,"Unable to create device context", "Error", MB_OK | MB_ICONEXCLAMATION); return false; } if (!SetupPixelFormat()) return false; // create the OpenGL rendering context if (!(g_hrc = wglCreateContext(g_hdc))) { MessageBox(NULL, "Unable to create OpenGL rendering context", "Error",MB_OK | MB_ICONEXCLAMATION); return false; } // now make the rendering context the active one if(!wglMakeCurrent(g_hdc, g_hrc)) { MessageBox(NULL,"Unable to activate OpenGL rendering context", "ERROR", MB_OK | MB_ICONEXCLAMATION); return false; } // show the window in the forground, and set the keyboard focus to it ShowWindow(g_hwnd, SW_SHOW); SetForegroundWindow(g_hwnd); SetFocus(g_hwnd); // set up the perspective for the current screen size ResizeScene(g_screenWidth, g_screenHeight); // do one-time initialization if (!GameInit()) { MessageBox(NULL, "Initialization failed", "Error", MB_OK | MB_ICONEXCLAMATION); return false; } return true; } // end SetupWindow()
void GameUpdate() { game* g = &g_game; if (is_key_pressed(KEY_RESET)) { memset(g->_map, 0, sizeof(g->_map)); g->_entities.free(); g->_player = 0; g->_cam_pos = vec2(MAP_WIDTH * 0.5f, 8.5f); g->_target_cam_y = 8.5f; g->_diff = 1; g->_diff_dmg = 1; g->_spawn_time = 800; g->_spawn_count = 6; g->_wave_incoming = true; g->_plr_dmg = 1; GameInit(); g_title = true; } if (g_title) { set_camera(vec2(), 10.0f); float ratio = g_WinSize.y / (float)g_WinSize.x; vec2 orig(-10.0f, -10.0f * ratio); draw_string(vec2(0.0f, -4.75), 0.15f, TEXT_CENTRE, colour(0.5f, 0.5f, 1.0f, 1.0f), "Tunnel Defense"); float y = -3.25f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.3f, 0.6f, 1.0f), "Originally made for LD29 - post competition version"); y += 0.5f; y += 0.5f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "Dig for your life, the creeps are coming and the"); y += 0.5f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "only safe place is underground! Collect resources"); y += 0.5f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "and build turrets to protect yourself."); y += 0.5f; y += 0.25f; float r = 5.0f; draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "\001\002\003\004"); draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Move + Aim"); y += 0.5f; draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyZ); draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Jump"); y += 0.5f; draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyX); draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Dig block / shoot"); y += 0.5f; draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyC); draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Build / upgrade turret"); y += 0.5f; y += 0.25f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.15f, 0.3f, 0.15f, 1.0f), "Alternate controls - %c%c%c%c, %c, %c, %c", g_LocKeyW, g_LocKeyA, g_LocKeyS, g_LocKeyD, g_LocKeyI, g_LocKeyO, g_LocKeyP); y += 0.5f; y += 0.25f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.15f, 0.3f, 1.0f), "Building / upgrading a turret costs 3 metal."); y += 0.5f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.15f, 0.3f, 1.0f), "Building a turret increases your shot power."); y += 0.5f; y += 0.25f; draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.5f, 0.5f, 0.5f, 1.0f), "press SPACE to START"); y+= 0.5f; y += 0.5f; draw_string(vec2(0.0f, y), 0.035f, TEXT_CENTRE, colour(0.15f, 0.15f, 0.15f, 1.0f), "by Stephen Cakebread @quantumrain"); if (is_key_pressed(KEY_FIRE) || is_key_pressed(KEY_ALT_FIRE)) g_title = false; return; } if (player* p = g->_player) { vec2 target_cam_pos = vec2(MAP_WIDTH * 0.5f, p->centre().y); float dy = target_cam_pos.y - g->_target_cam_y; float hyst = 1.25f; if (fabsf(dy) > hyst) { if (dy > 0.0f) g->_target_cam_y += dy - hyst; else g->_target_cam_y += dy + hyst; } target_cam_pos.y = g->_target_cam_y; update_search(g, to_ivec2(p->centre())); g->_cam_pos = lerp(g->_cam_pos, target_cam_pos, 0.2f); g->_plr_dmg = 1; for(uint32_t i = 0; i < g->_entities.size(); i++) { entity* e = g->_entities[i]; if (!(e->_flags & entity::FLAG_DESTROYED)) { if (e->_type == ET_TURRET) g->_plr_dmg++; } } } set_camera(g->_cam_pos, 15.0f); if (g->_player) { if (--g->_spawn_time <= 0) { if (g->_wave_incoming) { g->_spawn_count = 4 + 4 * (int)g->_diff; g->_diff_dmg = (int)(2.5f * (1 + g->_diff)) - 1; } g->_wave_incoming = false; vec2 pos(g_game_rand.frand(1.0f, MAP_WIDTH - 1.0f), 2.0f); if (bug* e = spawn_entity(&g_game, new bug(), pos)) { e->_max_damage = g->_diff_dmg; if (g_game_rand.rand(0, 5) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg); if (g_game_rand.rand(0, 15) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg); if (g_game_rand.rand(0, 30) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg); } g->_spawn_time = clamp(60 - ((g->_diff * 5) / 4), 10, 60); if (--g->_spawn_count <= 0){ g->_diff += 1 + (g->_diff / 5); g->_spawn_time = 600; g->_wave_incoming = true; } } } tick_entities(g); purge_entities(g); update_particles(g); colour sky0(0.4f, 0.7f, 1.0f, 1.0f); colour sky1(0.45f, 0.75f, 1.0f, 1.0f); colour sky2(0.3f, 0.6f, 0.9f, 1.0f); colour sky3(0.35f, 0.65f, 0.9f, 1.0f); sky0 *= colour(0.65f, 0.0f); sky1 *= colour(0.65f, 0.0f); sky2 *= colour(0.35f, 1.0f); sky3 *= colour(0.35f, 1.0f); float sky_space = 4.5f; float sky_top = 4.75f; float sky_y = 10.0f; float sky_yf = 10.5f; float sky_yb = 11.0f; for(int j = 0; j < MAP_HEIGHT; j++) { colour bk_colour(get_master_colour(j) * colour(0.2f, 1.0f)); for(int i = 0; i < MAP_WIDTH; i++) { int t = g->get_tile(i, j); if (t == TT_EMPTY || t == TT_TURRET) { int hash = ((i * 7) ^ (j * 3)) + (i + j); hash ^= ((hash >> 3) * 9); int tile_num = 132 + (hash % 4); draw_tile(vec2((float)i, (float)j), vec2(i + 1.0f, j + 1.0f), bk_colour, tile_num, 0); } } }
void kol_main() { BoardPuts("Hello, Heliothryx!\n"); int err; int version =-1; if((err = InitSound(&version)) !=0 ){ BoardPuts("Sound Error 1\n"); }; if( (SOUND_VERSION>(version&0xFFFF)) || (SOUND_VERSION<(version >> 16))){ BoardPuts("Sound Error 2\n"); } unsigned event; unsigned key; unsigned key_up; unsigned btn, btn_state; unsigned pos, x, y; int gx, gy; //srand(kol_system_time_get()); kol_event_mask(0xC0000027); // mouse and keyboard kol_key_mode_set(1); area_width = 512; area_height = 512; // Initializing variables window_width = FIX_MENUETOS_LEGACY_ONE_PIXEL_BORDER_GAP_BUG + area_width + 10; // 2 x 5px border window_height = FIX_MENUETOS_LEGACY_ONE_PIXEL_BORDER_GAP_BUG + kol_skin_height() + area_height + 5; // bottom 5px border //rs_main_init(); GameInit(); wnd_draw(); fps = 0; unsigned int tick_start = kol_time_tick(); unsigned int tick_current = tick_start; unsigned int tick_last = tick_start; unsigned int fps_counter = 0; int wait_time; int already_drawn = 0; float xf; float xfs; int xfs_i; while (1) { tick_last = tick_current; tick_current = kol_time_tick(); dt = tick_current - tick_last; tick_last = tick_current; already_drawn = 0; while (( event = kol_event_wait_time(1) )) { //while (( event = kol_event_wait() )) { switch (event) { case 1: wnd_draw(); // <--- need to clear event! already_drawn = 1; break; case 2: key = kol_key_get(); key = (key & 0xff00)>>8; key_up = key & 0x80; key = key & 0x7F; if (key_up) { GameKeyUp(key); //rs_app.OnKeyUp(key); } else { GameKeyDown(key); //rs_app.OnKeyDown(key, 1); }; break; case 3: switch ((kol_btn_get() & 0xff00)>>8) { case 1: // close button kol_exit(); case 2: // 'new' button //init_board(); //wnd_draw(); break; } break; case 6: btn = kol_mouse_btn() & 1; // read mouse button (only left) pos = kol_mouse_posw(); // read mouse position x = pos / 65536; y = pos % 65536; /*if (x > window_width) x=0; if (y > window_height) y=0;*/ if (btn && (!btn_state)) { //rs_app.OnMouseDown(x,y); GameMouseDown(x, y); BoardPuts("MouseDown!\n"); } else if ( (!btn) && btn_state ) { //rs_app.OnMouseUp(x,y); GameMouseUp(x, y); } else { //GameMouseMove(x, y); }; btn_state = btn; break; } }; if (!already_drawn) { wnd_draw(); }; fps_counter++; tick_current = kol_time_tick(); if (tick_current > tick_start+100) { fps = fps_counter; fps_counter = 0; tick_start += 100; }; draw_dt = tick_current - tick_last; wait_time = (100/GAME_REQUIRED_FPS) - draw_dt; if (wait_time <= 0) { wait_time = 1; }; kol_sleep(wait_time); } GameTerm(); kol_exit(); }
int main(int argc, char** argv) { #ifdef DEBUGCONSOLE if(AllocConsole()) { freopen("CONOUT$", "wt", stdout); SetConsoleTitle("The Outcast : Debug Console"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); } #endif DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "THE OUTCAST 0.4\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "===============\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Reading cmd line arguments\n"); for (int i=1;i<argc;i++) { if (!strcmp(argv[i], "sprplayground")) { sprplayground = true; } #ifndef WIN32 // linux only arguments: if (!strcmp(argv[i], "softwarerenderer")) { setenv("LIBGL_ALWAYS_INDIRECT", "1", 1); } #endif } DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up net\n"); NetInit(); DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up database\n"); DBInit(); DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up sound system\n"); SoundInit(NULL); DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up windowing system\n"); win_Init(&argc, argv); options.Load(); win_CreateDisplay(); DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up GL\n"); GLInit(); if (!sprplayground) { DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Loading skin\n"); skin = new Skin; skin->Load(options.skin.c_str()); } DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Loading mousepointer\n"); win_SetMousePointer("DEFAULT"); // game must be inited LAST. DEBUGPRINT(DEBUGPRINT_LEVEL_USEFUL, DEBUGPRINT_NORMAL, "Setting up game\n"); GameInit(); win_MainLoop(); return 0; }
int main() { // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. SYSTEMConfig(F_SYS, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); // Auto-configure the PIC32 for optimum performance at the specified operating frequency. SYSTEMConfigPerformance(F_SYS); // osc source, PLL multipler value, PLL postscaler , RC divisor OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1); // Configure the PB bus to run at 1/4th the CPU frequency, so 20MHz. OSCSetPBDIV(OSC_PB_DIV_4); // Enable multi-vector interrupts INTEnableSystemMultiVectoredInt(); INTEnableInterrupts(); // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer. OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, F_PB / 16 / 100); // Set up the timer interrupt with a medium priority of 4. INTClearFlag(INT_T2); INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T2, INT_ENABLED); /******************************** Your custom code goes below here ********************************/ int check; OledInit(); AdcInit(); LEDS_INIT(); check = GameInit(); if(check == STANDARD_ERROR) { FATAL_ERROR(); } float currPage; float binSize; float titleSize; float descSize; float numPages; uint8_t roomExit; uint16_t adcValue = 0; while(1) { roomExit = GameGetCurrentRoomExits(); LEDS_SET(roomExit); while(buttonEvents == 0) { descSize = GameGetCurrentRoomDescription(roomData.description); titleSize = GameGetCurrentRoomTitle(roomData.title); numPages = ((titleSize + descSize) / MAX_OLED_PIXELS); binSize = (ADC_MAX_VALUE / numPages); if(AdcChanged()) { adcValue = AdcRead(); } currPage = (adcValue / binSize); if(currPage < 1) { char titleArray[TITLE_OLED_SPACE] = {0}; char descriptionBuffer[FIRST_PG_DESCRIPTION_OLED_SPACE] = {0}; strncpy(descriptionBuffer, roomData.description, DESCRIPTION_COPY); sprintf(titleArray, "%s\n%s", roomData.title, descriptionBuffer); OledClear(OLED_COLOR_BLACK); OledDrawString(titleArray); } else { char buffer[MAX_OLED_PIXELS] = {0}; int buffIndex; buffIndex = (int)currPage * MAX_OLED_PIXELS; strncpy(buffer, (roomData.description + buffIndex - OFFSET), MAX_OLED_PIXELS); OledClear(OLED_COLOR_BLACK); OledDrawString(buffer); } OledUpdate(); } if((buttonEvents & BUTTON_EVENT_4UP) && (roomExit & GAME_ROOM_EXIT_NORTH_EXISTS)) { GameGoNorth(); } else if((buttonEvents & BUTTON_EVENT_3UP) && (roomExit & GAME_ROOM_EXIT_EAST_EXISTS)) { GameGoEast(); } else if((buttonEvents & BUTTON_EVENT_2UP) && (roomExit & GAME_ROOM_EXIT_SOUTH_EXISTS)) { GameGoSouth(); } else if((buttonEvents & BUTTON_EVENT_1UP) && (roomExit & GAME_ROOM_EXIT_WEST_EXISTS)) { GameGoWest(); } buttonEvents = BUTTON_EVENT_NONE; } /**************************************************************************************************/ while (1); }
int c_player::Process(){ control->UpdateKeyInput(); board->Draw(); board->DrawPuyo(); board->DrawScoreBoard(this->score); switch(mode){ case 0: DrawString(10,360,"Press SPACE key to start.",GetColor(255,255,255)); DrawString(10,380,"Change Colors <- -> Key.",GetColor(255,255,255)); DrawFormatString(10,400,GetColor(255,255,255),"Colors:%d",colors); //change colors much if(control->GetStateKey(KEY_INPUT_LEFT) == 1) colors--; if(control->GetStateKey(KEY_INPUT_RIGHT) == 1)colors++; if(colors < 2) colors = 2; if(colors > 5) colors = 5; if(control->GetStateKey(KEY_INPUT_SPACE) == 1){ GameInit(); loop_count = 0; mode = 1; DelMode = 0; } break; case 1: board->DrawNextPuyo(next_puyo); if(DelMode == 0){ DropControl(); board->DrawDropPuyo(next_x,next_y,n_drop); }else if(DelMode == 1){ int rr = 0; if(r_del > 0)DrawFormatString(250,300,GetColor(255,255,255),"%d Chains!",r_del); if( loop_count % 20 == 0 ){ if(board->DownPuyo() == 0){ int ma = 0; rr = board->DeletePuyo(&ma); if(rr > 0)r_del++; score += sqrt(pow(SCORE_MULTIPLIER,r_del) * sqrt(pow((SCORE_MULTIPLIER * ma),rr) * colors)); if(rr == 0){ if(board->CheckGameOver() != 0) mode = 2; else{ DelMode = 0; r_del = 0; SetNext(); } } } } } loop_count++; break; case 2: board->DrawGameOver(); if(control->GetStateKey(KEY_INPUT_SPACE) == 1) board->Init(),mode = 0,score = 0; break; } if(control->GetStateKey(KEY_INPUT_ESCAPE) == 1) return 1; return 0; }
void GameOnKeyCallback(int keypressed) { switch(keypressed) { case '7': fCoF = clampf(fCoF + 0.05f, 0.0f, 1.0f); break; case '4': fCoF = clampf(fCoF - 0.05f, 0.0f, 1.0f); break; case '8': fCoR = clampf(fCoR + 0.05f, 0.0f, 1.0f); break; case '5': fCoR = clampf(fCoR - 0.05f, 0.0f, 1.0f); break; case '9': fGlue = clampf(fGlue + 0.01f, 0.0f, 3.0f); break; case '6': fGlue = clampf(fGlue - 0.01f, 0.0f, 3.0f); break; case 'p': case 'P': dbg_Pause = !dbg_Pause; break; case 'f': case 'F': dbg_UseFriction = !dbg_UseFriction; break; case 'g': case 'G': dbg_UseGravity = !dbg_UseGravity; break; case '-': case '_': m_iNumBodies--; if (m_iNumBodies < eMinBodies) m_iNumBodies = eMinBodies; break; case 13: m_iNumBodies = eNumBodiesDefault; return; case '+': case '=': m_iNumBodies++; if (m_iNumBodies >= eNumBodies) m_iNumBodies = eNumBodies-1; break; case ' ': GameInit(); break; case 'h': case 'H': ikeypressedtimer = 0; break; default: printf("\n"); printf("--------------------------------\n"); printf("- Keys -\n"); printf("--------------------------------\n"); printf("- Pause On/Off : 'p'\n"); printf("- Gravity On/Off : 'g'\n"); printf("- Glue On/Off : 's'\n"); printf("- Friction On/Off : 'f'\n"); printf("- Add Box : '+'\n"); printf("- Remove box : '-'\n"); printf("- Reset box count : 'return'\n"); printf("- Reset simulation : 'spacebar'\n"); printf("- Friction : 'numpad 7-4'\n"); printf("- Restitution : 'numpad 8-5'\n"); printf("- help : 'h'\n"); printf("--------------------------------\n"); printf("\n"); break; } CBody::SetRestitution(fCoR); CBody::SetFriction (fCoF); CBody::SetGlue (fGlue); printf("\n"); printf("--------------------------------\n"); printf("- Flags -\n"); printf("--------------------------------\n"); printf("- Gravity [%s]\n", dbg_UseGravity ? "On" : "Off"); printf("- Friction [%s]\n", dbg_UseFriction ? "On" : "Off"); printf("- boxes [%d]\n", m_iNumBodies); printf("- Friction. [%1.2f]\n", CBody::GetFriction()); printf("- Restitution[%1.2f]\n", CBody::GetRestitution()); printf("- Glue [%1.2f]\n", CBody::GetGlue()); printf("--------------------------------\n"); printf("\n"); }
void CGameGunHound::Loop() { //----------------------------------------- //ハウンドメイン //----------------------------------------- if( m_bResetOK ) { if( m_bResetPlease ) { m_bResetPlease = gxFalse; m_sEndSeq = -1; ChangeGameSeq( enMainSeqGameEnd ); } else if( CDashBoard::GetInstance()->IsMenuBar() ) { m_bPauseFlag = gxTrue; } else { m_bPauseFlag = gxFalse; } } switch( m_GameSeq ){ case enMainSeqInit: //----------------------------------------- //ゲーム初期化 //----------------------------------------- m_bBriefingRoot = gxTrue; m_bResetOK = gxFalse; viiDbg::log("ハウンドシーケンス:enMainSeqInit"); //SaveDataInit(); //GameConfigLoad(); m_bPauseFlag = gxFalse; ChangeGameSeq( enMainSeqStart ); break; case enMainSeqStart: //----------------------------------------- //スコア初期化 //----------------------------------------- m_bResetOK = gxFalse; viiDbg::log("ハウンドシーケンス:enMainSeqStart"); #ifdef _VII_DEBUG_ CDashBoard::GetInstance()->SetMenuDisable(gxFalse); CDashBoard::GetInstance()->SetLogo(gxFalse); CDashBoard::GetInstance()->SetWallPaper(gxFalse); ChangeGameSeq( enMainSeqRestart ); #else // ChangeGameSeq( enMainSeqGameOpeningDemo ); CDashBoard::GetInstance()->SetMenuDisable(gxFalse); CDashBoard::GetInstance()->SetLogo(gxFalse); CDashBoard::GetInstance()->SetWallPaper(gxFalse); ChangeGameSeq( enMainSeqGameTitle ); #endif break; case enMainSeqGameTitle: //----------------------------------------- //タイトルのシーケンス //----------------------------------------- UploadTexture(); m_bResetOK = gxFalse; ChangeGameSeq( enMainSeqRestart ); break; case enMainSeqRestart: //----------------------------------------- //リスタートのポイント //----------------------------------------- m_bResetOK = gxFalse; ResetClass(); #ifdef GX_DEBUG ChangeGameSeq( enMainSeqDebugMenu ); #else ChangeGameSeq( enMainSeqGameMainMenu ); #endif break; case enMainSeqGameMainMenu: //----------------------------------------- //メインメニューのシーケンス //----------------------------------------- m_bResetOK = gxTrue; CDashBoard::GetInstance()->SetMenuDisable(gxTrue); switch( MainMenu() ){ case enMenuSeqBack: case enMenuSeqNext: g_StGameInfo.Reset(); if( m_sMainMenuSelected == CMainMenu::enMainMenuOpening ) { //オープニングへ ChangeGameSeq( enMainSeqGameOpeningDemo ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuDebug ) { //デバッグモードへ g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal; ChangeGameSeq( enMainSeqDebugMenu ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuEnding ) { //エンディング CDashBoard::GetInstance()->SetIcon( enIconNone ); ChangeGameSeq( enMainSeqGameEndingDemo ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuStart ) { //ゲームスタートへ CDashBoard::GetInstance()->SetIcon( enIconNone ); g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal; g_StGameInfo.m_bMessage = gxTrue; ChangeGameSeq( enMainSeqGameBriefing ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuTutorial ) { //チュートリアルスタートへ g_StGameInfo.m_bMusic = gxTrue; g_StGameInfo.m_bMessage = gxTrue; g_StGameInfo.m_bReplay = gxFalse; CDashBoard::GetInstance()->SetIcon( enIconNone ); g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal; g_StGameInfo.PlayStage = enScenarioTutorial; StageSet(); g_StGameInfo.PlayArea = m_sSelectedStage; ChangeGameSeq( enMainSeqGameInit ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuMission ) { //ゲームスタートへ CDashBoard::GetInstance()->SetIcon( enIconNone ); g_StGameInfo.m_sGameMode = StGameInfo::enGameModeMission; g_StGameInfo.PlayStage = m_sSelectedStage;//enScenarioTutorial; g_StGameInfo.PlayArea = 0; StageSet(); ChangeGameSeq( enMainSeqGameInit ); } else if( m_sMainMenuSelected == CMainMenu::enMainMenuExit ) { //ゲーム終了 ExitGame(); } break; default: break; } break; case enMainSeqGameOpeningDemo: //----------------------------------------- //オープニングのシーケンス //----------------------------------------- m_bResetOK = gxFalse; if( AdvertiseDemo() ) { ChangeGameSeq( enMainSeqGameTitle ); } break; case enMainSeqDebugMenu: //----------------------------------------- //デバッグメニュー //----------------------------------------- m_bResetOK = gxTrue; switch( DebugMenu() ) { case enMenuSeqBack: ChangeGameSeq( enMainSeqGameMainMenu ); break; case enMenuSeqNext: // g_StGameInfo.Reset(); g_StGameInfo.m_bMessage = gxTrue; g_StGameInfo.m_bMusic = gxTrue; g_StGameInfo.m_bReplay = gxFalse; ChangeGameSeq( enMainSeqGameInit ); break; } break; case enMainSeqGameBriefing: g_StGameInfo.ContinueArea = 0; CCockpit::GetInstance()->SetHidden(); CDashBoard::GetInstance()->SetMenuDisable(gxFalse); m_bResetOK = gxTrue; if( m_pSetUp == NULL ) { //セットアップ画面を作る m_pSetUp = new CSetUp( -1 );//g_StGameInfo.PlayStage ); } if( BriefingMain() ) { //ステージ決定 StageSet(); m_bBriefingRoot = gxTrue; ChangeGameSeq( enMainSeqGameSetUp ); } CockpitControl(); break; case enMainSeqGameSetUp: CCockpit::GetInstance()->SetHidden(); m_bResetOK = gxTrue; if( m_pSetUp->IsEnd() ) { ChangeGameSeq( enMainSeqGameBefore ); } CockpitControl(); break; case enMainSeqGameBefore: //----------------------------------------- //ゲーム初期化 //----------------------------------------- CCockpit::GetInstance()->ReNew(); CCockpit::GetInstance()->SetHidden(); CockpitControl(); m_bResetOK = gxTrue; if( !m_pSetUp->IsWait() ) { //CCockpit::GetInstance()->Reset(); viiMus::StopBGM( enSoundBgm1 ); ChangeGameSeq( enMainSeqGameInit ); } break; case enMainSeqGameInit: //----------------------------------------- //ゲーム初期化 //----------------------------------------- CCockpit::GetInstance()->Destroy(); CCockpit::GetInstance()->SetHidden(); m_bResetOK = gxFalse; if( pGame ) delete pGame; pGame = new CGameManager(); GameInit(); pGame->init(); CockpitControl(); viiMus::Destroy(); ChangeGameSeq( enMainSeqGameMain ); break; case enMainSeqGameMain: //----------------------------------------- //ゲームメイン //----------------------------------------- CDashBoard::GetInstance()->SetMenuDisable(gxFalse); m_bResetOK = gxTrue; if( m_pSetUp ) { m_bResetOK = gxFalse; m_pSetUp->Draw(); if( m_pSetUp->GoDestroy() ) { //---------------------------------------------- //セットアップ終了 //---------------------------------------------- CCockpit::GetInstance()->Reset(); delete m_pSetUp; m_pSetUp = NULL; } } if( !m_bGameStart && pGame->IsGameStart() ) { m_bGameStart = gxTrue; } GameMain(); if( pGame->IsStageClear() ) { m_sEndSeq = pGame->GetNextSeq(); //m_sEndSeq = 1; //次へ ChangeGameSeq( enMainSeqGameEnd ); } else if( CCockpit::GetInstance()->IsGameOver() ) { m_sEndSeq = enClearSeqContinue; ChangeGameSeq( enMainSeqGameEnd ); } break; case enMainSeqGameEnd: //----------------------------------------- //ゲーム終了 //----------------------------------------- m_bResetOK = gxFalse; GameEnd(); if( pGame ) { delete pGame; pGame = NULL; } if( !m_bBriefingRoot ) { m_sEndSeq = 0; } CCockpit::GetInstance()->ReNew(); if( m_sMainMenuSelected == CMainMenu::enMainMenuMission || m_sMainMenuSelected == CMainMenu::enMainMenuTutorial) { //--------------------------------------- //ストーリーモード以外の時 //--------------------------------------- //スコアを加算する g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore ); //ミッションモードだった ChangeGameSeq( enMainSeqGameMainMenu ); //チュートリアルモードだった ChangeGameSeq( enMainSeqGameMainMenu ); } else if( m_sEndSeq == enClearSeqStageClear ) { #ifdef _TRIAL_VERSION_ //タイトルに戻る g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore ); ChangeGameSeq( enMainSeqRestart ); #else //ステージクリアだった g_StGameInfo.SetStageClear( g_StGameInfo.PlayStage ); switch( g_StGameInfo.PlayStage ){ case enScenarioJungle: g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission2 ); break; case enScenarioRiver: g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission3 ); break; case enScenarioMountain: g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission4 ); break; case enScenarioBase: g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission5 ); break; } ChangeGameSeq( enMainSeqGameBriefing ); #endif } else if( m_sEndSeq == enClearSeqContinue ) { //ステージ失敗だった(コンティニュールート) ChangeGameSeq( enMainSeqGameContinue ); } else if( m_sEndSeq == enClearSeqGameOver ) { //ゲームオーバーだった ChangeGameSeq( enMainSeqGameContinue ); } else if( m_sEndSeq == enClearSeqEnding ) { //エンディングだった g_StGameInfo.SetStageClear( g_StGameInfo.PlayStage ); g_CHoundSaveData.UpdateHighScore( MISSION_ALLOVER_BONUS ); Uint32 uScore = 0; //ゲームスコアを加算 m_stEndingBonus.uAllScore = g_StGameInfo.m_uAllScore; //オールオーバーボーナスをコンティニュー回数で割る m_stEndingBonus.uContinueBonus = MISSION_ALLOVER_BONUS/(g_StGameInfo.m_sContinueCnt+1); m_stEndingBonus.uContinueBonus = m_stEndingBonus.uContinueBonus/10; m_stEndingBonus.uContinueBonus = m_stEndingBonus.uContinueBonus*10; //Trueエンディングの場合場合ボーナス m_stEndingBonus.uTrueEndBonus = 0; if( g_StGameInfo.m_bTrueEnd ) { m_stEndingBonus.uTrueEndBonus = ENDING_TRUEVERSION_BONUS; g_CHoundSaveData.SetHiddenOpen( enHiddenItemViewEnding ); } //ノーコンティニューだった場合2倍ボーナス if( g_StGameInfo.m_sContinueCnt == 0 ) { m_stEndingBonus.uNoContinueBonus = m_stEndingBonus.uAllScore + m_stEndingBonus.uContinueBonus + m_stEndingBonus.uTrueEndBonus; } uScore = m_stEndingBonus.uAllScore; uScore += m_stEndingBonus.uContinueBonus; uScore += m_stEndingBonus.uTrueEndBonus; uScore += m_stEndingBonus.uNoContinueBonus; m_stEndingBonus.uTotalScore = uScore; //スコアを加算する g_CHoundSaveData.UpdateHighScore( uScore ); ChangeGameSeq( enMainSeqGameEndingDemo ); } else { //リセットだった /* if( m_bGameStart && m_sMainMenuSelected == CMainMenu::enMainMenuStart ) { m_sResetCount = 120; ChangeGameSeq( enMainSeqResetInGame ); } else { ChangeGameSeq( enMainSeqRestart ); } */ ChangeGameSeq( enMainSeqRestart ); } break; case enMainSeqGameContinue: //----------------------------------------- //コンティニュー //----------------------------------------- m_bResetOK = gxTrue; m_bGameStart = gxFalse; switch( ContinueScreen() ){ case enMenuSeqNext: { //タイトルに戻る g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore ); ChangeGameSeq( enMainSeqRestart ); } break; case enMenuSeqBack: { //コンティニューする // Sint32 sMem = g_StGameInfo.PlayArea; // StageSet(); //スコアをリセットする /* g_StGameInfo.m_uAllScore = (g_StGameInfo.m_uAllScore/2); g_StGameInfo.m_uAllScore -= g_StGameInfo.m_uAllScore%10;; */ //スコア更新 g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore ); g_StGameInfo.m_uAllScore = 0;//(g_StGameInfo.m_uAllScore/2); g_StGameInfo.m_uStageScore = g_StGameInfo.m_uAllScore; if( g_StGameInfo.m_sContinueCnt < 99 ) g_StGameInfo.m_sContinueCnt ++; g_StGameInfo.ContinueArea = g_StGameInfo.PlayArea; ChangeGameSeq( enMainSeqGameInit ); } break; default: break; } break; case enMainSeqGameEndingDemo: //----------------------------------------- //ゲーム終了 //----------------------------------------- m_bResetOK = gxTrue; m_bGameStart = gxFalse; CCockpit::GetInstance()->SetHidden(); CDashBoard::GetInstance()->SetMenuDisable(gxFalse); if( EndingDemo() ) { ChangeGameSeq( enMainSeqRestart ); } break; case enMainSeqResetInGame: if( m_sResetCount > 0 ) { m_sResetCount --; } else { g_StGameInfo.m_uAllScore = 0; g_StGameInfo.m_uStageScore = 0; g_StGameInfo.ContinueArea = g_StGameInfo.PlayArea; CCockpit::GetInstance()->ReNew(); ChangeGameSeq( enMainSeqGameInit ); } break; default: break; } viiMus::GetInstance()->Action(); CFadeManager::GetInstance()->action(); }
int main(void) { int i,j,k,x,y; //byte bi,bj; //byte cursize=1; //int cursorx=0,cursory=0; //byte spritecont=10,spritecont2=10+16; //byte sprconmeno,sprconpiu; //byte sprconmeno2,sprconpiu2; //byte terrancont=0,solidcont=0; //bool speed=false; //bool print=false,toggleprint=false; //bool moved=false,pushed=false; int nlevel; BITMAP *buffer; // Double-buffering BITMAP *textures; // Immagine globale delle texture BITMAP *sprites[256]; // Array degli sprite //RGB color[256]; //char nomefile[30],errmess[20]; //FILE *fp; T_Map mappa; strcpy(errmess,""); // inizializzo la stringa if(!mappa.InitLevel()){ strcpy(errmess,"Impossibile allocare la mappa"); exit(0); } /////////// INPUT NOME FILE DELLA MAPPA /////////////////////// printf("\n\t Inserta il nome del file della mappa(senza est.) : "); gets(nomefile); strcat(nomefile,".map"); ///////////////////////////////////////////////////////////////// if(!mappa.SetMapFile){ printf("\n\t File non trovato"); } nlevel=mappa.RetNLevel(); printf("\n\t Numero attuale di livelli: %d",nlevel); printf("\n\t Inserta il numero di livelli da creare nella mappa:"); printf("\n\t (0 per non aggiungerne)"); scanf("%d",&i); if(i>0){ nlevel+=i; mappa.SetNLevel(nlevel); mappa.AllocMap(); } GameInit(); textures=create_bitmap(128,128); mappa.SetTextureFile("D:\\DJGPP\\Game01\\IndexTxt.txt"); /////// Gestione delle texture... s�, lo so, lo so che sono tile for(y=0,i=0;y<16&&i<256;y++){ for(x=0;x<16&&i<256;x++,i++){ sprites[i]=create_sub_bitmap(textures,x*UNITX, y*UNITY,UNITX,UNITY); } } /////////// INIZIALIZZAZIONE MATRICE DELLA FINESTRELLA ///// for(i=0;i<WIMGY;i++){ for(j=0;j<WIMGX;j++){ miniwmask[i][j]=0; } } ////// INIZIALIZZAZIONE MATRICE DELLA LISTA DELLE TILE///////////// for(i=0;i<2;i++){ for(j=0;j<20;j++){ spritemask1[i][j]=0; spritemask2[i][j]=0; } } ///////////////// BUFFER PER IL DOUBLE BUFFERING ////////////// buffer=create_bitmap(SCREEN_W,SCREEN_H); //show_mouse(buffer); clear_to_color(buffer,DESK_COL); //clear_to_color(lvldis,BACKG_COL); ////////////////////////////////////////////////////////////////// /////////////////////////// PUTTAGGIO /////////////////////////// DrawMainWindow(); DrawMiniWindow(); DrawTileLists(); //show_mouse(buffer); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); //rectfill(screen,0,0,100,100,5); ////////////////////////////////////////////////////////////////// ////////////////// INPUT E CONTROLLI //////////////////////////// while(!key[KEY_ESC]){ if(key[KEY_RSHIFT]||key[KEY_LSHIFT]){ speed=true; }else{ speed=false; } if(key[KEY_P]){ cursize=2; moved=true; } if(key[KEY_O]){ cursize=1; moved=true; } if(key[KEY_SPACE]&&!pushed){ print=true; pushed=true; moved=true; } if(key[KEY_T]&&!pushed){ pushed=true; moved=true; if(toggleprint){ toggleprint=false; }else{ toggleprint=true; } } if(key[KEY_LEFT]&&cursorx&&!pushed){ if(!speed) pushed=true; cursorx--; if(cursize==2&&cursorx) cursorx--; relx=cursorx*MUNITX; moved=true; } if(key[KEY_RIGHT]&&cursorx<NSPRITEX-cursize&&!pushed){ if(!speed) pushed=true; cursorx++; if(cursize==2&&cursorx<NSPRITEX-cursize) cursorx++; relx=cursorx*MUNITX; moved=true; } if(key[KEY_UP]&&cursory&&!pushed){ if(!speed) pushed=true; cursory--; if(cursize==2&&cursory) cursory--; rely=cursory*MUNITY; moved=true; } if(key[KEY_DOWN]&&cursory<NSPRITEY-cursize&&!pushed){ if(!speed) pushed=true; cursory++; if(cursize==2&&cursory<NSPRITEY-cursize) cursory++; rely=cursory*MUNITY; moved=true; } if(key[KEY_PLUS_PAD]&&!pushed){ //if(!button[KEY_PLUS_PAD]){ pushed=true; BACKG_COL++; moved=true; //button[KEY_PLUS_PAD]=true; //} //}else{ // button[KEY_PLUS_PAD]=false; } if(key[KEY_Z]&&!pushed){ if(!speed) pushed=true; //spritecont--; //spritecont2--; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_X]&&!pushed){ if(!speed) pushed=true; //spritecont++; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_A]&&!pushed){ if(!speed) pushed=true; if(terrancont>0) terrancont--; else terrancont=MAX_TERR; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_S]&&!pushed){ if(!speed) pushed=true; terrancont++; if(terrancont>MAX_TERR) terrancont=0; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_Q]&&!pushed){ if(!speed) pushed=true; if(solidcont>0) solidcont--; else solidcont=MAX_SOLID; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_W]&&!pushed){ if(!speed) pushed=true; solidcont++; if(solidcont>MAX_SOLID) solidcont=0; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_F3]&&!pushed){ pushed=true; fp=fopen(nomefile,"rb"); if(fp!=NULL){ if(!mappa.LoadLevel(fp)) strcpy(errmess,"Unable to load"); fclose(fp); for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ livello[i][j].solid=mappa.RetSolid(k); livello[i][j].terran=mappa.RetTerran(k); } } } moved=true; } if(key[KEY_F2]&&!pushed){ pushed=true; /* for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ mappa.SetSolid(k,livello[i][j].solid); mappa.SetTerran(k,livello[i][j].terran); } } for(i=OVER_SPACE,k=0;i<OVER_SPACE+NSPRITEY;i++){ for(j=LEFT_SPACE;j<LEFT_SPACE+NSPRITEX;j++,k++){ mappa.SetSprite(k,livello[i][j].sprite); } } */ fp=fopen(nomefile,"wb"); //mappa.SaveLevel(fp); fclose(fp); } if(key[KEY_F7]&&!pushed){ pushed=true; for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ //fwrite(&livello[i][j],sizeof(level),1,fp); livello[i][j].solid=mappa.RetSolid(k); livello[i][j].terran=mappa.RetTerran(k); } } moved=true; } if(key[KEY_F5]&&!pushed){ pushed=true; for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ mappa.SetSolid(k,livello[i][j].solid); mappa.SetTerran(k,livello[i][j].terran); } } } if(key[KEY_ENTER]){ clear_to_color(buffer,0); for(i=OVER_SPACE,y=0;i<NSPRITEY-BOTTOM_SPACE;i++,y+=UNITY){ for(j=LEFT_SPACE,x=0;j<NSPRITEX-RIGHT_SPACE;j++,x+=UNITX){ blit(sprites[livello[i][j].sprite],buffer,0,0, x,y,UNITX,UNITY); } } vsync(); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); while(!key[KEY_BACKSPACE]); moved=true; } if(print||toggleprint){ livello[cursory][cursorx].sprite=spritecont; livello[cursory][cursorx].terran=terrancont; livello[cursory][cursorx].solid=solidcont; print=false; //stretch_blit(sprites[spritecont],lvldis,0,0,UNITX,UNITY, // cursorx*MUNITX,cursory*MUNITY,MUNITX,MUNITY); if(cursize>1){ livello[cursory][cursorx+1].sprite=spritecont+1; livello[cursory][cursorx+1].terran=terrancont; livello[cursory][cursorx+1].solid=solidcont; // stretch_blit(sprites[spritecont+1], // lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX, // cursory*MUNITY,MUNITX,MUNITY); livello[cursory+1][cursorx].sprite=spritecont2; livello[cursory+1][cursorx].terran=terrancont; livello[cursory+1][cursorx].solid=solidcont; // stretch_blit(sprites[spritecont2], // lvldis,0,0,UNITX,UNITY,cursorx*MUNITX, // (cursory+1)*MUNITY,MUNITX,MUNITY); livello[cursory+1][cursorx+1].sprite=spritecont2+1; livello[cursory+1][cursorx+1].terran=terrancont; livello[cursory+1][cursorx+1].solid=solidcont; // stretch_blit(sprites[spritecont2+1], // lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX, // (cursory+1)*MUNITY,MUNITX,MUNITY); } } if(moved){ clear_to_color(buffer,DESK_COL); // Puttaggio dello schema del livello : ex lvldis rectfill(buffer,0,0,XLAR,YLAR,BACKG_COL); //blit(lvldis,buffer,0,0,0,0,XLAR,YLAR); for(i=0,y=0;i<NSPRITEY;i++,y+=MUNITY){ for(j=0,x=0;j<NSPRITEX;j++,x+=MUNITX){ if(livello[i][j].sprite){ stretch_blit(sprites[livello[i][j].sprite], buffer,0,0,UNITX,UNITY,x,y,MUNITX,MUNITY); } } } // Rettangoli dello schema //rect(buffer,LEFT_SPACE*MUNITX,OVER_SPACE*MUNITY, // XLAR-(RIGHT_SPACE*MUNITX)-1,YLAR-(BOTTOM_SPACE*MUNITY)-1, // CONF_COL); rect(buffer,relx,rely,relx+(cursize*MUNITX-1), rely+(cursize*MUNITY-1),CURS_COL); // Disegno della finestra laterale // for(i=cursory-2,bi=0;i<cursory+3;i++,bi++){ for(j=cursorx-2,bj=0;j<cursorx+3;j++,bj++){ if(i<0||j<0){ windimg[bi][bj]=0; }else{ windimg[bi][bj]=livello[i][j].sprite; } } } for(i=0,y=0;i<WIMGY;i++,y+=UNITY){ for(j=0,x=SCREEN_W-(WIMGX*UNITX);j<WIMGX;j++,x+=UNITX){ //temp=; blit(sprites[windimg[i][j]],buffer,0,0,x,y,UNITX,UNITY); } } // Se � premuto 'toggleprint' ( che � un Pokemon? ) if(toggleprint){ rectfill(buffer,300,110,320,130,CURS_COL); }else{ rectfill(buffer,300,110,320,130,DESK_COL); } textprintf(buffer,font,250,60,255,"Sol : %d",solidcont); textprintf(buffer,font,250,70,255,"Terr: %d",terrancont); // Disegno elenco sprite if(spritecont>10){ sprconmeno=spritecont-10; }else{ sprconmeno=256-(10-spritecont); } if(spritecont<246){ sprconpiu=spritecont+10; }else{ sprconpiu=10-(256-spritecont); } if(spritecont2>10){ sprconmeno2=spritecont2-10; }else{ sprconmeno2=256-(10-spritecont2); } if(spritecont2<246){ sprconpiu2=spritecont2+10; }else{ sprconpiu2=10-(256-spritecont2); } for(bi=sprconmeno,bj=sprconmeno2,x=0;bi!=sprconpiu;bi++,bj++,x+=BIGUNITX){ stretch_blit(sprites[bi],buffer,0,0,UNITX,UNITY,x, 200,BIGUNITX,BIGUNITY); if(cursize>1){ stretch_blit(sprites[bj],buffer,0,0, UNITX,UNITY,x,216,BIGUNITX,BIGUNITY); } } rect(buffer,160,199,160+(cursize*BIGUNITX), 200+(cursize*BIGUNITY),CURS_COL); moved=false; } if(pushed){ pushed=false; for(i=0;i<128;i++){ if(key[i]){ pushed=true; break; } } } show_mouse(buffer); vsync(); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); show_mouse(NULL); } /// Distruzione Bitmap for(i=0;i<256;i++){ destroy_bitmap(sprites[i]); //destroy_bitmap(texture[1][i]); } destroy_bitmap(textures); //destroy_bitmap(lvldis); destroy_bitmap(buffer); readkey(); GameExit(); printf("Programmed with DJGPP RHIDE Allegro"); puts(errmess); getch(); return 0; }
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd ) { MSG msg; WNDCLASSEX ex; int argc; char cmdline[512]; const char* argv[32]; char* tok; // Convert command line into C-style argc & argv. strcpy( cmdline, lpcmdline ); argv[0] = "cylindrix"; argc = 1; tok = strtok( cmdline, " \t" ); while ( tok ) { argv[argc++] = tok; tok = strtok( 0, " \t" ); } ex.cbSize = sizeof(WNDCLASSEX); ex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC; ex.lpfnWndProc = WinProc; ex.cbClsExtra = 0; ex.cbWndExtra = 0; ex.hInstance = hinstance; ex.hIcon = LoadIcon(NULL, IDI_APPLICATION); ex.hCursor = LoadCursor(NULL, IDC_ARROW); ex.hbrBackground = NULL; ex.lpszMenuName = NULL; ex.lpszClassName = WNDCLASSNAME; ex.hIconSm = NULL; if ( !RegisterClassEx( &ex ) ) { MessageBox( NULL, "Failed to register the window class", "Window Reg Error", MB_OK ); return 1; } // Create the window CreateWnd( hinstance, screenw, screenh, SCRDEPTH, WINDOWED ); GameInit( argc, argv ); // The message loop while ( !quit ) { quit = GameLoop(); // clear keys pressed. memset( keysPressed, 0, 255 ); SwapBuffers( hdc ); if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) { if (msg.message == WM_QUIT) quit = TRUE; TranslateMessage( &msg ); DispatchMessage( &msg ); } } GameShutdown(); SysShutdown(); return msg.lParam; }
static LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hDC; static PAINTSTRUCT ps; int x,y; static HWND hWndButton; switch(message) { case LMSG_CREATE: hWndButton = CreateWindow("button", "start", WS_CONTROL | BS_PUSHBUTTON | WS_BORDER | WS_VISIBLE, 106, 210, 40 , 20, hWnd, (HMENU)ID_BUTTON, NULL, NULL); break; case LMSG_COMMAND: switch(HIWORD(wParam)){ case BN_CLICKED://×ÀÃæÍŒ±êµÄµã»÷ÊÂŒþŽŠÀí switch(LOWORD(wParam)){ case ID_BUTTON: if(!is_run){ SetTimer(hWnd,1,10); } GameInit(); break; default: break; } break; default: break; } break; case LMSG_PENDOWN://×ÀÃæµÄmouseÊÂŒþ CaptureMouse(hWnd,BYCLIENT); x=(int)wParam; y=(int)lParam; if(x<board.x+BOARD_LENGTH/2) board.x-=10; else board.x+=10; break; case LMSG_TIMER: TimerAction(hWnd); break; case LMSG_PENMOVE: break; case LMSG_PENUP://×ÀÃæµÄmouseÊÂŒþ DisCaptureMouse(); break; case LMSG_PAINT: { HGDIOBJ brush; HGDIOBJ pen; ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } if(is_run){ brush = CreateSolidBrush(RGB(23,43,133)); pen = CreatePen(PS_SOLID,1,RGB(230,0,255)); SelectObject(hDC,brush); SelectObject(hDC,pen); DeleteObject(brush); DeleteObject(pen); for(x=0;x<BRICK_NUM_IN_Y;x++) for(y=0;y<BRICK_NUM_IN_X;y++) { if(brick[x][y]==1) Rectangle(hDC,y*BRICK_LENGTH,x*BRICK_WIDTH,y*BRICK_LENGTH+BRICK_LENGTH,x*BRICK_WIDTH+BRICK_WIDTH); } Rectangle(hDC,board.x,board.y,board.x+BOARD_LENGTH,board.y+BOARD_WIDTH); Circle(hDC,ball.x,ball.y,BALL_RADIUS); } EndPaint(hWnd, &ps); break; } case LMSG_CLOSE: is_run=false; KillTimer(hWnd,1); PostQuitMessage(hWnd); break; case LMSG_DESTROY: is_run=false; KillTimer(hWnd,1); PostQuitMessage(hWnd);//ÓÃÀŽÍ˳öÏûϢѻ· break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return true; }
void GameOnKeyCallback(char keypressed) { switch(keypressed) { case '7': fCoF = Clamp(fCoF + 0.05f, 0.0f, 1.0f); break; case '4': fCoF = Clamp(fCoF - 0.05f, 0.0f, 1.0f); break; case '8': fCoR = Clamp(fCoR + 0.05f, 0.0f, 1.0f); break; case '5': fCoR = Clamp(fCoR - 0.05f, 0.0f, 1.0f); break; case '9': fCoS = Clamp(fCoS + 0.01f, 0.0f, 1.5f); break; case '6': fCoS = Clamp(fCoS - 0.01f, 0.0f, 1.5f); break; case 'p': case 'P': dbg_Pause = !dbg_Pause; break; case 'f': case 'F': dbg_UseFriction = !dbg_UseFriction; break; case 'i': case 'I': dbg_UseImpulses = !dbg_UseImpulses; break; case 'g': case 'G': dbg_UseGravity = !dbg_UseGravity; break; case '-': case '_': m_iNumBodies--; if (m_iNumBodies < eMinBodies) m_iNumBodies = eMinBodies; break; case 13: m_iNumBodies = eNumBodiesDefault; return; case '+': case '=': m_iNumBodies++; if (m_iNumBodies >= eNumBodies) m_iNumBodies = eNumBodies-1; break; case ' ': GameInit(); break; case 'h': case 'H': ikeypressedtimer = 0; default: printf("\n"); printf("--------------------------------\n"); printf("- Keys -\n"); printf("--------------------------------\n"); printf("- Pause On/Off : 'p'\n"); printf("- Gravity On/Off : 'g'\n"); printf("- Impulses On/Off : 'i'\n"); printf("- dyna.fric. On/Off : 'f'\n"); printf("- stat.fric. On/Off : 's'\n"); printf("- Add Box : '+'\n"); printf("- Remove box : '-'\n"); printf("- Reset box count : 'return'\n"); printf("- Reset simulation : 'spacebar'\n"); printf("- attract / repulse : 'mouse'\n"); printf("- Restitution : 'numpad 8-5'\n"); printf("- dynamic friction : 'numpad 7-4'\n"); printf("- static friction : 'numpad 9-6'\n"); printf("- help : 'h'\n"); printf("--------------------------------\n"); printf("\n"); break; } s_xContactMaterial.SetRestitution(fCoR); s_xContactMaterial.SetFriction (fCoF); s_xContactMaterial.SetStaticFriction(fCoS); printf("\n"); printf("--------------------------------\n"); printf("- Flags -\n"); printf("--------------------------------\n"); printf("- Gravity [%s]\n", dbg_UseGravity ? "On" : "Off"); printf("- Impulses [%s]\n", dbg_UseImpulses ? "On" : "Off"); printf("- Friction [%s]\n", dbg_UseFriction ? "On" : "Off"); printf("- boxes [%d]\n", m_iNumBodies); printf("- Restitution[%1.2f]\n", s_xContactMaterial.GetRestitution()); printf("- Stat.Fric. [%1.2f]\n", s_xContactMaterial.GetStaticFriction()); printf("- Dyn.Fric. [%1.2f]\n", s_xContactMaterial.GetFriction()); printf("--------------------------------\n"); printf("\n"); }
static int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { AllocConsole(); //create a console freopen( "conin$","r",stdin ); freopen( "conout$","w",stdout ); freopen( "conout$","w",stderr ); printf( "Program Started, console initialized\n" ); appInfo.appInstance = hInstance; const char WindowName[] = "Wet Clay"; appInfo.running = true; appInfo.isFullScreen = false; appInfo.mSecsPerFrame = 16; //60FPS appInfo.wc.cbSize = sizeof(WNDCLASSEX); appInfo.wc.style = CS_OWNDC; appInfo.wc.lpfnWndProc = WndProc; appInfo.wc.cbClsExtra = 0; appInfo.wc.cbWndExtra = 0; appInfo.wc.hInstance = appInfo.appInstance; appInfo.wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); appInfo.wc.hCursor = LoadCursor(NULL, IDC_ARROW); appInfo.wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); appInfo.wc.lpszMenuName = NULL; appInfo.wc.lpszClassName = WindowName; appInfo.wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if( !RegisterClassEx( &appInfo.wc ) ) { printf( "Failed to register class\n" ); appInfo.running = false; return -1; } // center position of the window appInfo.windowPosX = (GetSystemMetrics(SM_CXSCREEN) / 2) - (SCREEN_WIDTH / 2); appInfo.windowPosY = (GetSystemMetrics(SM_CYSCREEN) / 2) - (SCREEN_HEIGHT / 2); // set up the window for a windowed application by default //long wndStyle = WS_OVERLAPPEDWINDOW; if( appInfo.isFullScreen ) { appInfo.windowPosX = 0; appInfo.windowPosY = 0; //change resolution before the window is created //SysSetDisplayMode(width, height, SCRDEPTH); //TODO: implement } // at this point WM_CREATE message is sent/received // the WM_CREATE branch inside WinProc function will execute here appInfo.hwnd = CreateWindowEx(0, WindowName, "Wet Clay App", WS_BORDER, appInfo.windowPosX, appInfo.windowPosY, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, appInfo.appInstance, NULL); GetClientRect( appInfo.hwnd, appInfo.windowRect ); PIXELFORMATDESCRIPTOR pfd = { sizeof( PIXELFORMATDESCRIPTOR ), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette. 32, //Colordepth of the framebuffer. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, //Number of bits for the depthbuffer 0, //Number of bits for the stencilbuffer 0, //Number of Aux buffers in the framebuffer. 0, 0, 0, 0, 0 }; appInfo.deviceContext = GetDC( appInfo.hwnd ); int letWindowsChooseThisPixelFormat; letWindowsChooseThisPixelFormat = ChoosePixelFormat( appInfo.deviceContext, &pfd ); SetPixelFormat( appInfo.deviceContext, letWindowsChooseThisPixelFormat, &pfd ); appInfo.openglRenderContext = wglCreateContext( appInfo.deviceContext ); if( wglMakeCurrent ( appInfo.deviceContext, appInfo.openglRenderContext ) == false ) { printf( "Couldn't make GL context current.\n" ); return -1; } printf("Size of double:%d\n", sizeof( double ) ); glewInit(); MemorySlab gameSlab; gameSlab.slabSize = MEGABYTES( RESERVED_SPACE ); gameSlab.slabStart = VirtualAlloc( NULL, gameSlab.slabSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE ); assert( gameSlab.slabStart != NULL ); gameSlab.current = gameSlab.slabStart; SlabSubsection_Stack systemsMemory = CarveNewSubsection( &gameSlab, KILOBYTES( 12 ) ); SlabSubsection_Stack gameMemoryStack = CarveNewSubsection( &gameSlab, sizeof( GameMemory ) * 2 ); void* gMemPtr = AllocOnSubStack_Aligned( &gameMemoryStack, sizeof( GameMemory ) ); SoundSystemStorage* soundSystemStorage = Win32InitSound( appInfo.hwnd, 60, &systemsMemory ); RendererStorage* renderSystemStorage = InitRenderer( SCREEN_WIDTH, SCREEN_HEIGHT, &systemsMemory ); SetWindowLong( appInfo.hwnd, GWL_STYLE, 0 ); ShowWindow ( appInfo.hwnd, SW_SHOWNORMAL ); UpdateWindow( appInfo.hwnd ); BOOL canSupportHiResTimer = QueryPerformanceFrequency( &appInfo.timerResolution ); assert( canSupportHiResTimer ); GameInit( &gameSlab, gMemPtr, renderSystemStorage ); MSG Msg; do { while( PeekMessage( &Msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &Msg ); DispatchMessage( &Msg ); } static LARGE_INTEGER startTime; LARGE_INTEGER lastTime = startTime; QueryPerformanceCounter( &startTime ); //GAME LOOP if(appInfo.running) { XINPUT_STATE state; DWORD queryResult; memset( &state, 0, sizeof( XINPUT_STATE ) ) ; queryResult = XInputGetState( 0, &state ); if( queryResult == ERROR_SUCCESS ) { //Note: polling of the sticks results in the range not quite reaching 1.0 in the positive direction //it is like this to avoid branching on greater or less than 0.0 appInfo.controllerState.leftStick_x = ((float)state.Gamepad.sThumbLX / 32768.0f ); appInfo.controllerState.leftStick_y = ((float)state.Gamepad.sThumbLY / 32768.0f ); appInfo.controllerState.rightStick_x = ((float)state.Gamepad.sThumbRX / 32768.0f ); appInfo.controllerState.rightStick_y = ((float)state.Gamepad.sThumbRY / 32768.0f ); appInfo.controllerState.leftTrigger = ((float)state.Gamepad.bLeftTrigger / 255.0f ); appInfo.controllerState.rightTrigger = ((float)state.Gamepad.bRightTrigger / 255.0f ); appInfo.controllerState.leftBumper = state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER; appInfo.controllerState.rightBumper = state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER; appInfo.controllerState.button1 = state.Gamepad.wButtons & XINPUT_GAMEPAD_A; appInfo.controllerState.button2 = state.Gamepad.wButtons & XINPUT_GAMEPAD_B; appInfo.controllerState.button3 = state.Gamepad.wButtons & XINPUT_GAMEPAD_X; appInfo.controllerState.button4 = state.Gamepad.wButtons & XINPUT_GAMEPAD_Y; appInfo.controllerState.specialButtonLeft = state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK; appInfo.controllerState.specialButtonRight = state.Gamepad.wButtons & XINPUT_GAMEPAD_START; } else { appInfo.controllerState = { }; } LARGE_INTEGER elapsedTime; elapsedTime.QuadPart = startTime.QuadPart - lastTime.QuadPart; elapsedTime.QuadPart *= 1000; elapsedTime.QuadPart /= appInfo.timerResolution.QuadPart; appInfo.running = Update( gMemPtr, (float)elapsedTime.QuadPart, &soundSystemStorage->srb, soundSystemStorage->activeSounds ); Render( gMemPtr, renderSystemStorage ); PushAudioToSoundCard( soundSystemStorage ); SwapBuffers( appInfo.deviceContext ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } LARGE_INTEGER endTime, computeTime; QueryPerformanceCounter( &endTime ); computeTime.QuadPart = endTime.QuadPart - startTime.QuadPart; computeTime.QuadPart *= 1000; computeTime.QuadPart /= appInfo.timerResolution.QuadPart; if( computeTime.QuadPart <= appInfo.mSecsPerFrame ) { Sleep(appInfo.mSecsPerFrame - computeTime.QuadPart ); } else { printf("Didn't sleep, compute was %ld\n", computeTime.QuadPart ); } } while( appInfo.running ); FreeConsole(); return Msg.wParam; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { // Window WNDCLASSEX wc = { sizeof(wc) }; wc.lpszClassName = L"MainWnd"; wc.lpfnWndProc = MainWndProc; wc.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_LD24)); wc.hCursor = LoadCursor(0, MAKEINTRESOURCE(IDC_ARROW)); RegisterClassEx(&wc); DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU; DWORD styleEx = WS_EX_WINDOWEDGE; RECT rcWin = { 0, 0, kWinWidth * 4, kWinHeight * 4 }; AdjustWindowRectEx(&rcWin, style, FALSE, styleEx); OffsetRect(&rcWin, 100, 100); gMainWnd = CreateWindowEx(styleEx, wc.lpszClassName, L"LD24 - Super Conga Kat", style, rcWin.left, rcWin.top, rcWin.right - rcWin.left, rcWin.bottom - rcWin.top, 0, 0, 0, 0); ShowWindow(gMainWnd, SW_SHOWNORMAL); // Graphics if ((gD3d = Direct3DCreate9(D3D_SDK_VERSION)) == 0) { Panic("D3DCreate failed - do you have D3D9 installed?"); } D3DPRESENT_PARAMETERS pp = { }; pp.Windowed = TRUE; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.BackBufferWidth = kWinWidth; pp.BackBufferHeight = kWinHeight; pp.BackBufferFormat = D3DFMT_A8R8G8B8; pp.hDeviceWindow = gMainWnd; pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; if (FAILED(gD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, gMainWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &gDevice))) { Panic("D3D CreateDevice failed - do you have D3D9 installed?"); } D3DVIEWPORT9 vp; vp.Width = kWinWidth; vp.Height = kWinHeight; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; vp.X = 0; vp.Y = 0; gDevice->SetViewport(&vp); gpu::Init(); // Audio SoundInit(); // Keys int locKeyW = MapVirtualKey(0x11, MAPVK_VSC_TO_VK); int locKeyS = MapVirtualKey(0x1F, MAPVK_VSC_TO_VK); int locKeyA = MapVirtualKey(0x1E, MAPVK_VSC_TO_VK); int locKeyD = MapVirtualKey(0x20, MAPVK_VSC_TO_VK); int locKeyZ = MapVirtualKey(0x2C, MAPVK_VSC_TO_VK); // Main void RenderInit(); RenderInit(); void GameInit(); GameInit(); for(;;) { MSG msg; if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (gDevice) { gDevice->BeginScene(); void RenderPreUpdate(); RenderPreUpdate(); gKeyUp = gHasFocus && (((GetAsyncKeyState(VK_UP) & 0x8000) != 0) || ((GetAsyncKeyState(locKeyW) & 0x8000) != 0)); gKeyDown = gHasFocus && (((GetAsyncKeyState(VK_DOWN) & 0x8000) != 0) || ((GetAsyncKeyState(locKeyS) & 0x8000) != 0)); gKeyLeft = gHasFocus && (((GetAsyncKeyState(VK_LEFT) & 0x8000) != 0) || ((GetAsyncKeyState(locKeyA) & 0x8000) != 0)); gKeyRight = gHasFocus && (((GetAsyncKeyState(VK_RIGHT) & 0x8000) != 0) || ((GetAsyncKeyState(locKeyD) & 0x8000) != 0)); gKeyFire = gHasFocus && (((GetAsyncKeyState(VK_SPACE) & 0x8000) != 0) || ((GetAsyncKeyState(VK_RETURN) & 0x8000) != 0) || ((GetAsyncKeyState(locKeyZ) & 0x8000) != 0)); void GameUpdate(); GameUpdate(); void RenderGame(); RenderGame(); gDevice->EndScene(); gDevice->Present(0, 0, 0, 0); } Sleep(gHasFocus ? 0 : 250); } } gDevice->SetVertexDeclaration(0); gDevice->SetVertexShader(0); gDevice->SetPixelShader(0); gDevice->SetTexture(0, 0); SoundShutdown(); void RenderShutdown(); RenderShutdown(); gDevice->Release(); gD3d->Release(); DestroyWindow(gMainWnd); return 0; }
//----------------------------------------------------- // resets the world with random data //----------------------------------------------------- void Init() { GameInit(); }
int main( int argc, char* argv[] ) { if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) return -1; if( TTF_Init() < 0 ) return -1; SDL_Window* window = SDL_CreateWindow( WINDOW_TITLE, WINDOW_X, WINDOW_Y, WINDOW_W, WINDOW_H, SDL_WINDOW_OPENGL ); if( window ) { SDL_GLContext context = SDL_GL_CreateContext( window ); if( context ) { glewExperimental = GL_TRUE; if( glewInit() != GLEW_OK ) return -1; Memory memory; memory.size = GAME_MEMORY_POOL; memory.pointer = malloc( memory.size ); Input newInput = {}, oldInput = {}; const real64_t dt = GAME_DT; real64_t accumulator = 0.0; uint32_t ticks = SDL_GetTicks(); bool32_t running = GameInit( &memory ); while( running ) { uint32_t curTicks = SDL_GetTicks(); uint32_t frametime = curTicks - ticks; ticks = curTicks; accumulator += (real64_t)frametime / 1000.0; while( accumulator > dt ) { oldInput = newInput; SDL_Event e; while( SDL_PollEvent( &e ) ) { if( e.type == SDL_QUIT ) running = false; else if( e.type == SDL_KEYDOWN ) { if( e.key.keysym.sym == SDLK_ESCAPE ) running = false; else if( e.key.keysym.sym == SDLK_SPACE ) newInput.keys[KEY_SPACE] = true; else if( e.key.keysym.sym == SDLK_RETURN ) newInput.keys[KEY_ENTER] = true; } else if( e.type == SDL_KEYUP ) { if( e.key.keysym.sym == SDLK_SPACE ) newInput.keys[KEY_SPACE] = false; else if( e.key.keysym.sym == SDLK_RETURN ) newInput.keys[KEY_ENTER] = false; } else if( e.type == SDL_MOUSEBUTTONDOWN ) { if( e.button.button == SDL_BUTTON_LEFT ) newInput.buttons[BUTTON_LEFT] = true; else if( e.button.button == SDL_BUTTON_RIGHT ) newInput.buttons[BUTTON_RIGHT] = true; } else if( e.type == SDL_MOUSEBUTTONUP ) { if( e.button.button == SDL_BUTTON_LEFT ) newInput.buttons[BUTTON_LEFT] = false; else if( e.button.button == SDL_BUTTON_RIGHT ) newInput.buttons[BUTTON_RIGHT] = false; } else if( e.type == SDL_MOUSEMOTION ) { newInput.mousePosition.x = e.motion.x; newInput.mousePosition.y = e.motion.y; newInput.mouseDelta.x = e.motion.xrel; newInput.mouseDelta.y = e.motion.yrel; } } if( !GameUpdate( &memory, &newInput, &oldInput, dt ) ) running = false; accumulator -= dt; } GameRender( &memory ); SDL_GL_SwapWindow( window ); } } SDL_GL_DeleteContext( context ); } TTF_Quit(); SDL_DestroyWindow( window ); SDL_Quit(); return 0; }