Exemplo n.º 1
0
	void Update(const UniqueObjectCollection& graphicsObjects, const Screen& target)
	{
		target.Clear();

		for_each(graphicsObjects.begin(), graphicsObjects.end(),
			bind(&WorldObject::Draw, _1, boost::ref(target)));

		target.Update();
	}
Exemplo n.º 2
0
void ScreenManager::Update(float deltaTime)
{
	// make a copy of the mScreens instead of
	// directly working with the master list
	mScreensToUpdate.clear();

	for each (Screen* screen in mScreens)
		mScreensToUpdate.push_back(screen);

	// ensures that only the original topmost screen
	// handles input
	bool otherScreenHasFocus = false;

	// iterate through all screens
	while ( mScreensToUpdate.size() > 0)
	{
		// process and then pop the topmost screen
		// in the temporary screen list
		Screen* screen = mScreensToUpdate[mScreensToUpdate.size() - 1];
		mScreensToUpdate.erase(mScreensToUpdate.end()- 1);

		// update
		screen->Update( deltaTime );

		if ( screen->mScreenState == screen->SS_TRANSITION_ON ||
			 screen->mScreenState == screen->SS_ACTIVE )
		{	
			// handle input for the first active screen only
			if ( !otherScreenHasFocus )
			{
				screen->CheckForInput( deltaTime );
				otherScreenHasFocus = true;
			}
		}
	}
}
Exemplo n.º 3
0
int main()
{
	GLFWwindow* window = nullptr;
	if(!init(window))
	{
		system("pause");
		exit(0);
	}

	glClearColor(0.0, 0.0, 0.0, 0.0);

	//set up audio engine
	SoundSystemClass sounds;

	GLSLProgram shaders;
	//load shaders, compile and link	
	shaders.compileShaderFromFile("triangle.v.glsl", VERTEX);
	shaders.compileShaderFromFile("triangle.f.glsl", FRAGMENT);
	shaders.link();
	shaders.use();

	Screen* currentScreen;

	MainMenuScreen *mms = new MainMenuScreen(&sounds, &shaders);
	currentScreen = mms;
	
	//Text t(glm::vec3(0, 0, 0), glm::vec4(1.0, 0.0, 0.0, 1.0), 40, 40, "arial_0.png", "arial.fnt");

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	//create projection matrix
	glm::mat4 projectionMatrix = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f);
	double lastTime = glfwGetTime(), currentTime;

	while(!glfwWindowShouldClose(window) && currentScreen != nullptr)
	{
		//calculate delta time
		currentTime = glfwGetTime();
		double deltaTime = currentTime - lastTime;

		//draw
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		currentScreen->Draw();

		glfwSwapBuffers(window);
		
		//update
		Screen* next = currentScreen->Update(deltaTime);
		//if returned screen is null, pop current screen
		if(next != currentScreen)
		{
			delete currentScreen;
			currentScreen = next;
		}
		//else continue with current top of stack

		
		glfwPollEvents();
		lastTime = currentTime;
	}

	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}
Exemplo n.º 4
0
int MainProgram()
{
	Screen screen;

	if (screen.Init(0xFFFF00FF) == false)
	{
		std::cout << "Init went wrong" << endl;
		return 1;
	}

	int playerWidth, playerHeight, bulletWidth, bulletHeight;
	Uint32 *imageData = ReadBmp("P:\\My Documents\\Visual Studio 2013\\Projects\\SDLGame\\Debug\\firefox.bmp", playerWidth, playerHeight);
	Uint32 *bulletImage = ReadBmp("P:\\My Documents\\Visual Studio 2013\\Projects\\SDLGame\\Debug\\AimReticle3.bmp", bulletWidth, bulletHeight);
	int elapsed;
	
	float position[2] = { 0, 0 };
	{
		float bulletPos[2] = { 0, 0 };
		float bulletSize[2] = { bulletWidth, bulletHeight };
		Bullet bullet(bulletPos, bulletImage, );

	}

	while (true)
	{
		
		const Uint8* newKeyboardState = SDL_GetKeyboardState(NULL);
		
		if (screen.ProcessEvents() == false)
			break;

		ProcessKeyboard(newKeyboardState, screen);
		elapsed = SDL_GetTicks();

		for (int y = 0; y < screen.SCREEN_HEIGHT; ++y)
		{
			for (int x = 0; x < screen.SCREEN_WIDTH; ++x)
			{
				//screen.SetPixel(x, y, (sin(elapsed / 1000.0) + 1) * 127, sin(((elapsed / 1000.0 + 50) * 2) + 1) * 127, sin(((elapsed / 1000.0 + 120) * 3) + 1) * 127);
			}
		}

		if (imageData == nullptr)
			break;

		position[0] += velocity[0];
		position[1] += velocity[1];

		if (position[1] < 0)
		{
			position[1] = 0;
		}
		else if (position[1] + playerHeight > screen.SCREEN_HEIGHT)
		{
			position[1] = (float)(screen.SCREEN_HEIGHT - playerHeight);
		}
		if (position[0] < 0)
		{
			position[0] = 0;
		}
		else if (position[0] + playerWidth > screen.SCREEN_WIDTH)
		{
			position[0] = (float)(screen.SCREEN_WIDTH - playerWidth);
		}

		for (int y = 0; y < playerHeight; ++y)
		{
			for (int x = 0; x < playerWidth; ++x)
			{
				screen.SetPixel(x + (int)position[0], y + (int)position[1], imageData[(y * playerWidth) + x]);
			}
		}

		screen.Update();
	}
	delete[] imageData;
	screen.Close();
	return 0;
}