Merge branch 'salmon' of github.com:mephi1984/ZeptoLabTest1 into salmon
This commit is contained in:
commit
e91bf4b35f
@ -7,8 +7,11 @@
|
||||
|
||||
namespace ZL {
|
||||
|
||||
const float GameObjectManager::INVENTORY_ICON_SIZE = 64.0f;
|
||||
const float GameObjectManager::INVENTORY_MARGIN = 10.0f;
|
||||
const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f;
|
||||
const float GameObjectManager::INVENTORY_MARGIN = 44.0f;
|
||||
|
||||
const float GameObjectManager::SELECTED_CUBE_ICON_SIZE = 244.0f;
|
||||
const float GameObjectManager::SELECTED_CUBE_MARGIN = 50.0f;
|
||||
|
||||
void GameObjectManager::initializeLoadingScreen()
|
||||
{
|
||||
@ -26,12 +29,15 @@ void GameObjectManager::initializeLoadingScreen()
|
||||
void GameObjectManager::initialize() {
|
||||
|
||||
initializeLoadingScreen();
|
||||
|
||||
|
||||
std::function<bool()> loadingFunction1 = [this]()
|
||||
{
|
||||
|
||||
current_room_index = 0;
|
||||
objects_in_inventory = 0;
|
||||
bearName = "";
|
||||
current_room_index = 0;
|
||||
objects_in_inventory = 0;
|
||||
|
||||
//coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
|
||||
|
||||
@ -111,7 +117,13 @@ void GameObjectManager::initialize() {
|
||||
room_1.textMeshMutable.AssignFrom(room_1.textMesh);
|
||||
room_1.collisionMgr.setRoomBoundary(800, 800);
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ 80, 0, 200 }, Vector3f{ 400, 0, 400 }));
|
||||
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ -220, 0, 165 }, Vector3f{ -143, 0, 230 }));
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ -400, 0, 125 }, Vector3f{ -121, 0, 400 }));
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ -380, 0, -92 }, Vector3f{ -240, 0, 100 }));
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ -399, 0, -390 }, Vector3f{ -236, 0, -100 }));
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ -220, 0, -400 }, Vector3f{ -150, 0, -230 }));
|
||||
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ 156, 0, -400 }, Vector3f{ 380, 0, -360 }));
|
||||
|
||||
rooms.push_back(room_1);
|
||||
aoMgr.addActiveObject(ao1);
|
||||
|
||||
@ -148,16 +160,18 @@ void GameObjectManager::initialize() {
|
||||
|
||||
//roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||
|
||||
AddItemToInventory("book1", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
|
||||
AddItemToInventory("cube_T", std::make_shared<Texture>(CreateTextureDataFromBmp32("./textures/inventory_objects/cubic_T_icon.bmp32")), objects_in_inventory + 1);
|
||||
objects_in_inventory++;
|
||||
AddItemToInventory("book2", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
|
||||
AddItemToInventory("cube_O", std::make_shared<Texture>(CreateTextureDataFromBmp32("./textures/inventory_objects/cubic_O_icon.bmp32")), objects_in_inventory + 1);
|
||||
objects_in_inventory++;
|
||||
AddItemToInventory("cube_M", std::make_shared<Texture>(CreateTextureDataFromBmp32("./textures/inventory_objects/cubic_O_icon.bmp32")), objects_in_inventory + 1);
|
||||
objects_in_inventory++;
|
||||
|
||||
|
||||
//SDL_ShowCursor(SDL_DISABLE);
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
@ -196,6 +210,42 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
const auto highlightedObjects = aoMgr.findByHighlighted(true);
|
||||
if (InventoryItem* item = GetItemSelected(true)) {
|
||||
std::cout << item->name << std::endl;
|
||||
|
||||
if (current_room_index==0) {
|
||||
|
||||
if (bearName.length() <= 3) {
|
||||
if (item->name == "cube_T"){
|
||||
bearName += "T";
|
||||
selectedCubes.push_back(*item);
|
||||
gInventoryMap.erase(item->name);
|
||||
objects_in_inventory--;
|
||||
}
|
||||
else if (item->name == "cube_O"){
|
||||
bearName += "O";
|
||||
selectedCubes.push_back(*item);
|
||||
gInventoryMap.erase(item->name);
|
||||
objects_in_inventory--;
|
||||
}
|
||||
else if (item->name == "cube_M"){
|
||||
bearName += "M";
|
||||
selectedCubes.push_back(*item);
|
||||
gInventoryMap.erase(item->name);
|
||||
objects_in_inventory--;
|
||||
}
|
||||
}
|
||||
else if (bearName.length() >= 3 && !(bearName.compare("TOM") == 0)) {
|
||||
bearName = "";
|
||||
for (const auto& cube : selectedCubes) {
|
||||
gInventoryMap[cube.name] = cube;
|
||||
}
|
||||
selectedCubes.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const auto highlightedObjects = aoMgr.findByHighlighted(true);
|
||||
|
||||
for (auto* ao : highlightedObjects) {
|
||||
if (!ao) {
|
||||
@ -209,7 +259,9 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
}
|
||||
// bx.Interpolate(animationCounter);
|
||||
// animationCounter += 2;
|
||||
}
|
||||
}
|
||||
|
||||
else if (event.type == SDL_MOUSEWHEEL) {
|
||||
static const float zoomstep = 1.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
@ -287,10 +339,17 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
break;
|
||||
case SDLK_1:
|
||||
case SDLK_2:
|
||||
{
|
||||
int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2;
|
||||
case SDLK_3:
|
||||
case SDLK_4:
|
||||
case SDLK_5:
|
||||
case SDLK_6:
|
||||
case SDLK_7:
|
||||
case SDLK_8:
|
||||
case SDLK_9:
|
||||
{
|
||||
|
||||
UnselectAllItems();
|
||||
if (InventoryItem* item = GetItemByHotkey(hot_key)) {
|
||||
if (InventoryItem* item = GetItemByHotkey(event.key.keysym.sym - SDLK_1 + 1)) {
|
||||
item->isSelected = true;
|
||||
}
|
||||
}
|
||||
@ -419,7 +478,7 @@ void GameObjectManager::updateScene(size_t ms) {
|
||||
newPosition.v[0] += directionVector.v[1] * ms;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
|
||||
|
||||
std::cout << "Player position: x=" << characterNewPos.v[0]
|
||||
|
||||
@ -4,14 +4,18 @@
|
||||
#include "AudioPlayerAsync.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "ActiveObject.h"
|
||||
#include "Room.h"
|
||||
#include "Inventory.h"
|
||||
#ifdef __linux__
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
#include "OpenGlExtensions.h"
|
||||
#include <thread>
|
||||
#include <list>
|
||||
|
||||
#include "BoundaryBox.h" // Добавляем новый include
|
||||
|
||||
|
||||
namespace ZL {
|
||||
|
||||
@ -50,7 +54,10 @@ public:
|
||||
|
||||
std::vector<ZL::ActiveObject> activeObjects;
|
||||
std::vector<ZL::Room> rooms;
|
||||
|
||||
std::vector<InventoryItem> selectedCubes;
|
||||
|
||||
std::string bearName;
|
||||
|
||||
AudioPlayerAsync audioPlayerAsync;
|
||||
|
||||
ZL::VertexDataStruct inventoryIconMesh;
|
||||
@ -58,6 +65,8 @@ public:
|
||||
|
||||
static const float INVENTORY_ICON_SIZE;
|
||||
static const float INVENTORY_MARGIN;
|
||||
static const float SELECTED_CUBE_ICON_SIZE;
|
||||
static const float SELECTED_CUBE_MARGIN;
|
||||
ActiveObjectManager aoMgr;
|
||||
int objects_in_inventory;
|
||||
|
||||
@ -73,11 +82,10 @@ public:
|
||||
|
||||
int current_room_index;
|
||||
private:
|
||||
|
||||
//int animationCounter = 0;
|
||||
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
||||
int lastMouseY = 0;
|
||||
|
||||
|
||||
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
|
||||
void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод
|
||||
Matrix4f projectionModelView,
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
#include "GameObjectManager.h"
|
||||
#include "Inventory.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
@ -9,16 +12,17 @@ namespace ZL
|
||||
std::function<void(GameObjectManager&, size_t)> createRoom1Logic()
|
||||
{
|
||||
return [](GameObjectManager& gom, size_t ms)
|
||||
// Simple test logic
|
||||
{
|
||||
if (GetItemByName("book")) {
|
||||
std::cout << "[Room 1] Игрок поднял книгу!\n";
|
||||
|
||||
gom.switch_room(1);
|
||||
if (gom.bearName.compare("TOM") == 0) {
|
||||
gInventoryMap.clear();
|
||||
gom.objects_in_inventory = 0;
|
||||
// std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
gom.switch_room(1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
std::function<void(GameObjectManager&, size_t)> createRoom2Logic()
|
||||
{
|
||||
return [](GameObjectManager& gom, size_t ms)
|
||||
|
||||
@ -236,11 +236,12 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
||||
if (item.isSelected) {
|
||||
float xPos = Environment::width
|
||||
- gameObjects.INVENTORY_MARGIN
|
||||
- gameObjects.INVENTORY_ICON_SIZE+25;
|
||||
- gameObjects.INVENTORY_ICON_SIZE;
|
||||
float yPos = gameObjects.INVENTORY_MARGIN
|
||||
+ i * (gameObjects.INVENTORY_ICON_SIZE+25
|
||||
+ i * (gameObjects.INVENTORY_ICON_SIZE
|
||||
+ gameObjects.INVENTORY_MARGIN);
|
||||
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
|
||||
renderer.ScaleMatrix(Vector3f{1.5f, 1.5f, 1.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, item.texture->getTexID());
|
||||
}
|
||||
else {
|
||||
@ -262,6 +263,27 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
||||
i++;
|
||||
}
|
||||
|
||||
// Отрисовка кубиков
|
||||
if (gameObjects.current_room_index == 0) {
|
||||
for (int j = gameObjects.selectedCubes.size() - 1; j >= 0; j--) {
|
||||
auto& cube = gameObjects.selectedCubes[j];
|
||||
renderer.PushMatrix();
|
||||
|
||||
float xPos = (gameObjects.SELECTED_CUBE_MARGIN + 300.0f)
|
||||
+ j * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN);
|
||||
float yPos = 500.0f;
|
||||
|
||||
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
|
||||
renderer.ScaleMatrix(Vector3f{2.8f, 2.8f, 1.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, cube.texture->getTexID());
|
||||
|
||||
renderer.DrawVertexRenderStruct(gameObjects.inventoryIconMeshMutable);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ namespace ZL {
|
||||
class RenderSystem {
|
||||
public:
|
||||
RenderSystem() = default;
|
||||
Renderer renderer;
|
||||
void initialize();
|
||||
void drawScene(GameObjectManager& gameObjects);
|
||||
Renderer& getRenderer() { return renderer; }
|
||||
@ -26,7 +27,6 @@ private:
|
||||
|
||||
void drawLoadingScreen(const GameObjectManager& gameObjects);
|
||||
|
||||
Renderer renderer;
|
||||
ShaderManager shaderManager;
|
||||
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
||||
int lastMouseX = 0;
|
||||
|
||||
BIN
textures/inventory_objects/cubic_O_icon.bmp32
Normal file
BIN
textures/inventory_objects/cubic_O_icon.bmp32
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 KiB |
BIN
textures/inventory_objects/cubic_T_icon.bmp32
Normal file
BIN
textures/inventory_objects/cubic_T_icon.bmp32
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 KiB |
Loading…
Reference in New Issue
Block a user