Click here to Skip to main content
15,887,267 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Again CListBox Pin
Eytukan28-Jan-06 17:17
Eytukan28-Jan-06 17:17 
AnswerRe: Again CListBox Pin
Laxman929-Jan-06 17:43
Laxman929-Jan-06 17:43 
Questionmemcpy Pin
Anthony988728-Jan-06 6:06
Anthony988728-Jan-06 6:06 
AnswerRe: memcpy Pin
Chris Losinger28-Jan-06 6:12
professionalChris Losinger28-Jan-06 6:12 
AnswerRe: memcpy Pin
Roland Pibinger28-Jan-06 7:54
Roland Pibinger28-Jan-06 7:54 
QuestionLoading list elements in a CListBox Pin
hanno2528-Jan-06 5:37
hanno2528-Jan-06 5:37 
AnswerRe: Loading list elements in a CListBox Pin
Owner drawn29-Jan-06 18:04
Owner drawn29-Jan-06 18:04 
QuestionWhat's wrong with my map engine? Pin
Lord Kixdemp28-Jan-06 4:35
Lord Kixdemp28-Jan-06 4:35 
Hello everyone! Big Grin | :-D
OK, I posted a question 1 or 2 days ago about this... I already solved that problem, but now I'm facing another one!

The problem is that the maps don't load up correctly... Here's the ObjectType enumeration:

enum ObjectType<br />
{<br />
	// Empty tile<br />
	LX_EMPTY,<br />
<br />
	// Tiles for first layer<br />
	//L1_DESERT,	// Commented out because it's the default value (LX_EMPTY)s<br />
	L1_GRASS,<br />
<br />
	// Tiles for second layer<br />
	L2_ROCK,<br />
<br />
	// Tiles for third layer<br />
	L3_TELEPORTER,<br />
};


Here's some previous declarations needed to understand the troublesome methods:

<br />
#define WIDTH	512<br />
<br />
#define HEIGHT	384<br />
<br />
#define CHARW	32<br />
<br />
#define CHARH	32<br />
<br />
SDL_Surface ** mapLayerTiles;<br />
<br />
ObjectType mapLayers[3][WIDTH*HEIGHT];<br />
<br />
SDL_Surface * screen;<br />


Here's the method that loads the map layers:

void Mazzee::GetMapInfo(std::string map)<br />
{<br />
	// Map file streams<br />
	FILE * f[3] = {<br />
		fopen((map + ".ml1").c_str(), "rt"), <br />
		fopen((map + ".ml2").c_str(), "rt"), <br />
		fopen((map + ".ml3").c_str(), "rt")<br />
	};<br />
<br />
	//FILE * outputz = fopen("outputz.txt", "wt");<br />
<br />
	for (int x = 0; x < 3; x++)<br />
	{<br />
		if (f[x] == NULL)<br />
			exit(1);<br />
	}<br />
<br />
	// Get data for the layers<br />
<br />
	for (int x = 0; x < 3; x++)<br />
	{<br />
		int p = 0;<br />
		while (p < (WIDTH/32)*(HEIGHT/32))<br />
		{<br />
			//p = 0;	// Commented for debug purposes<br />
<br />
			// Exit if EOF was found<br />
			if (feof(f[x]))<br />
				return;<br />
<br />
			char v = fgetc(f[x]);<br />
<br />
			//fputc(v, outputz);<br />
<br />
			switch (v)<br />
			{<br />
				// Layer X (all)<br />
			case '.':<br />
				this->mapLayers[x][p] = LX_EMPTY;<br />
				++p;<br />
				break;<br />
<br />
				// Layer 1<br />
			case '|':<br />
				this->mapLayers[x][p] = L1_GRASS;<br />
				++p;<br />
				break;<br />
<br />
				// Layer 2<br />
			case 'o':<br />
				this->mapLayers[x][p] = L2_ROCK;<br />
				++p;<br />
				break;<br />
			<br />
				// Layer 3<br />
			case 'T':<br />
				this->mapLayers[x][p] = L3_TELEPORTER;<br />
				++p;<br />
				break;<br />
<br />
				/*// Newlines: Less p var by one<br />
			case '\r':<br />
			case '\n':<br />
				--p;<br />
				break;*/<br />
			}<br />
		}<br />
<br />
		//fclose(outputz);<br />
<br />
		// Close stream<br />
		fclose(f[x]);<br />
	}<br />
}


And here's the method that displays the map on the screen:

void Mazzee::DrawMap()<br />
{<br />
	// Fill with tiles<br />
	for (int x = 0; x < (WIDTH); x += CHARW)<br />
	{<br />
		for (int y = 0; y < (HEIGHT); y += CHARH)<br />
		{<br />
			for (int v = 0; v < 3; v++)<br />
			{<br />
				SDL_Rect src, dest;<br />
<br />
				if (v == 0)<br />
				{<br />
					if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
					else if (this->mapLayers[v][(x/32)*(y/32)] == L1_GRASS) src.x = 32;<br />
				}<br />
				else if (v == 1)<br />
				{<br />
					if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
					else if (this->mapLayers[v][(x/32)*(y/32)] == L2_ROCK) src.x = 32;<br />
				}<br />
				else if (v == 2)<br />
				{<br />
					if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
					else if (this->mapLayers[v][(x/32)*(y/32)] == L3_TELEPORTER) src.x = 32;<br />
				}<br />
<br />
				src.y = 0;<br />
				src.h = CHARH;<br />
				src.w = CHARW;<br />
<br />
				dest.x = x;<br />
				dest.y = y;<br />
				dest.h = CHARH;<br />
				dest.w = CHARW;<br />
<br />
				SDL_BlitSurface(this->mapLayerTiles[v], &src, this->screen, &dest);<br />
			}<br />
		}<br />
	}<br />
}


Here's the map files:

<br />
map1.ml1:<br />
...............<br />
...............<br />
...|...........<br />
...............<br />
...............<br />
...............<br />
...............<br />
.........|.....<br />
...|...........<br />
...............<br />
...............<br />
...............<br />
<br />
map1.ml2:<br />
o.............o<br />
...............<br />
...............<br />
...............<br />
..............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
o.............o<br />
<br />
map1.ml3:<br />
...............<br />
...............<br />
..T............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
............T..<br />
...............<br />


Sorry for making it long... Blush | :O Thanks! Wink | ;-)

Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
QuestionProblems with a trayicon popup menu Pin
428828-Jan-06 3:51
428828-Jan-06 3:51 
AnswerRe: Problems with a trayicon popup menu Pin
Owner drawn29-Jan-06 18:06
Owner drawn29-Jan-06 18:06 
GeneralRe: Problems with a trayicon popup menu Pin
428829-Jan-06 19:05
428829-Jan-06 19:05 
GeneralRe: Problems with a trayicon popup menu Pin
Owner drawn30-Jan-06 16:50
Owner drawn30-Jan-06 16:50 
QuestionMS DataGrid Control 6 - Find Selected Row & Read Cell Values Pin
sdancer7528-Jan-06 3:07
sdancer7528-Jan-06 3:07 
QuestionNumber of Children in a Particular Node Pin
kandukuri27-Jan-06 23:53
kandukuri27-Jan-06 23:53 
AnswerRe: Number of Children in a Particular Node Pin
Stephen Hewitt28-Jan-06 0:43
Stephen Hewitt28-Jan-06 0:43 
GeneralRe: Number of Children in a Particular Node Pin
kandukuri28-Jan-06 3:56
kandukuri28-Jan-06 3:56 
GeneralRe: Number of Children in a Particular Node Pin
Stephen Hewitt28-Jan-06 18:06
Stephen Hewitt28-Jan-06 18:06 
GeneralRe: Number of Children in a Particular Node Pin
kandukuri28-Jan-06 22:01
kandukuri28-Jan-06 22:01 
QuestionMDI Without menu Pin
bantisk27-Jan-06 23:24
bantisk27-Jan-06 23:24 
AnswerRe: MDI Without menu Pin
Joey Bloggs28-Jan-06 2:40
Joey Bloggs28-Jan-06 2:40 
GeneralRe: MDI Without menu Pin
bruspark9-Apr-06 23:28
bruspark9-Apr-06 23:28 
GeneralRe: MDI Without menu Pin
Joey Bloggs10-Apr-06 19:49
Joey Bloggs10-Apr-06 19:49 
QuestionHow to put IStream into IDataObject Pin
saravana pandy27-Jan-06 23:19
saravana pandy27-Jan-06 23:19 
AnswerRe: How to put IStream into IDataObject Pin
Stephen Hewitt28-Jan-06 1:04
Stephen Hewitt28-Jan-06 1:04 
GeneralRe: How to put IStream into IDataObject Pin
saravana pandy28-Jan-06 1:21
saravana pandy28-Jan-06 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.