⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_render.cpp

📁 C++课程大学作业的一次任务
💻 CPP
字号:
////////////////////////////////
//    M_Render.cpp
//
// CORE RENDERER of UPM
//
// PROJECT: ULTRA PAC MAN
// PROGRAMER: Mal
// LAST UPDATED: Dec 2nd 2001
///////////////////////////////\

#include "m_render.h"
#include "m_err.h"
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>

//Pre-defined Global Pointer
M_Render* thisRenderer;

M_Render::M_Render()
{
	//Init graphics system
	/* request auto detection */
	int gdriver = DETECT, gmode, errorcode;
	//register the EGAVGA BGI driver
	registerfarbgidriver(EGAVGA_driver_far);
	/* initialize graphics and local variables */
	initgraph(&gdriver, &gmode, ".\\fonts");

	/* read result of initialization */
	errorcode = graphresult();
	if (errorcode != grOk)  /* an error	occurred */
	{
		MErr(grapherrormsg(errorcode),M_ERR_GRAPHICS_SYSTEM);
	}

	if((pMBC_Head = new ChgNode)==NULL || (pEC_Head = new ChgNode)==NULL)
	{
		MErr("ERROR OCCURRED WHEN CREATING BASE CHANGE LIST NODES");
	}

	//Directs their next to NULL
	pMBC_Head->pNext = NULL;
	pEC_Head->pNext = NULL;

}

M_Render::~M_Render()
{
 //flush the Map Block chglist first
 ChgNode* pHead = pMBC_Head;
 ChgNode* pThis = pHead;

 while(pHead->pNext != NULL)
 {
	pThis = pHead;
	pHead = pHead->pNext;
	delete pThis;
 }
 //delete the last one left on MBC
 delete pHead;

 //then flush the Entity chglist...
 pHead = pEC_Head;
 pThis = pHead;

 while(pHead->pNext != NULL)
 {
	pThis = pHead;
	pHead = pHead->pNext;
	delete pThis;
 }
 //delete the last one left on EC
 delete pHead;

 //close graphics system
 closegraph();
}


bool M_Render::AddMBC(int bx, int by, int texture)
{
	if(bx>0 && bx<=MAPMAXX && by>0 && by<=MAPMAXY)
	{
		ChgNode* pPrvHead = pMBC_Head;

		if((pMBC_Head = new ChgNode)==NULL)//Memory not enough
		{
		  //go refresh the entire list
		  pMBC_Head = pPrvHead;
		  Refresh();

		  pPrvHead = pMBC_Head;
		  pMBC_Head = new ChgNode;
		}

		//fill the new node
		pMBC_Head->pNext = pPrvHead;
		pMBC_Head->nPosX = bx;
		pMBC_Head->nPosY = by;
		pMBC_Head->nTexture = texture;
	 return M_NORMAL;
	}
 return M_ERR_ADDMBC;
}

bool M_Render::AddEC(int x, int y, int texture, int offsetX, int offsetY)
{
	if(x>0 && x<=MAPMAXX && y>0 && y<=MAPMAXY)
	{
		ChgNode* pPrvHead = pEC_Head;
		if((pEC_Head = new ChgNode)==NULL)//Memory not enough
		{
		 //go refresh the entire list
			pEC_Head = pPrvHead;
			Refresh();

			pPrvHead = pEC_Head;
			pEC_Head = new ChgNode;
		}

		//fill the new node
		pEC_Head->pNext = pPrvHead;
		pEC_Head->nPosX = (x-1)*8+offsetX;
		pEC_Head->nPosY = (y-1)*8+offsetY;
		pEC_Head->nTexture = texture;
	  return M_NORMAL;
	 }
 return M_ERR_ADDEC;
}

bool M_Render::Refresh()
{
	ChgNode* pDel;//the one ready to delete
	ChgNode* pThis;//the one working on

	//Refresh Map Blocks first
	pThis = pMBC_Head;
	while(pThis->pNext != NULL)
	{
		setcolor(BLACK);
		outtextxy(((pThis->nPosX)-1)*8,((pThis->nPosY)-1)*8,"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -