コード例 #1
0
//function that is repeatedly called to render the window
void renderWin1(int currentTime, int deltaTime)
{
	Matrix4 vpMatrix, viewMatrix, modelMatrix;
	handleInput(deltaTime);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	viewMatrix = camera1->getViewMatrix();
	vpMatrix = projectionMatrix * viewMatrix;
	Matrix4 orthographicMatrix = Matrix4::IDENTITY;
	orthographicMatrix = createOrthographicProjectionMatrix(win1.width, win1.height, -1, 1);
	char buffer[256];

	if (State == "Play"){
		checkEnemyCollision();
		skybox->render_self(projectionMatrix*viewMatrix, camera1->getPosition(), win1.zFar);
		levels[currLevel]->drawLevel(vpMatrix);
		time->setPosition(Vector3(0, -330, 0));

		if (Time >= 59){
			Time -= 59;
			TimeMin++;
		}
		
		if (Time >= 9.0f){
			sprintf(buffer, "Total time : %d:%0.0f", TimeMin, Time);
		}
		else{
			sprintf(buffer, "Total time : %d:0%0.0f", TimeMin, Time);
		}

		std::string timeM(buffer);
		time->render(orthographicMatrix, timeM);
		cylinder1.setPosition((camera1->getPosition()));
		cylinder1.render(vpMatrix);

		for (int i = 0; i < 30; i++){
			if (enemies[i]->getAlive())
				enemies[i]->render(vpMatrix);
			moveEnemies(i);
		}

		if (hasSavePoint){
			saveFlag->setPosition(savePoint);
			saveFlag->render(vpMatrix);
		}
		buffer[256];
		sprintf(buffer, "Stamina: %0.2f", Stamina);
		std::string message(buffer);
		Paused->setPosition(Vector3(-390, -330, 0));
		if (Stamina < 20){
			Paused->setColor(Color(1, 0, 0, 1));
		}
		else if (Stamina < 60){
			Paused->setColor(Color(1, 1, 0, 1));
		}
		else{
			Paused->setColor(Color(0, 1, 0, 1));
		}

		Paused->render(orthographicMatrix, message);
			
		checkNextLevel();
	} else if (State == "Menu") {
		notice->setColor(Color(1, 0, 1, 0));
		notice->setPosition(Vector3(-260, -180, 0));
		notice->render(orthographicMatrix, "ARROWS TO NAVIGATE SPACE TO SELECT");
		Title->render(orthographicMatrix, "Maze Adventures!");
		PlayBut->render(orthographicMatrix, "Play");
		
		if (MenOption == 0)
			PlayBut->setColor(Color(1, 1, 0, 1));
		else
			PlayBut->setColor(Color(1, 1, 1, 200));

		ControlsBut->render(orthographicMatrix, "Controls");
		if (MenOption == 1)
			ControlsBut->setColor(Color(1, 1, 0, 1));
		else
			ControlsBut->setColor(Color(1, 1, 1, 200));

		CreditsBut->render(orthographicMatrix, "Credits");
		if (MenOption == 2)
			CreditsBut->setColor(Color(1, 1, 0, 1));
		else
			CreditsBut->setColor(Color(1, 1, 1, 200));

		Exitbut->render(orthographicMatrix, "Exit");
		if (MenOption == 3)
			Exitbut->setColor(Color(1, 1, 0, 0.1f));
		else
			Exitbut->setColor(Color(1, 1, 1, 200));

		if (isPaused){
			Paused->setPosition(Vector3(-50, -150, 0));
			Paused->setColor(Color(1, 0, 0, 1));
			Paused->render(orthographicMatrix, "PAUSED");
			if (MenOption == 4)
				Restartbut->setColor(Color(1, 1, 0, 1));
			else
				Restartbut->setColor(Color(1, 1, 1, 200));
			Restartbut->render(orthographicMatrix, "Restart Level");

		}
	}
	else if (State == "Controls"){
		Back->setPosition(Vector3(-260, 200, 0));
		Back->render(orthographicMatrix, "BACK");
		Controls1->render(orthographicMatrix, "MOVE: W - Forward, S - Backward");
		Controls2->render(orthographicMatrix, "STRAFE: A - Left, D - Right");
		Controls3->render(orthographicMatrix, "LOOK/TURN: Mouse");
		Controls4->render(orthographicMatrix, "JUMP: Spacebar");
		Controls5->render(orthographicMatrix, "SPRINT: L-Shift");
		Controls6->render(orthographicMatrix, "PLACE SAVE: F - RETURN TO SAVE: G");
	}
	else if (State == "Credits"){
		Back->setPosition(Vector3(-260, 200, 0));
		Credits1->render(orthographicMatrix, "Maze Adventures Created By:");
		Credits2->render(orthographicMatrix, "Joel Scarfone & Alex Carlucci");
		Back->render(orthographicMatrix, "BACK");
	}
	else if (State == "Loading"){
		
		time->setPosition(Vector3(-50, -150, 0));
		sprintf(buffer, "Total time", Time);
		std::string timeM(buffer);
		//time->render(orthographicMatrix, timeM);
		char buffer[256];
		sprintf(buffer, "Level: %d", currLevel + 1);
		std::string message(buffer);
		

		Loading->render(orthographicMatrix, message);
		Back->setPosition(Vector3(-50, -150, 0));
		Back->render(orthographicMatrix, "Start");
	}
	else if (State == "Game_Finished"){
		Paused->setPosition(Vector3(-220, 120, 0));
		Paused->setColor(Color(0, 1, 0, 0));
		Paused->render(orthographicMatrix, "CONGRAGULATION YOU WON!");
		if (Time >= 59){
			Time -= 59;
			TimeMin++;
		}

		if (Time >= 9.0f){
			sprintf(buffer, "Total time: %d:%0.0f", TimeMin, Time);
		}
		else{
			sprintf(buffer, "Total time: %d:0%0.0f", TimeMin, Time);
		}

		std::string timeM(buffer);
		time->render(orthographicMatrix, timeM);
		time->setPosition(Vector3(-150, -150, 0));
	}
	glutSwapBuffers(); //works with GL_DOUBLE. use glFlush(); instead, if using GL_SINGLE
}
コード例 #2
0
ファイル: main.cpp プロジェクト: vincentlai97/SP1-12
void render()
{    
    // Clears the buffer with this colour attribute
    clearBuffer(0x00);

    // Set up sample colours, and output shadings
    const WORD colors[] =   {
	                        0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F,
	                        0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6
	                        };
	
    COORD c;

    // displays the framerate
    std::ostringstream ss;
    ss << std::fixed << std::setprecision(3);
    ss << 1.0 / deltaTime << "fps";
    c.X = ConsoleSize.X-9;
    c.Y = 0;
    writeToBuffer(c, ss.str());

    // displays the elapsed time
    ss.str("");
    ss << elapsedTime << "secs";
    c.X = 0;
	c.Y = ConsoleSize.Y - 1;
    writeToBuffer(c, ss.str(), 0x59);

	if (!levelStart)
		levelStart = initLevel();

	renderShip();
	moveBullets();
	checkBulletCollision(enemyArr, levelInfo.number);
	renderBullets();
	if (!spawnBufferCount && enemiesSpawned < levelInfo.number)
	{
		if (spawnEnemy(enemyArr, levelInfo.number))
		{
			spawnBufferCount += levelInfo.spawnBuffer;
			enemiesSpawned++;
		}
	}
	else if (spawnBufferCount) spawnBufferCount--;
	moveEnemy(enemyArr, levelInfo.number);
	checkBulletCollision(enemyArr, levelInfo.number);
	checkEnemyCollision(enemyArr, levelInfo.number);
	renderEnemy(enemyArr, levelInfo.number);
	if (levelInfo.bullets)
	{
		if (spawnEnemyBullet(enemyArr))
		{
				spawnBufferCount += bulletInfo.spawnBuffer;
		}
		moveEnemy(enemyBulletArr, bulletInfo.number);
		checkEnemyCollision(enemyBulletArr, bulletInfo.number);
		renderEnemy(enemyBulletArr, bulletInfo.number);
	}
	
	// Writes the buffer to the console, hence you will see what you have written
    flushBufferToConsole();

	if (enemiesSpawned == levelInfo.number) 
	{
		if (checkClear(enemyArr, levelInfo.number)) 
		{
			levelStart = false;
			enemiesSpawned = 0;
			spawnBufferCount = 0;
			delete[] enemyArr;
			delete[] enemyBulletArr;
			levelInfo.level = levelInfo.nextLevel;
		}
	}
}