Scene
์ฐ๋ฆฌ๊ฒ์์ ๊ตฌ์กฐ๋ ์ด๋ฐ ๋ฐฉ์์ผ๋ก ์งํ๋ ๊ฒ์ด๋ค.
์ฌ ์์๋ ์ค๋ธ์ ํธ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
์ฌ์ ์ฌ์ฉํ์ฌ ๋ฉ์ธ ๋ฉ๋ด, ๊ฐ๊ฐ์ ๋ ๋ฒจ ๋ฐ ๊ธฐํ ์ฌ๋ฌ๊ฐ์ง๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค.
ํ๋์ ์ฌ ํ์ผ์ ํ ๋ ๋ฒจ๋ก ์๊ฐํด์ผ ํฉ๋๋ค.
๊ฐ ์ฌ์์๋ ํ๊ฒฝ๊ณผ ์ฅ์ ๋ฌผ, ์ฅ์์ ๋ฐฐ์นํ๊ณ ๊ฒ์์ ์ธ์ธํ๊ฒ ๋์์ธํ๊ณ ๋ง๋ญ๋๋ค.
class Scene : public Entity
{
public:
Scene();
virtual ~Scene();
virtual void Initialize();
virtual void Update();
virtual void FixedUpdate();
virtual void Render();
Layer* GetLayer(UINT index) { return& mLayers[index]; }
void AddGameObject(GameObject* gameObject, UINT layerIndex);
private:
Layer mLayers[LAYER::MAX];
};
SceneManager
๊ทธ๋ฆฌ๊ณ ๊ฐ๊ฐ์ ์ฌ์ ๊ด๋ฆฌํ๋ SceneManager ํด๋์ค๊ฐ ์กด์ฌํ๋ค.
Scene๊ณผ Scene์ ๋๋๋๋ ์์ ์ ํ ๋ ์ด์ฉ๋๋ ํด๋์ค๋ผ๊ณ ์๊ฐํ๋ฉด ์ฝ๋ค.
์๋ฅผ ๋ค์ผ์ ๋ก๋ฉ์ด ๋๋๋ฉด ํ์ดํ์ฌ์ผ๋ก ์ด๋ํ๊ณ ๊ฒ์์์์ ๋๋ฅด๋ฉด ๊ฒ์ ํ๋ ์ด์ฌ์ผ๋ก ์ด๋ํ๊ณ
์ํ์ฒ๋ผ ์ฅ๋ฉดํ๋๋ฅผ ๋จ์๋ก ๊ฒ์์ ๊ตฌ์ฑํด์ฃผ๊ณ ๊ทธ ์ฅ๋ฉด๋ค์ ๊ด๋ฆฌํด์ฃผ๋ ํด๋์ค๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค.
class Scene;
class SceneManager
{
SINGLE(SceneManager)
public:
void Initialize();
void Tick();
void Render(HDC hdc);
private:
Scene* mScenes[SCENE_TYPE::END];
Scene* mPlayScene;
};
Game Object
๊ฒ์ ์ค๋ธ์ ํธ๋ ๋ ๋ฒจ์ ๋ฐฐ์นํ ์ ์๋ ์ค๋ธ์ ํธ๋ฅผ ๋งํฉ๋๋ค. ๊ฒ์ ์ค๋ธ์ ํธ๋ ์ด๋, ํ์ , ์ค์ผ์ผ๊ณผ ๊ฐ์ ํธ๋์คํผ์ ์ง์ํ๋ ๋ฒ์ฉ ํด๋์ค์ ๋๋ค. ํ๋ง๋๋ก ํ๋ฉด์์ ์กด์ฌํ๋ UI, ๋ชฌ์คํฐ, ํ๋ ์ด์ด ๋ฑ๋ฑ ์ฌ์ ๊ตฌ์ฑํ๋ ๋จ์๋ผ๊ณ ์๊ฐํ๋ฉด ๋ฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ ๊ฒ์ ์ค๋ธ์ ํธ ์์๋ ์ฌ๋ฌ๊ฐ์ง ๋ค๋ฅธ ๋ถ์ํ(component)๋ค์ด ์กด์ฌํฉ๋๋ค.
์๋ฅผ๋ค์ด Transform ์ ํฌ๊ธฐ ์ด๋ ๊ฐ๋ ๊ฐ์ ์์ ์ ๋ด๋นํ๊ณ SpriteRenderer๋ ํ๋ฉด์์ ๊ทธ๋ฆผ์ ๊ทธ๋ ค์ฃผ๋ ์ญํ ์ ํฉ๋๋ค. AudioSource๋ ์๋ฆฌ๋ฅผ ์ฌ์์์ผ์ฃผ๋ ์ญํ ์ ํ๊ตฌ์.
class GameObject;
class Component : public Entity
{
public:
friend GameObject;
Component(COMPONENTTYPE type);
virtual ~Component();
virtual void Initialize() = 0;
virtual void Update() = 0;
virtual void FixedUpdate() = 0;
virtual void Render() = 0;
GameObject* GetOwner() { return mOwner; }
UINT GetUpdateOrder() { return (UINT)mType; }
private:
const COMPONENTTYPE mType;
GameObject* mOwner;
};
์ด๋ ๊ฒ ์ฌ๋ฌ๊ฐ์ ์ฌ๊ณผ ๊ทธ ์ฌ์์ ์กด์ฌํ๋ ์ค๋ธ์ ํธ๋ค์ ๋ฐฐ์นํ์ฌ ๊ฒ์์ ๋ง๋ค๊ฒ ๋ฉ๋๋ค.
class GameObject : public Entity
{
public:
enum eState
{
Active,
Paused,
Dead,
};
GameObject();
virtual ~GameObject();
void AddComponent(Component* component);
template <typename T>
T* GetComponent()
{
T* component;
for (auto c : mComponents)
{
component = dynamic_cast<T*>(c);
if (component != nullptr)
return component;
}
return nullptr;
}
virtual void Initialize();
virtual void Update();
virtual void FixedUpdate();
virtual void Render();
private:
eState mState;
std::vector<Component*> mComponents;
};
'๐ Development Study > ๐ผ GameProgramming 2D' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Sampler ์ํ๋ฌ (0) | 2023.01.02 |
---|---|
Texture ์์ฑ (0) | 2022.12.26 |
Mesh, MeshRenderer (0) | 2022.12.21 |
Constant Buffer(์์ ๋ฒํผ), Index Buffer(์ธ๋ฑ์ค ๋ฒํผ) (1) | 2022.12.08 |
Drawing a Triangle (0) | 2022.12.06 |
๋๊ธ