示例#1
0
//-----------------------------------------------------
// displays the objects
//-----------------------------------------------------
void Display()
{
	//--------------------------------------------------------------------------
	// render stuff
	//--------------------------------------------------------------------------
	glClearColor(0.2f, 0.2f, 0.2f, 0.2f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	float aspect = 	width / (float) height;


	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, dbg_world_size * aspect, 0, dbg_world_size, -100, 100);
	
	//-----------------------------------------------------------------
	// Setup the model view matrix
	//-----------------------------------------------------------------
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	float fx = (       (mouse_x / (float) width )) * dbg_world_size * aspect;
	float fy = (1.0f - (mouse_y / (float) height)) * dbg_world_size;

	GameMouse(fx, fy, mouse_b);

	GameUpdate(1.0f / 60.0f);
	
	GameRender();

	glutSwapBuffers();
}
示例#2
0
// Update method
bool CGameManager::Update( CD3DManager* d3dManager, float updateTime )
{
	if( m_GameState == FrontEnd )
	{
		return FrontEndUpdate( d3dManager, updateTime );
	}
	else if( m_GameState == Game )
	{
		if( KeyHit( Key_Escape ) )
		{
			if( m_GUI->GetState() != GUIRaceStarting )
			{				
				m_Pause = !m_Pause;

				ShowCursor( m_Pause );

				if( m_GUI->GetState() != GUIPaused )
					m_GUI->SetState( GUIPaused );		
				else
					m_GUI->SetState( GUIRacing );
			}
		}

		if( !m_Pause )
			return GameUpdate( d3dManager, updateTime );
		else
			return GamePaused( d3dManager, updateTime  );
	}

	return true;
}
示例#3
0
Bool GApp::Update()
{
	//	flagged to quit
	if ( m_AppFlags & GAppFlags::QuitApp )
		return FALSE;

	//	update update counter
	m_Stats.OnNewFrame();
	GIncCounter(UpdateCounter,1);

	//	update inputs
	g_Keyboard.Update();
	g_Mouse.Update();
	g_Pad.Update();

	//	update stats
	m_Stats.Update();


	//	update game
	if ( !GameUpdate() )
		return FALSE;

	//	draw
	m_Display.Draw();

	return TRUE;
}
示例#4
0
// main function
int _tmain(int argc, _TCHAR* argv[])
{  

	PlayerSetup(Juego);

	if(GameInit(Juego) <0)
		return -1;

	while(Juego->EstadoActual != Terminado)
	{
		
		if(GameUpdate(Juego) < 0)
			Juego->EstadoActual = EnError;

		if(GameRender(Juego) < 0)
			Juego->EstadoActual = EnError;
		Sleep(16);
	}

	
	GameDeInit(Juego);


	return 0;
}
示例#5
0
文件: main.cpp 项目: wakqaz4/MyGame
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
	WNDCLASS wndClass;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
	wndClass.hIcon = (HICON)LoadImage(nullptr, _T("icon.ico"), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
	wndClass.hInstance = hInstance;
	wndClass.lpfnWndProc = WndProc;
	wndClass.lpszClassName = _T("CName");
	wndClass.lpszMenuName = nullptr;
	wndClass.style = CS_VREDRAW | CS_HREDRAW;

	if (!RegisterClass(&wndClass))
	{
		return -1;
	}

	HWND hwnd = CreateWindow(_T("CName"), _T("AnimMovingRight"), WS_OVERLAPPEDWINDOW,
		0, 0, 800, 600,
		nullptr, nullptr, hInstance, nullptr);

	ShowWindow(hwnd, nShowCmd);
	UpdateWindow(hwnd);

	if (!GameInit(hwnd))
	{
		MessageBox(nullptr, _T("Init Game Failed!"), _T("Error!"), MB_OK);
		return -1;
	}
	PlaySound(_T("NOIR3.wav"), nullptr, SND_FILENAME | SND_ASYNC | SND_LOOP);
	MSG msg{ 0 };
	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			gCurrTickCount = GetTickCount();
			if (gCurrTickCount - gPrevTickCount >= 50.3f)
			{
				GameUpdate(hwnd, gCurrTickCount - gPrevTickCount);
				gPrevTickCount = gCurrTickCount;

			}
		}
	}
	UnregisterClass(_T("CName"), hInstance);
	exit(0);
	return 0;
}
示例#6
0
文件: main.cpp 项目: wakqaz4/MyGame
bool GameInit(HWND hwnd)
{
	gHDC = GetDC(hwnd);
	gMemDC = CreateCompatibleDC(gHDC);
	gBufDC = CreateCompatibleDC(gHDC);
	HBITMAP bmp = CreateCompatibleBitmap(gHDC, 800, 600);
	SelectObject(gMemDC, bmp);

	gBmpBackground = (HBITMAP)LoadImage(nullptr, _T("bg.bmp"), IMAGE_BITMAP, 800, 600, LR_LOADFROMFILE);
	gBmpSprite = (HBITMAP)LoadImage(nullptr, _T("snow.bmp"), IMAGE_BITMAP, 30, 30, LR_LOADFROMFILE);

	GetClientRect(hwnd, &gRect);
	srand(unsigned (time(NULL)));
	GameUpdate(hwnd, 0);

	return true;
}
示例#7
0
//-----------------------------------------------------------------------------------------------
void Game::Update( float deltaSeconds, Keyboard& keyInput, const Mouse& mouseInput, const Xbox::Controller& xboxInput )
{
	Debug::UpdateDrawings( deltaSeconds );

	if( keyInput.KeyIsPressed( Keyboard::GRAVE ) )
		m_consoleVisible = !m_consoleVisible;

	if( m_consoleVisible )
	{
		UpdateConsoleInput( deltaSeconds, keyInput, mouseInput );
		m_console->Update( deltaSeconds );
	}
	else
	{
		InputUpdate( deltaSeconds, keyInput, mouseInput, xboxInput );
	}

	GameUpdate( deltaSeconds );
}
示例#8
0
void	ClientRun()
{
	timer t;
	float32 now = 0;
	float32 last = 0;

	float delay = 0.0;
	while (true)
	{
		if(bExist)
			break;
		SSleep(10);
		now		= (float32)t.elapsed();
		delay	= now - last;
		gGameCommond.Command(delay);
		GameUpdate(delay);
		ClientPlayerMgr::Instance()->Update();
		last = now;
	}

}
示例#9
0
//-----------------------------------------------------
// Update the objects
//-----------------------------------------------------
void Update(float dt)
{
	GameUpdate(dt);
}
示例#10
0
文件: main.cpp 项目: ezliang/CS3113
int main(int argc, char *argv[])
{
	
	SDL_Event event;
	bool done = false;
	float lastFrameTicks = 0.0f;
	float ball_angle = 0.0f;
	srand(time(NULL));

	Matrix projectionMatrix;
	Matrix viewMatrix;
	Setup(&displayWindow, &projectionMatrix);

	std::vector<Entity*> entities;
	std::vector<DrawSpriteText> text;
	std::vector<Entity*> enemy_bullets;
	std::vector<DrawSpriteText> title_text;

	GLuint space_sheet = LoadTexture("sheet.png", GL_RGBA);
	GLuint fontsheet = LoadTexture("font1.png", GL_RGBA);
	GLuint bg = LoadTexture("darkPurple.png", GL_RGB);

	Entity* newEnt;
	for (size_t x = 0; x < 11; ++x){
		for (size_t y = 0; y < 4; ++y){
			
			switch (y){
			case 0:
				newEnt = new Entity(space_sheet, 1024.0f, 423.0f, 728.0f, 93.0f, 84.0f, 0.5f);

				break;
			case 1:
				newEnt = new Entity(space_sheet, 1024.0f, 425.0f, 468.0f, 93.0f, 84.0f, 0.5f);
				break;
			default:
				newEnt = new Entity(space_sheet, 1024.0f, 425.0f, 384.0f, 93.0f, 84.0f, 0.5f);
				break;
			}
			
			newEnt->x = (-6.22 + newEnt->width/2 * 11) + (x * (newEnt->width + 0.15));
			newEnt->y = ((3.5 - newEnt->height * 2) - newEnt->height/2 ) - (y * (newEnt->height + 0.2));
			entities.push_back(newEnt);
		}
	}

	for (size_t i = 0; i < entities.size(); ++i){
		points.push_back(std::make_pair(entities[i]->x, entities[i]->y));
	}
	
	Entity player(space_sheet, 1024.0f, 211.0f, 941.0f, 99.0f, 75.0f, 0.5);
	player.y = -3.5 + 0.1 + player.height/2;

	Entity player_bullet(space_sheet, 1024.0f, 843.0f, 789.0f, 13.0f, 57.0f, 0.5);
	player_bullet.x = 7.0;
	
	for (size_t i = 0; i < ENEMY_BULLETS; ++i){
		newEnt = new Entity(space_sheet, 1024.0f, 843.0f, 789.0f, 13.0f, 57.0f, 0.5);
		newEnt->x = 7.0;
		enemy_bullets.push_back(newEnt);
	}

	Entity explosion(space_sheet, 1024.0f, 737.0f, 613.0f, 37.0f, 37.0f, 0.5);
	explosion.x = 7.0;

	DrawSpriteText Life(fontsheet, "LIFE", 0.5, 0);
	Life.y = 3.0f;
	Life.x = 1.0f;
	text.push_back(Life);

	for (size_t i = 0; i < MAX_LIVES; ++i){
		newEnt = new Entity(space_sheet, 1024.0f, 211.0f, 941.0f, 99.0f, 75.0f, 0.5);
		newEnt->y = 3.0f;
		newEnt->x = 1.2f + newEnt->width*3 + ((newEnt->width + 0.1)*i);
		entities.push_back(newEnt);
	}

	DrawSpriteText Title(fontsheet, "Press Enter to Start", 0.5, 0);
	Title.x = -4.7;
	title_text.push_back(Title);

	ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");

	glUseProgram(program.programID);
	
	while (!done) {
		
		float ticks = (float)SDL_GetTicks() / 1000.0f;
		float elapsed = ticks - lastFrameTicks;
		lastFrameTicks = ticks;
		

		float fixedElapsed = elapsed;
		program.setProjectionMatrix(projectionMatrix);
		program.setViewMatrix(viewMatrix);

		switch (state){
		case(STATE_TITLE) :
			TitleProcessEvents(&event,&done);
			TitleRender(&program,title_text);
			break;
		case(STATE_GAME):
			GameProcessEvents(&event, &done, elapsed, entities, player_bullet, player);
			if (fixedElapsed > FIXED_TIMESTEP * MAX_TIMESTEPS){
				fixedElapsed = FIXED_TIMESTEP * MAX_TIMESTEPS;
			}
			while (fixedElapsed >= FIXED_TIMESTEP){
				fixedElapsed -= FIXED_TIMESTEP;
				GameUpdate(FIXED_TIMESTEP, entities, enemy_bullets, player_bullet, explosion, player);
			}
			GameUpdate(fixedElapsed, entities, enemy_bullets, player_bullet, explosion, player);
			GameRender(&program, entities, enemy_bullets, text, player_bullet, explosion, player);
			break;
		}
		
	}
	for (size_t i = 0; i < entities.size(); ++i){
		delete entities[i];
	}

	SDL_Quit();
	return 0;
}
示例#11
0
void Game::Create()
{
	// Set the platform
	ApConfig::SetPlatform( ApPlatform_WinGL );
	ApConfig::SetDevice( ApDevice_WIN );

	GLFWvidmode dvm;

	// Initialise GLFW
	if(!glfwInit())
	{
		fprintf(stderr, "Failed to initialize GLFW\n");
		exit(EXIT_FAILURE);
	}

	glfwGetDesktopMode(&dvm);

	project->Init();

	// Frame counter and window settings variables
	int frame = 0;
	int redBits = 8, greenBits = 8, blueBits = 8;
	int alphaBits = 8, depthBits = 24, stencilBits = 8;
	m_width = RsUtil::GetWidth();
	m_height = RsUtil::GetHeight();

	glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);

	// Create a window
	if(!glfwOpenWindow(m_width, m_height, redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, GLFW_WINDOW))
	{
		fprintf(stderr, "Failed to open GLFW window\n");

		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	// Set listeners
	glfwSetWindowCloseCallback(windowCloseListener);

	int width, height;
	GetDesktopResolution(width, height);
	glfwSetWindowPos((width / 2) - (RsUtil::GetWidth() / 2), (height / 2) - (RsUtil::GetHeight() / 2));

	// Cache the window handle
	int handle = glfwGetWindowParam( -1 );

	// Create the game mouse
	m_gameMouse.Setup( (HWND)handle );
	m_gameMouse.CreateOnDevice();

	// Create the render system
	RsImpl::pInstance()->Create();

	SdSoundWinGL::CreateManager();

	BtTimeDX11::Init();

	//glfwOpenWindowHint( GLFW_REFRESH_RATE, 1.0f / 30.0f );

	glfwSetWindowTitle( ApConfig::GetTitle() );

	// Ensure we can capture the escape key being pressed below
	glfwEnable(GLFW_STICKY_KEYS);

	// Enable vertical sync (on cards that support it)
	glfwSwapInterval(1);

	// Hide the cursor
	glfwDisable(GLFW_MOUSE_CURSOR);

	project->Create();
	project->Reset();
	do
	{
		// Get window size (may be different than the requested size)
		glfwGetWindowSize(&m_width, &m_height);

		// Set the window size
		glViewport(0, 0, m_width, m_height);

		BtFloat dt = BtTime::GetTick();
		BtFloat elapsedTime = BtTime::GetElapsedTimeInSeconds();
		BtFloat deltaTime = elapsedTime - m_lastGameLogic;

		m_lastGameLogic = elapsedTime;

		// Add the excess
		m_frameRemainder += deltaTime;

		// Cap the frame
		m_frameRemainder = BtClamp(m_frameRemainder, (BtFloat)0, 1.0f);

		BtBool isExiting = BtFalse;

		//while( m_frameRemainder >= dt )
		{
			// Update the keys
			input.Update();

			// Update the game logic
			GameUpdate();

			// Remove the dt from the frame remainder
			m_frameRemainder -= dt;
		}

		if((isClosing == BtFalse) && (project->IsClosing() == BtFalse))
		{
			// Render
			project->Render();

			// Render
			RsImpl::pInstance()->Render();
		}

		// Swap buffers
		glfwSwapBuffers();
	} // Check if the ESC key was pressed or the window was closed
	while(project->IsClosed() == BtFalse);

	// Destroy the renderer
	RsImpl::pInstance()->Destroy();

	// Destroy the sound
	SdSoundWinGL::DestroyManager();

	// Remove the game mouse
	m_gameMouse.RemoveFromDevice();

	// Destroy the project
	project->Destroy();

	// Close OpenGL window and terminate GLFW
	glfwTerminate();
}
示例#12
0
文件: Main.cpp 项目: quantumrain/LD24
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;
}
示例#13
0
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;
}