starting refactoring main.cpp

This commit is contained in:
Альберт Гадиев 2025-03-01 19:18:42 +06:00
parent 666bfc1b37
commit e2af375aa0
5 changed files with 91 additions and 2 deletions

View File

@ -0,0 +1,23 @@
#include "GameWorld.h"
#include "InputManager.h"
namespace ZL {
GameWorld& GameWorld::getInstance() {
static GameWorld instance;
return instance;
}
void GameWorld::update(float deltaTime) {
auto& input = InputManager::getInstance();
// Update game state based on input
if (input.isKeyPressed(SDL_SCANCODE_W)) {
// Move forward
}
// ... handle other game logic ...
}
void GameWorld::addObject(const Vector3f& position) {
mGameObjects.push_back(position);
}
}

View File

@ -0,0 +1,18 @@
#pragma once
#include "Vector3f.h"
#include <vector>
#include <memory>
namespace ZL {
class GameWorld {
public:
static GameWorld& getInstance();
void update(float deltaTime);
void addObject(const Vector3f& position);
// ...other game world related methods...
private:
GameWorld() = default;
std::vector<Vector3f> mGameObjects;
};
}

View File

@ -0,0 +1,27 @@
#include "InputManager.h"
namespace ZL {
InputManager& InputManager::getInstance() {
static InputManager instance;
return instance;
}
void InputManager::processInput() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
mShouldQuit = true;
}
else if (event.type == SDL_KEYDOWN) {
mKeys[event.key.keysym.scancode] = true;
}
else if (event.type == SDL_KEYUP) {
mKeys[event.key.keysym.scancode] = false;
}
}
}
bool InputManager::isKeyPressed(SDL_Scancode key) const {
return mKeys[key];
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <SDL2/SDL.h>
namespace ZL {
class InputManager {
public:
static InputManager& getInstance();
void processInput();
bool isKeyPressed(SDL_Scancode key) const;
bool shouldQuit() const { return mShouldQuit; }
private:
InputManager() = default;
bool mKeys[SDL_NUM_SCANCODES] = {false};
bool mShouldQuit = false;
};
}

View File

@ -413,7 +413,9 @@ namespace ZL
// std::cout << "Before removal:\n";
ZL::PrintInventory();
21s
~/g/ZeptoLabTest1 Albert 2 +5 git commit -m "added sh file for start in linux"
[Albert 666bfc1] added sh file for start in linux
// Удаляем "Cone" из инвентаря
// ZL::RemoveItemFromInventory("Cone");
@ -534,7 +536,9 @@ namespace ZL
case SDLK_w:
Env::upPressed = false;
break;
case SDLK_DOWN:
case SDLK_DOWN: 21s
~/g/ZeptoLabTest1 Albert 2 +5 git commit -m "added sh file for start in linux"
[Albert 666bfc1] added sh file for start in linux
case SDLK_s:
Env::downPressed = false;
break;