🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Cripes Update

Published June 22, 2008
Advertisement
I've made some pretty good progress! I fixed some problems (and overcompensations) in GameView's Hook/UnhookEntity functions, and got rid of the iterator contained in entity. Now you just pass the address of the entity to UnhookEntity. Does the same job, and is a lot cleaner.

Also, up to this point I was assuming that the GameView's map buffer and window were the same sizes. I changed that today, so now it properly shows a window onto the buffer, no matter what size the buffer is. Even if the window is bigger than the map, I think, because I've added in looping maps! If you happen to see, say, further than the right edge of the buffer, the left edge loops over so it's a continuous, infinite map in all directions. Here's how I do it in Draw():

void GameView::Draw(int x, int y){	SMALL_RECT writerect = {x, y, x+viewsize.X-1, y+viewsize.Y-1};	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);	CHAR_INFO* tempbuf = new CHAR_INFO[viewsize.X*viewsize.Y];	for (int i = viewloc.Y; i < viewloc.Y+viewsize.Y; ++i)	{		for (int j = viewloc.X; j < viewloc.X+viewsize.X; ++j)		{			int tempidx = (i-viewloc.Y)*viewsize.X+(j-viewloc.X); // index within the tempbuf			int playidx = i*realsize.X+j;                         // these two indices refer to the same conceptual location.			// This "sews" the left/right and up/down map edges together, if they're visible.			if (j >= realsize.X)				playidx -= realsize.X;			if (i >= realsize.Y)				playidx -= realsize.X*realsize.Y;			tempbuf[tempidx].Attributes = playbuf[playidx].Attributes;			tempbuf[tempidx].Char = playbuf[playidx].Char;		}	}	COORD topleft = {0, 0};	WriteConsoleOutput(hOut, tempbuf, viewsize, topleft, &writerect);}


Okay, one thing before I go on. WriteConsoleOutput is wonderfully handy. But I can never, ever remember how to use it properly without looking at the docmentation. >_<

The code starts off by creating a few things that WriteConsoleOutput will need, such as the buffer to copy to the console, the console output handle, and the.. um.. Hold on, where's that MSDN link... Okay, that's the rectangle that defines where the buffer will be written to. From there, I iterate through the temporary buffer, and copy each CHAR_INFO from the map to the temporary buffer. The complicated indexing is because the window is offset from the map, so you have to compensate to get the proper indexing. It's ugly.

During the copying, I check to see if a given coordinate value is too far over to the right or down. If it is, I subtract the X or Y value of the size of the map buffer, to achieve a looparound effect. The last two lines of the function create a COORD that defines where the top left location of the rect to copy from is, and then it does the actual writing.

Okay, so. The looparound isn't exactly an obvious effect, but here are two screenies. The blue-background, black-letter A's are just there for testing, to make it look like something's actually there.


This is the window view with no looparound, at least not needed. The edges of the screen are the edges of the map.


This is the window view when you've moved up and to the right a bit. No difference you can see, right? The four specially-coloured spaces were at the top-left of the screen, and now two are on the left and two are on the right.


Next up I'm going to work on adding the entities into the buffer. Right now I'm just using cout (and my color/position manipulators from April, I think) to draw my little green X, when I should really be letting the GameView do that.
Previous Entry Username Change
Next Entry The 'Entity'
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement