mege
This commit is contained in:
commit
dc01bdf12e
@ -5,6 +5,7 @@
|
||||
|
||||
namespace ZL {
|
||||
struct ActiveObject {
|
||||
std::string name;
|
||||
std::shared_ptr<ZL::Texture> activeObjectTexturePtr;
|
||||
ZL::VertexDataStruct activeObjectMesh;
|
||||
ZL::VertexRenderStruct activeObjectMeshMutable;
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
#include "Environment.h"
|
||||
#include "ObjLoader.h"
|
||||
#include "Inventory.h"
|
||||
#include "Room.h"
|
||||
#include "TextModel.h" // Add this include for LoadFromTextFile
|
||||
|
||||
namespace ZL {
|
||||
@ -12,6 +11,8 @@ const float GameObjectManager::INVENTORY_MARGIN = 10.0f;
|
||||
|
||||
void GameObjectManager::initialize() {
|
||||
|
||||
current_room_index = 0;
|
||||
|
||||
std::cout << "Hello x1" << std::endl;
|
||||
|
||||
coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
|
||||
@ -52,6 +53,7 @@ void GameObjectManager::initialize() {
|
||||
|
||||
// Create active object
|
||||
ActiveObject ao1;
|
||||
ao1.name = "book";
|
||||
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
|
||||
ao1.activeObjectMesh.Scale(4);
|
||||
ao1.activeObjectMeshMutable.AssignFrom(ao1.activeObjectMesh);
|
||||
@ -62,19 +64,26 @@ void GameObjectManager::initialize() {
|
||||
ao1.activeObjectScreenMesh = CreateRect2D({ 0.f, 0.f }, { 64.f, 64.f }, 0.5);
|
||||
ao1.activeObjectScreenMeshMutable.AssignFrom(ao1.activeObjectScreenMesh);
|
||||
ao1.activeObjectScreenMeshMutable.RefreshVBO();
|
||||
activeObjects.push_back(ao1);
|
||||
|
||||
std::cout << "Hello x5" << std::endl;
|
||||
Room room_1;
|
||||
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||
room_1.objects.push_back(ao1);
|
||||
room_1.sound_name = "file_example_OOG_5MG.ogg";
|
||||
rooms.push_back(room_1);
|
||||
|
||||
Room room_2;
|
||||
room_2.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./background.bmp"));
|
||||
room_2.sound_name = "Symphony No.6 (1st movement).ogg";
|
||||
rooms.push_back(room_2);
|
||||
|
||||
activeObjects = rooms[current_room_index].objects;
|
||||
|
||||
// Initialize audio
|
||||
audioPlayer = std::make_unique<AudioPlayer>();
|
||||
if (audioPlayer) {
|
||||
audioPlayer->playMusic("Symphony No.6 (1st movement).ogg");
|
||||
audioPlayer->playMusic(rooms[current_room_index].sound_name);
|
||||
}
|
||||
|
||||
std::cout << "Hello x6" << std::endl;
|
||||
|
||||
// Initialize inventory
|
||||
inventoryIconMesh = CreateRect2D(
|
||||
{0.0f, 0.0f},
|
||||
@ -84,33 +93,47 @@ void GameObjectManager::initialize() {
|
||||
inventoryIconMeshMutable.AssignFrom(inventoryIconMesh);
|
||||
inventoryIconMeshMutable.RefreshVBO();
|
||||
|
||||
std::cout << "Hello x7" << std::endl;
|
||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||
}
|
||||
|
||||
void GameObjectManager::switch_room(int index){
|
||||
current_room_index = index;
|
||||
|
||||
// Add test items to inventory
|
||||
auto testRoomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||
auto testConeTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
|
||||
AddItemToInventory("RoomCeramics", testRoomTexture);
|
||||
AddItemToInventory("Cone", testConeTexture);
|
||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||
|
||||
std::cout << "Hello x8" << std::endl;
|
||||
audioPlayer.reset(); // This deletes the current AudioPlayer
|
||||
|
||||
// Reinitialize it
|
||||
audioPlayer = std::make_unique<AudioPlayer>();
|
||||
if (audioPlayer) {
|
||||
audioPlayer->playMusic(rooms[current_room_index].sound_name);
|
||||
}
|
||||
|
||||
roomTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||
activeObjects = rooms[current_room_index].objects;
|
||||
|
||||
std::cout << "Current music" << rooms[current_room_index].sound_name << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) {
|
||||
switch_room(1);
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) {
|
||||
|
||||
//switchRoom();
|
||||
|
||||
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
for (size_t i = 0; i < activeObjects.size(); ++i) {
|
||||
auto& ao = activeObjects[i];
|
||||
if (ao.highlighted) {
|
||||
AddItemToInventory(ao.name, ao.activeObjectTexturePtr);
|
||||
activeObjects.erase(activeObjects.begin() + i);
|
||||
// Можно выйти из цикла, если объект удален, чтобы избежать ошибок индексации.
|
||||
break;
|
||||
}
|
||||
}
|
||||
// bx.Interpolate(animationCounter);
|
||||
// animationCounter += 2;
|
||||
}
|
||||
|
||||
else if (event.type == SDL_MOUSEWHEEL) {
|
||||
static const float zoomstep = 1.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "ActiveObject.h"
|
||||
#include "Room.h"
|
||||
#ifdef __linux__
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
#include "OpenGlExtensions.h"
|
||||
|
||||
namespace ZL {
|
||||
@ -13,6 +17,8 @@ class GameObjectManager {
|
||||
public:
|
||||
void initialize();
|
||||
|
||||
void switch_room(int index);
|
||||
|
||||
void handleEvent(const SDL_Event& event);
|
||||
void updateScene(size_t ms);
|
||||
void checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView); // Добавляем новый метод
|
||||
@ -37,6 +43,7 @@ public:
|
||||
ZL::VertexRenderStruct coneMeshMutable;
|
||||
|
||||
std::vector<ZL::ActiveObject> activeObjects;
|
||||
std::vector<ZL::Room> rooms;
|
||||
std::unique_ptr<AudioPlayer> audioPlayer;
|
||||
|
||||
ZL::VertexDataStruct inventoryIconMesh;
|
||||
@ -49,6 +56,7 @@ private:
|
||||
//int animationCounter = 0;
|
||||
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
||||
int lastMouseY = 0;
|
||||
int current_room_index;
|
||||
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
|
||||
void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод
|
||||
Matrix4f projectionModelView,
|
||||
|
||||
@ -11,7 +11,7 @@ namespace ZL
|
||||
gInventory.push_back({ name, tex });
|
||||
}
|
||||
|
||||
void RemoveItemFromInventory(const std::string& name)
|
||||
void RemoveItemFromInventory(const std::string name)
|
||||
{
|
||||
gInventory.erase(
|
||||
std::remove_if(gInventory.begin(), gInventory.end(),
|
||||
|
||||
@ -169,6 +169,7 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
||||
// Draw highlighted objects UI
|
||||
for (const auto& ao : gameObjects.activeObjects) {
|
||||
if (ao.highlighted) {
|
||||
if (ao.activeObjectScreenTexturePtr){
|
||||
int screenX, screenY;
|
||||
worldToScreenCoordinates(ao.objectPos, currentProjectionModelView,
|
||||
Environment::width, Environment::height, screenX, screenY);
|
||||
@ -177,6 +178,7 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
||||
glBindTexture(GL_TEXTURE_2D, ao.activeObjectScreenTexturePtr->getTexID());
|
||||
renderer.DrawVertexRenderStruct(ao.activeObjectScreenMeshMutable);
|
||||
renderer.PopMatrix();
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ private:
|
||||
void drawUI(const GameObjectManager& gameObjects);
|
||||
|
||||
void drawViola(GameObjectManager& gameObjects);
|
||||
|
||||
|
||||
Renderer renderer;
|
||||
ShaderManager shaderManager;
|
||||
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
||||
|
||||
14
Room.h
14
Room.h
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "TextureManager.h"
|
||||
#include "Renderer.h"
|
||||
#include "ObjLoader.h"
|
||||
#include "Physics.h"
|
||||
#include "Math.h"
|
||||
#include <memory>
|
||||
#include "ActiveObject.h"
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
struct Room{
|
||||
std::shared_ptr<ZL::Texture> roomTexture;
|
||||
std::vector<ActiveObject> objects;
|
||||
std::string sound_name;
|
||||
};
|
||||
}
|
||||
|
||||
@ -143,7 +143,8 @@ bool AudioPlayer::playMusic(const std::string& filename) {
|
||||
alSourcei(musicSource, AL_BUFFER, musicBuffer);
|
||||
alSourcei(musicSource, AL_LOOPING, AL_TRUE); // Включаем зацикливание
|
||||
|
||||
std::cout << "▶️ Starting music playback...\n";
|
||||
std::cout << "▶️ Starting music playback... " << musicSource << std::endl;
|
||||
std::cout << "▶️ Music buffer... " << musicBuffer << std::endl;
|
||||
alSourcePlay(musicSource);
|
||||
|
||||
currentMusic = filename;
|
||||
|
||||
BIN
sounds/file_example_OOG_5MG.ogg
Normal file
BIN
sounds/file_example_OOG_5MG.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user