Compare commits
	
		
			2 Commits
		
	
	
		
			linux
			...
			affichage_
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 54e2f32aba | ||
|  | 90fdc8ed1b | 
| @@ -4,6 +4,24 @@ | |||||||
| #include "transformation.h" | #include "transformation.h" | ||||||
| #include "player.h" | #include "player.h" | ||||||
|  |  | ||||||
|  | #include <iostream> | ||||||
|  | #include <chrono> | ||||||
|  | #include <thread> | ||||||
|  | #include <queue> | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // Define a structure to represent notifications | ||||||
|  | struct Notification { | ||||||
|  | 	std::string message; | ||||||
|  | 	float displayStartTime = 0.0f; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | // Use a queue to manage notifications | ||||||
|  | //std::queue<Notification> notificationQueue; | ||||||
|  | // Use a vector to manage notifications | ||||||
|  | std::vector<Notification> notifications; | ||||||
|  |  | ||||||
| Engine::Engine() {} | Engine::Engine() {} | ||||||
|  |  | ||||||
| Engine::~Engine() { | Engine::~Engine() { | ||||||
| @@ -100,6 +118,91 @@ void Engine::LoadResource() { | |||||||
|  |  | ||||||
| void Engine::UnloadResource() {} | void Engine::UnloadResource() {} | ||||||
|  |  | ||||||
|  | void Engine::SystemNotification(std::string systemLog) { | ||||||
|  | 	std::string message = ""; | ||||||
|  |  | ||||||
|  | 	message = systemLog; | ||||||
|  |  | ||||||
|  | 	DisplayNotification(message); | ||||||
|  | } | ||||||
|  | void Engine::KillNotification(Player killer, Player killed) { | ||||||
|  | 	std::string message = ""; | ||||||
|  |  | ||||||
|  | 	message = killed.GetUsername() + " killed by -> " + killer.GetUsername(); | ||||||
|  |  | ||||||
|  | 	DisplayNotification(message); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void Engine::DisplayNotification(std::string message) { | ||||||
|  |  | ||||||
|  | 	if (message.length() > 45) { | ||||||
|  | 		message = message.substr(0, 45); | ||||||
|  | 	} | ||||||
|  | 	// Create a new notification and add it to the queue | ||||||
|  | 	Notification newNotification; | ||||||
|  | 	newNotification.message = message; | ||||||
|  | 	newNotification.displayStartTime = m_time; | ||||||
|  | 	 | ||||||
|  | 	notifications.push_back(newNotification); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Add a method to process the notification queue | ||||||
|  | void Engine::ProcessNotificationQueue() { | ||||||
|  | 	m_textureFont.Bind(); | ||||||
|  | 	float scale = GetScale() / 2.0f; | ||||||
|  | 	unsigned int xOffset = Width() - Width() * 0.26; | ||||||
|  | 	unsigned int yOffset = Height() - (Height() / 2.2); | ||||||
|  |  | ||||||
|  | 	// Iterate through the notifications and display them | ||||||
|  | 	for (auto it = notifications.begin(); it != notifications.end(); ) { | ||||||
|  | 		float timeSinceDisplay = m_time - it->displayStartTime; | ||||||
|  |  | ||||||
|  | 		// Display the notification message with vertical offset | ||||||
|  | 		unsigned int y = yOffset - (static_cast<unsigned int>(scale * 20) * (it - notifications.begin())); | ||||||
|  | 		glDisable(GL_STENCIL_TEST); | ||||||
|  | 		glDisable(GL_DEPTH_TEST); | ||||||
|  |  | ||||||
|  | 		glBlendFunc(GL_SRC_ALPHA, GL_ONE); | ||||||
|  | 		glBlendEquation(GL_FUNC_ADD); | ||||||
|  |  | ||||||
|  | 		glMatrixMode(GL_PROJECTION); | ||||||
|  | 		glPushMatrix(); | ||||||
|  |  | ||||||
|  | 		glLoadIdentity(); | ||||||
|  | 		glOrtho(0, Width(), 0, Height(), -1, 1); | ||||||
|  |  | ||||||
|  | 		glMatrixMode(GL_MODELVIEW); | ||||||
|  | 		glPushMatrix(); | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		PrintText(xOffset, y, scale, it->message); | ||||||
|  |  | ||||||
|  | 		glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); | ||||||
|  | 		glBlendEquation(GL_FUNC_SUBTRACT); | ||||||
|  |  | ||||||
|  | 		glEnable(GL_STENCIL_TEST); | ||||||
|  | 		glEnable(GL_DEPTH_TEST); | ||||||
|  |  | ||||||
|  | 		glMatrixMode(GL_PROJECTION); | ||||||
|  | 		glPopMatrix(); | ||||||
|  |  | ||||||
|  | 		glMatrixMode(GL_MODELVIEW); | ||||||
|  | 		glPopMatrix(); | ||||||
|  | 		// Check if it's time to remove the notification (display for 2 seconds) | ||||||
|  | 		if (timeSinceDisplay >= 4.0f) { | ||||||
|  | 			it = notifications.erase(it);  // Remove the notification | ||||||
|  | 		} | ||||||
|  | 		else { | ||||||
|  | 			++it; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| void Engine::DisplayCrosshair() { | void Engine::DisplayCrosshair() { | ||||||
| 	m_textureCrosshair.Bind(); | 	m_textureCrosshair.Bind(); | ||||||
| 	static const int crossSize = 32; | 	static const int crossSize = 32; | ||||||
| @@ -249,6 +352,17 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) { | |||||||
|  |  | ||||||
| 	int timer = GetCountdown(elapsedTime); | 	int timer = GetCountdown(elapsedTime); | ||||||
|  |  | ||||||
|  | 	// Appel de la fonction pour l'affichage de notifications | ||||||
|  | 	if (m_keyK) { | ||||||
|  | 		SystemNotification(m_messageNotification); | ||||||
|  | 		m_keyK = false; | ||||||
|  | 	} | ||||||
|  | 	if (m_keyL) { | ||||||
|  | 		 | ||||||
|  | 		KillNotification(m_player, m_player); | ||||||
|  | 		m_keyL = false; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if (m_displayInfo) { | 	if (m_displayInfo) { | ||||||
| 		DisplayInfo(elapsedTime, bloc); | 		DisplayInfo(elapsedTime, bloc); | ||||||
| 	} | 	} | ||||||
| @@ -393,6 +507,7 @@ void Engine::Render(float elapsedTime) { | |||||||
|  |  | ||||||
| 	if (m_isSkybox) m_skybox.Render(skybox); | 	if (m_isSkybox) m_skybox.Render(skybox); | ||||||
|  |  | ||||||
|  | 	ProcessNotificationQueue(); | ||||||
| 	DrawHud(elapsedTime, bloc); | 	DrawHud(elapsedTime, bloc); | ||||||
| 	 | 	 | ||||||
| 	static bool fell = false; | 	static bool fell = false; | ||||||
| @@ -444,6 +559,13 @@ void Engine::KeyPressEvent(unsigned char key) { | |||||||
| 		break; | 		break; | ||||||
| 	case 5: // F - Ignorer | 	case 5: // F - Ignorer | ||||||
| 		break; | 		break; | ||||||
|  | 	case 10: // K - Debugging DisplayNotification() | ||||||
|  | 		m_keyK = true; | ||||||
|  | 		m_messageNotification = "notifications systeme peuvent <20>tre affich<63>"; | ||||||
|  | 		break; | ||||||
|  | 	case 11: // L - Debugging DisplayNotification() | ||||||
|  | 		m_keyL = true; | ||||||
|  | 		break; | ||||||
| 	case 6: // G - Ignorer | 	case 6: // G - Ignorer | ||||||
| 		break; | 		break; | ||||||
| 	case 12: // M - Ignorer | 	case 12: // M - Ignorer | ||||||
| @@ -492,6 +614,12 @@ void Engine::KeyReleaseEvent(unsigned char key) { | |||||||
| 		m_displayInfo = !m_displayInfo; | 		m_displayInfo = !m_displayInfo; | ||||||
| 		std::cout << "DISPLAY INFO " << (m_displayInfo ? "enabled" : "disabled") << std::endl; | 		std::cout << "DISPLAY INFO " << (m_displayInfo ? "enabled" : "disabled") << std::endl; | ||||||
| 		break; | 		break; | ||||||
|  | 	case 10: // K | ||||||
|  | 		m_keyK = false; | ||||||
|  | 		break; | ||||||
|  | 	case 11: // L - Debugging DisplayNotification() | ||||||
|  | 		m_keyL = false; | ||||||
|  | 		break; | ||||||
| 	case 12: // M - Toggle music | 	case 12: // M - Toggle music | ||||||
| 		m_audio.ToggleMusicState(); | 		m_audio.ToggleMusicState(); | ||||||
| 		break; | 		break; | ||||||
|   | |||||||
| @@ -39,6 +39,10 @@ private: | |||||||
|  |  | ||||||
|     bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); |     bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); | ||||||
|  |  | ||||||
|  |     void SystemNotification(std::string systemLog); | ||||||
|  |     void KillNotification(Player killer, Player killed); | ||||||
|  |     void DisplayNotification(std::string message); | ||||||
|  |     void ProcessNotificationQueue(); | ||||||
|     void DisplayCrosshair(); |     void DisplayCrosshair(); | ||||||
|     void DisplayCurrentItem(); |     void DisplayCurrentItem(); | ||||||
|     void DisplayHud(int timer); |     void DisplayHud(int timer); | ||||||
| @@ -83,6 +87,8 @@ private: | |||||||
|     bool m_resetcountdown = false; |     bool m_resetcountdown = false; | ||||||
|     bool m_stopcountdown = false; |     bool m_stopcountdown = false; | ||||||
|      |      | ||||||
|  |     bool m_keyK = false; | ||||||
|  |     bool m_keyL = false; | ||||||
|     bool m_keyW = false; |     bool m_keyW = false; | ||||||
|     bool m_keyA = false; |     bool m_keyA = false; | ||||||
|     bool m_keyS = false; |     bool m_keyS = false; | ||||||
| @@ -93,6 +99,8 @@ private: | |||||||
|     bool m_mouseC = false; |     bool m_mouseC = false; | ||||||
|     bool m_mouseWU = false; |     bool m_mouseWU = false; | ||||||
|     bool m_mouseWD = false; |     bool m_mouseWD = false; | ||||||
|  |  | ||||||
|  |     std::string m_messageNotification = ""; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // ENGINE_H__ | #endif // ENGINE_H__ | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(po | |||||||
| 	m_velocity = Vector3f(0, 0, 0); | 	m_velocity = Vector3f(0, 0, 0); | ||||||
| 	m_airborne = true; | 	m_airborne = true; | ||||||
| 	m_hp = 0.75f; //TODO: Remettre <20> 1.0f | 	m_hp = 0.75f; //TODO: Remettre <20> 1.0f | ||||||
| 	m_username = "Zelda Bee-Bop"; | 	m_username = "Zelda Bee-Bop56"; | ||||||
| } | } | ||||||
|  |  | ||||||
| void Player::TurnLeftRight(float value) { | void Player::TurnLeftRight(float value) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user