Added monster
This commit is contained in:
parent
32b2acf739
commit
769854ac84
@ -42,4 +42,7 @@ bool Environment::exitGameLoop = false;
|
|||||||
|
|
||||||
bool Environment::gameIsLoading = true;
|
bool Environment::gameIsLoading = true;
|
||||||
|
|
||||||
|
float Environment::monsterTimer = 0.0;
|
||||||
|
int Environment::monsterState = 1;
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
@ -46,6 +46,9 @@ public:
|
|||||||
|
|
||||||
static bool gameIsLoading;
|
static bool gameIsLoading;
|
||||||
|
|
||||||
|
static float monsterTimer;
|
||||||
|
static int monsterState;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -174,6 +174,15 @@ void GameObjectManager::initialize() {
|
|||||||
objects_in_inventory++;
|
objects_in_inventory++;
|
||||||
|
|
||||||
|
|
||||||
|
monsterTexturePtr1 = std::make_shared<Texture>(CreateTextureDataFromBmp32("./monster001.bmp32"));
|
||||||
|
monsterTexturePtr2 = std::make_shared<Texture>(CreateTextureDataFromBmp32("./monster002.bmp32"));
|
||||||
|
|
||||||
|
|
||||||
|
monsterScreenMesh = CreateRect2D({ 0.f, 0.f }, { 300.f, 300.f }, 0.5);
|
||||||
|
monsterScreenMeshMutable.AssignFrom(monsterScreenMesh);
|
||||||
|
monsterScreenMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
|
|
||||||
//SDL_ShowCursor(SDL_DISABLE);
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
|
|
||||||
@ -555,6 +564,30 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
|
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Environment::monsterState == 0)
|
||||||
|
{
|
||||||
|
Environment::monsterTimer += ms;
|
||||||
|
|
||||||
|
if (Environment::monsterTimer > 500)
|
||||||
|
{
|
||||||
|
Environment::monsterTimer = 0;
|
||||||
|
Environment::monsterState = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Environment::monsterTimer += ms;
|
||||||
|
|
||||||
|
if (Environment::monsterTimer > 500)
|
||||||
|
{
|
||||||
|
Environment::monsterTimer = 0;
|
||||||
|
Environment::monsterState = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//float Environment::monsterTimer = 0.0;
|
||||||
|
//int Environment::monsterState = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
||||||
|
|||||||
@ -81,6 +81,12 @@ public:
|
|||||||
bool sideThreadLoadingCompleted = false;
|
bool sideThreadLoadingCompleted = false;
|
||||||
|
|
||||||
int current_room_index;
|
int current_room_index;
|
||||||
|
|
||||||
|
std::shared_ptr<ZL::Texture> monsterTexturePtr1;
|
||||||
|
std::shared_ptr<ZL::Texture> monsterTexturePtr2;
|
||||||
|
ZL::VertexDataStruct monsterScreenMesh;
|
||||||
|
ZL::VertexRenderStruct monsterScreenMeshMutable;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//int animationCounter = 0;
|
//int animationCounter = 0;
|
||||||
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
||||||
|
|||||||
@ -121,6 +121,8 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
|||||||
//glBindTexture(GL_TEXTURE_2D, gameObjects.coneTexturePtr->getTexID());
|
//glBindTexture(GL_TEXTURE_2D, gameObjects.coneTexturePtr->getTexID());
|
||||||
//renderer.DrawVertexRenderStruct(gameObjects.coneMeshMutable);
|
//renderer.DrawVertexRenderStruct(gameObjects.coneMeshMutable);
|
||||||
|
|
||||||
|
//drawMonster(gameObjects);
|
||||||
|
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
drawViola(gameObjects);
|
drawViola(gameObjects);
|
||||||
|
|
||||||
|
|
||||||
@ -175,6 +177,13 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
|||||||
glBindTexture(GL_TEXTURE_2D, gameObjects.rooms[gameObjects.current_room_index].roomTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, gameObjects.rooms[gameObjects.current_room_index].roomTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(gameObjects.rooms[gameObjects.current_room_index].textMeshMutable);
|
renderer.DrawVertexRenderStruct(gameObjects.rooms[gameObjects.current_room_index].textMeshMutable);
|
||||||
|
|
||||||
|
if (gameObjects.current_room_index == 1)
|
||||||
|
{
|
||||||
|
drawMonster(gameObjects);
|
||||||
|
}
|
||||||
|
drawViola(gameObjects);
|
||||||
|
|
||||||
|
|
||||||
Matrix4f latestProjectionModelView = renderer.GetProjectionModelViewMatrix();
|
Matrix4f latestProjectionModelView = renderer.GetProjectionModelViewMatrix();
|
||||||
|
|
||||||
// Проверяем пересечение с мышью после расчета всех матриц
|
// Проверяем пересечение с мышью после расчета всех матриц
|
||||||
@ -326,6 +335,55 @@ void RenderSystem::drawLoadingScreen(const GameObjectManager& gameObjects)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderSystem::drawMonster(const GameObjectManager& gameObjects)
|
||||||
|
{
|
||||||
|
renderer.shaderManager.PushShader("default");
|
||||||
|
|
||||||
|
static const std::string vPositionName = "vPosition";
|
||||||
|
static const std::string vTexCoordName = "vTexCoord";
|
||||||
|
renderer.EnableVertexAttribArray(vPositionName);
|
||||||
|
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||||
|
|
||||||
|
renderer.PushProjectionMatrix(static_cast<float>(Environment::width),
|
||||||
|
static_cast<float>(Environment::height), -10, 10);
|
||||||
|
renderer.PushMatrix();
|
||||||
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Found activeObjectScreenTexturePtr" << std::endl;
|
||||||
|
int screenX, screenY;
|
||||||
|
|
||||||
|
Vector3f objectPosPlusShift = Vector3f{ -300, 50, -70 };
|
||||||
|
worldToScreenCoordinates(objectPosPlusShift, currentProjectionModelView,
|
||||||
|
Environment::width, Environment::height, screenX, screenY);
|
||||||
|
renderer.PushMatrix();
|
||||||
|
// Здесь можно использовать вычисленные screenX, screenY,
|
||||||
|
// но для теста оставляем фиксированное значение
|
||||||
|
renderer.TranslateMatrix(Vector3f{ screenX + 0.f, screenY + 0.f, 0.0f });
|
||||||
|
|
||||||
|
if (Environment::monsterState == 0)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gameObjects.monsterTexturePtr1->getTexID());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gameObjects.monsterTexturePtr2->getTexID());
|
||||||
|
}
|
||||||
|
renderer.DrawVertexRenderStruct(gameObjects.monsterScreenMeshMutable);
|
||||||
|
renderer.PopMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
renderer.PopMatrix();
|
||||||
|
renderer.PopProjectionMatrix();
|
||||||
|
|
||||||
|
// Выключаем атрибуты, чтобы сохранить баланс
|
||||||
|
renderer.DisableVertexAttribArray(vPositionName);
|
||||||
|
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||||
|
|
||||||
|
// Снимаем шейдер, тем самым балансируя стек
|
||||||
|
renderer.shaderManager.PopShader();
|
||||||
|
}
|
||||||
|
|
||||||
void RenderSystem::worldToScreenCoordinates(Vector3f objectPos,
|
void RenderSystem::worldToScreenCoordinates(Vector3f objectPos,
|
||||||
Matrix4f projectionModelView,
|
Matrix4f projectionModelView,
|
||||||
int screenWidth, int screenHeight,
|
int screenWidth, int screenHeight,
|
||||||
|
|||||||
@ -26,6 +26,7 @@ private:
|
|||||||
void drawViola(GameObjectManager& gameObjects);
|
void drawViola(GameObjectManager& gameObjects);
|
||||||
|
|
||||||
void drawLoadingScreen(const GameObjectManager& gameObjects);
|
void drawLoadingScreen(const GameObjectManager& gameObjects);
|
||||||
|
void drawMonster(const GameObjectManager& gameObjects);
|
||||||
|
|
||||||
ShaderManager shaderManager;
|
ShaderManager shaderManager;
|
||||||
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
||||||
|
|||||||
BIN
monster001.bmp32
Normal file
BIN
monster001.bmp32
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
BIN
monster002.bmp32
Normal file
BIN
monster002.bmp32
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
Loading…
Reference in New Issue
Block a user