added game logic class and lambda function for room
This commit is contained in:
parent
b7f8a0f67a
commit
d46e5da520
@ -2,6 +2,7 @@
|
||||
#include "Environment.h"
|
||||
#include "ObjLoader.h"
|
||||
#include "Inventory.h"
|
||||
#include "QuestScripts.h"
|
||||
#include "TextModel.h" // Add this include for LoadFromTextFile
|
||||
|
||||
namespace ZL {
|
||||
@ -13,12 +14,8 @@ void GameObjectManager::initialize() {
|
||||
|
||||
current_room_index = 0;
|
||||
|
||||
std::cout << "Hello x1" << std::endl;
|
||||
|
||||
coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
|
||||
|
||||
std::cout << "Hello x2" << std::endl;
|
||||
|
||||
// Load models
|
||||
colorCubeMesh = CreateCube3D(5.0);
|
||||
colorCubeMeshMutable.data = CreateCube3D(5.0);
|
||||
@ -30,23 +27,15 @@ void GameObjectManager::initialize() {
|
||||
testObjMeshMutable.data = testObjMesh;
|
||||
testObjMeshMutable.RefreshVBO();
|
||||
|
||||
std::cout << "Hello x2" << std::endl;
|
||||
|
||||
textMesh = ZL::LoadFromTextFile("./mesh001.txt"); // Add ZL:: namespace
|
||||
coneMesh = ZL::LoadFromTextFile("./cone001.txt"); // Add ZL:: namespace
|
||||
coneMesh.Scale(200);
|
||||
|
||||
std::cout << "Hello x3" << std::endl;
|
||||
|
||||
|
||||
textMeshMutable.AssignFrom(textMesh);
|
||||
textMeshMutable.RefreshVBO();
|
||||
coneMeshMutable.AssignFrom(coneMesh);
|
||||
coneMeshMutable.RefreshVBO();
|
||||
|
||||
std::cout << "Hello x4" << std::endl;
|
||||
|
||||
|
||||
// Load bone animations
|
||||
bx.LoadFromFile("mesh_armature_and_animation_data.txt");
|
||||
|
||||
@ -68,11 +57,13 @@ void GameObjectManager::initialize() {
|
||||
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";
|
||||
room_1.roomLogic = createRoom1Logic();
|
||||
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";
|
||||
room_2.roomLogic = createRoom1Logic();
|
||||
rooms.push_back(room_2);
|
||||
|
||||
activeObjects = rooms[current_room_index].objects;
|
||||
@ -235,6 +226,10 @@ void GameObjectManager::updateScene(size_t ms) {
|
||||
ao.highlighted = (dist < 50.f);
|
||||
|
||||
}
|
||||
|
||||
if (rooms[current_room_index].roomLogic) {
|
||||
rooms[current_room_index].roomLogic(*this, ms);
|
||||
}
|
||||
}
|
||||
|
||||
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
||||
|
||||
21
QuestScripts.cpp
Normal file
21
QuestScripts.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "QuestScripts.h"
|
||||
#include "GameObjectManager.h"
|
||||
#include "Inventory.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
std::function<void(GameObjectManager&, size_t)> createRoom1Logic()
|
||||
{
|
||||
return [](GameObjectManager& gom, size_t ms)
|
||||
{
|
||||
// if (gom.inventory.HasItem("book")) {
|
||||
// std::cout << "[Room 1] Игрок поднял книгу!\n";
|
||||
//
|
||||
// gom.switch_room(1);
|
||||
// }
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
9
QuestScripts.h
Normal file
9
QuestScripts.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
namespace ZL {
|
||||
class GameObjectManager;
|
||||
|
||||
std::function<void(GameObjectManager&, size_t)> createRoom1Logic();
|
||||
|
||||
}
|
||||
5
Room.h
5
Room.h
@ -4,11 +4,16 @@
|
||||
#include "Math.h"
|
||||
#include <memory>
|
||||
#include "ActiveObject.h"
|
||||
#include <functional>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
struct Room{
|
||||
std::shared_ptr<ZL::Texture> roomTexture;
|
||||
std::vector<ActiveObject> objects;
|
||||
std::string sound_name;
|
||||
|
||||
std::function<void(class GameObjectManager&, size_t)> roomLogic;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
2
start.sh
2
start.sh
@ -1,7 +1,7 @@
|
||||
g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp \
|
||||
ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp \
|
||||
ObjLoader.cpp cmakeaudioplayer/src/AudioPlayer.cpp TextModel.cpp \
|
||||
Inventory.cpp Environment.cpp GameObjectManager.cpp RenderSystem.cpp \
|
||||
Inventory.cpp Environment.cpp GameObjectManager.cpp RenderSystem.cpp QuestScripts.cpp \
|
||||
-o sdl_app -O2 -std=c++17 \
|
||||
-I cmakeaudioplayer/include \
|
||||
$(pkg-config --cflags --libs sdl2 gl) \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user