티스토리 뷰

마리오 게임을 구현해 보았다. 유튜브를 참고하였고, 내가 수정한 부분들도 있다. 유튜브 링크는:

https://www.youtube.com/watch?v=nD5OuMdS9FU 이다.

 

MapManager.h

#pragma once
#include "Stage.h"
#include "value.h"

class Cstage;
class CMapManager
{
private:
	CMapManager();
	~CMapManager();
	static CMapManager* m_pInst;
	CStage* m_pStage[STAGE_MAX_COUNT];
	int m_iEnableStage;
	bool Stop = false;
public:
	static CMapManager* GetInst();
	static void DestroyInst();
	bool Init();
	void Run(int iStage);
	void Render();
	CStage* GetStage() { return m_pStage[m_iEnableStage]; }
	bool SetStop() { Stop = true; return Stop; }
	bool GetStop() { return Stop; }
};

MapManager.cpp

#include "MapManager.h"
#include "Stage.h"
#include "Player.h"
#include "ObjectManager.h"
#include <string.h>

CMapManager* CMapManager::m_pInst = NULL;

CMapManager::CMapManager() {
	for (int i = 0; i < STAGE_MAX_COUNT; ++i) {
		m_pStage[i] = NULL;
	}
}

CMapManager::~CMapManager() {
	for (int i = 0; i < STAGE_MAX_COUNT; ++i) {
		SAFE_DELETE(m_pStage[i]);
	}
}

CMapManager* CMapManager::GetInst() {
	if (!m_pInst)
		m_pInst = new CMapManager;
	return m_pInst;
}

void CMapManager::DestroyInst() {
	SAFE_DELETE(m_pInst);
}

bool CMapManager::Init() {
	const char* pStageFile[3] = { "Stage1.txt", "Stage2.txt", "Stage3.txt" };
	for (int i = 0; i < STAGE_MAX_COUNT; ++i) {
		m_pStage[i] = new CStage;
		char save[40];
		strcpy_s(save, 20, pStageFile[i]);
		if (!m_pStage[i]->Init(save))
			return false;
	}
	return true;
}

void CMapManager::Run(int iStage) {
	CMapManager isStop;
	CPlayer* pPlayer = CObjectManager::GetInst()->GetPlayer();
	int Save[10][50] = { 0, };
	m_iEnableStage = iStage;

	pPlayer->SetPos(m_pStage[iStage]->GetStart().x, m_pStage[iStage]->GetStart().y);

	while (true) {

		CStage* pStage = CMapManager::GetInst()->GetStage();
		for (int i = 0; i < 10; ++i) {
			for (int j = 0; j < 50; ++j) {
				if (pStage->SaveCoin(i, j) == 1)
					Save[i][j] = 1;
			}
		}

		system("cls");

		if (GetAsyncKeyState('E') & 0x8000) {
			pPlayer->SetNotComplete();
			pPlayer->SetZeroScore();
			isStop.SetStop();
			break;
		}

		pPlayer->Update();
		m_pStage[iStage]->Render();
		cout << "Score : " << pPlayer->GetScore() << endl;

		if (pPlayer->GetComplete()) {
			cout << "스테이지 클리어!" << endl;
			Sleep(1500);
			pPlayer->SetNotComplete();
			pPlayer->SetZeroScore();
			break;
		}
		Sleep(100);
	}

	if (pPlayer->GetComplete() == false) {
		CStage* pStage = CMapManager::GetInst()->GetStage();
		for (int i = 0; i < 10; ++i) {
			for (int j = 0; j < 50; ++j) {
				if (Save[i][j] == 1) {
					pStage->ChangeBlock(j, i, SBT_COIN);
				}
			}
		}
	}
	if (isStop.GetStop()) {
		CStage* pStage = CMapManager::GetInst()->GetStage();
		for (int i = 0; i < 10; ++i) {
			for (int j = 0; j < 50; ++j) {
				if (Save[i][j] == 1) {
					pStage->ChangeBlock(j, i, SBT_COIN);
				}
			}
		}
	}
}

void CMapManager::Render() {
	m_pStage[0]->Render();
}
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함