smile blog 2022. 9. 23. 19:37
씬들을 모아놓은 파일
Scene.cpp

==> 기본 씬의 소스파일

#include "Scene.h"

Scene::Scene()
{
}

Scene::~Scene()
{
}

void Scene::Update()
{
}

void Scene::Render()
{
	mMap.Render();
}

void Scene::Destroy()
{
}

 

Scene.h

==> 기본씬의 헤더파일

#pragma once
#include "Map.h"


// 추상클래스 ( 순수가상함수가 하나라도 들어 있으면 )

class Scene
{
public:
	Scene();
	~Scene();

	// 순수가상함수
	virtual void Initiailize() = 0;
	virtual void Update() = 0;
	virtual void Render() = 0;
	virtual void Destroy() = 0;

protected:
	Map* mMap;
};

TitleScene.cpp

==> 타이틀씬의 소스파일

#include "TitleScene.h"
#include "Application.h"


TitleScene::TitleScene()
{
}

TitleScene::~TitleScene()
{
}

void TitleScene::Initiailize()
{
}

void TitleScene::Update()
{
	if (_kbhit())
	{        //키보드 입력 확인 (true / false)
		char input = _getch();

		if (input == '\r') //\0은 엔터키를 의미한다
		{
			Application::GetInstance()->SetPlaySceneNumber(SCENETYPE::PLAY);
		}
		else
		{
			int a = 0;
		}
	}
}

void TitleScene::Render()
{
	short x = SIZE_MAP_X * 2;
	short y = 10;

	SET_COLOR(COLOR::SKY_BLUE);
	GOTO_XY((x + 2), (y + 1));   std::wcout << (L"P U S H  P U S H");
	SET_COLOR(COLOR::DARK_YELLOW);
	GOTO_XY(x, (y + 2));   std::wcout << (L"┏━━━━━━━━━━━━━━━━┓");
	GOTO_XY(x, (y + 3));   std::wcout << (L"┃P U S H  P U S H┃");
	GOTO_XY(x, (y + 4));   std::wcout << (L"┃ made by AR 44th┃");
	GOTO_XY(x, (y + 5));   std::wcout << (L"┗━━━━━━━━━━━━━━━━┛");


	GOTO_XY(x, (y + 8));   std::wcout << (L"   PRESS ENTER");
	SET_COLOR(COLOR::YELLOW);


	// 반짝거리는 효과 타이틀 화면
	int to_add = 0;
	int cur_color = 0;
	while (true)
	{
		GOTO_XY((x - 7), (y + 9));
		for (to_add = 0; to_add < 37; to_add++)
		{
			SET_COLOR((cur_color + to_add) % 16 * 16);
			std::wcout << L" ";
		}
		if (cur_color > 0)
			cur_color--;
		else
			cur_color = 15;
		Sleep(100);

		if (_kbhit())
		{
			break;
		}
	}
}


void TitleScene::Destroy()
{
}

 

TitleScene.h

==> 타이틀씬의 헤더파일

#pragma once
#include "Scene.h"


class TitleScene : public Scene
{
public:
	TitleScene();
	~TitleScene();

	virtual void Initiailize() override;
	virtual void Update() override;
	virtual void Render() override;
	virtual void Destroy() override;

private:
	

};

PlayScene.cpp

==> 게임플레이씬의 소스파일

#include "PlayScene.h"
#include "Application.h"

#include "Ball.h"


PlayScene::PlayScene()
{
}

PlayScene::~PlayScene()
{
}

void PlayScene::Initiailize()
{
	InitializeMap();
	InitializePlayer();
}

void PlayScene::Update()
{
	mMap->Update();
	//mPlayer.InputProcess();
	//mMap->SetGameObjectInMap(mPlayer.GetPos(), mPlayer.GetWChar_t());
}

//추가
void PlayScene::Render()
{
	short x = SIZE_MAP_X * 2;
	short y = 3;

	SET_COLOR(COLOR::DARK_RED);
	GOTO_XY(x, (y + 2));   std::wcout << (L"┏━━━━━━━━━━━━━━━━┓ ");
	GOTO_XY(x, (y + 3));   std::wcout << (L"┃   PLAY SCENE   ┃ ");
	GOTO_XY(x, (y + 4));   std::wcout << (L"┗━━━━━━━━━━━━━━━━┛ ");

	y = 5;
	SET_COLOR(COLOR::DARK_GREEN);
	GOTO_XY((x - 35), y++); printf("[ Backspace ] : undo\n");
	GOTO_XY((x - 35), y++); printf("[ Reset ] : R \n");
	GOTO_XY((x - 35), y++); printf("[ Esc ] : Exit \n");
	SET_COLOR(BLUE);
	y++;
	GOTO_XY((x - 35), y++); printf("[ H ] : Replay\n"); //타이틀씬으로
	// 위 기능들 구현 과제2
	// 돌멩이 같이 이동시키기

	SET_COLOR(GRAY);
	y = 5;
	GOTO_XY((x + 35), y++); printf("       W      ");
	GOTO_XY((x + 35), y++); printf("      ↑      ");
	GOTO_XY((x + 35), y++); printf(" A ←    → S ");
	GOTO_XY((x + 35), y++); printf("      ↓      ");
	GOTO_XY((x + 35), y++); printf("	   D      ");

	y++;
	y++;
	SET_COLOR(DARK_BLUE);
	GOTO_XY((x + 35), y++); printf("[ PAGE_UP ] : Next stage");
	GOTO_XY((x + 35), y++); printf("[ PAGE_DOWN ] : Previous");

	x = SIZE_MAP_X * 2 + 1;
	y = (7 + 6);
	GOTO_XY(x, y);
	mMap->Render(x, y);
}

void PlayScene::Destroy()
{
	delete mMap;
}

void PlayScene::InitializeMap()
{
	mMap = new Map(8, 8);
	//mStage 메모장데이터를 읽어들어서
	//그거에맞게 세팅해준다

	//mStage.SetMap(mMap);
	//mStage.Load();

	std::wstring stageData = L""; // L을 붙여야 함 ()아무것도 없다

	stageData += L"ㅤㅤ▩▩▩ㅤㅤㅤ"; //공백문자 따로 잇음
	stageData += L"ㅤㅤ▩ㅤ▩ㅤㅤㅤ"; // 유니코드 백과사전에 들어가면 다양한 유니코드를
	stageData += L"ㅤㅤ▩ㅤ▩▩▩▩"; // 볼 수 있음
	stageData += L"▩▩▩ㅤㅤㅤㅤ▩";
	stageData += L"▩ㅤㅤㅤㅤ▩▩▩";
	stageData += L"▩▩▩▩ㅤ▩ㅤㅤ";
	stageData += L"ㅤㅤㅤ▩ㅤ▩ㅤㅤ";
	stageData += L"ㅤㅤㅤ▩▩▩ㅤㅤ";

	mMap->Initiailize(stageData);
}

//추가
void PlayScene::InitializePlayer()
{
	Player* player = new Player(); // 플레이어 동적할당
	mMap->AddGameObject(dynamic_cast<GameObject*>(player)); // 부모자식간의 형변환
	// dynamic_cast = 부모형으로 안전하게 바꿔준다

	Ball* ball1 = new Ball(Pos(3, 4));
	mMap->AddGameObject(dynamic_cast<GameObject*>(ball1));
}

 

PlayScene.h

==> 게임플레이씬의 헤더파일

#pragma once
#include "Scene.h"
#include "Player.h"


class PlayScene : public Scene
{
public:
	PlayScene();
	~PlayScene();

	virtual void Initiailize() override;
	virtual void Update() override;
	virtual void Render() override;
	virtual void Destroy() override;

private:
	void InitializeMap(); // 맵을 초기화
	void InitializePlayer(); // 플레이어를 초기화


};