Tile Collision/Destruction Demo Port Source

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

JS Lemming wrote:Ooooookaaayyy... Right.... You don't know whay I'm talking about do you?
Me wrote:Okay, JSL. You've so totally lost me.
Obviously, we've already established that.

I never will understand what you're talking about. I've never made a level editor and you keep refering to:

123
456
789

As that. That's not a very good explanation. What in the hell are those numbers? Coordinates? Tile identification numbers?

Call me stupid, but I think I'm just ignorant of what you're trying to say.
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

JS Lemming wrote:
GyroVorbis wrote:Okay, JSL. You've so totally lost me.

Coordinate 1,1 on a 20x20 coordinate plane is 1,1 on a 23421423423423x4324234234324234324234 coordinate plane.
Ooooookaaayyy... Right.... You don't know whay I'm talking about do you?

When the below is spliced and set into memory:

Code: Select all

123 
456 
789
it looks like this in memory:

Code: Select all

123456789
When the mutated (resized) image is spliced in (below)

Code: Select all

123000 
456000 
789000
It looks like this in memory

Code: Select all

123000456000789000
When a level is loaded, it asociates the values in the file with the index of the spliced array. So the level data in a way becomes corrupt.
Yeah, but the thing is.
We need to add to the height (not width as shown in your example).
It'll look the same in memory exept larger.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Yeah, but the thing is.
We need to add to the height (not width as shown in your example).
It'll look the same in memory exept larger.
Yeah, only if the original image happened to have a width that was power of 2, which is not always the case for sprites too. And GV, those numbers were just representations of indivual tiles. thats all. It was either that or post a pic. (too lazy)
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Can't you load your tile data into a 2d array? Then you have actual coordinates.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Since no one seems to have a solution, I'll go ahead and bust out my idea. After the PC version is completed, me or somebody else makes a program that loads a spite sheet or tileset (same thing). It then asks for width, height, and number of tiles in the image. It then finds the most efficient ratio of perfect square dimmensions and tiles the individual pieces left to right, top to bottom. Thus making it difficult to edit, hence it is done after developement, and then usable by the DC. Now we can move on with our lives. 8)
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

So just individual images for now?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Remember, that whole Sprite vs. Image battle a while back?
MarauderIIC wrote:So just individual images for now?
JSL, you've been pwnt!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

GyroVorbis wrote:Remember, that whole Sprite vs. Image battle a while back?
MarauderIIC wrote:So just individual images for now?
JSL, you've been pwnt!
I don't get it? What are you talking about Mar? You too GyroV, how was I pwnt? Its not like my idea said anything about using seperate images...
Last edited by JS Lemming on Sun Dec 12, 2004 10:40 am, edited 1 time in total.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

I meant, do we want to use sep. images instead of spritesheets for now during development, to avoid the power-of-2-messing-up-sheet problem? Then we can pad individual images w/ blank data to achieve power of two.
Actually, my OpenGL + non-standard-LoadBMP bit here can load non-power-of-twos and then it scales them to power of two for usage. IIRC, it scales the actual image part to fit when I draw on a shape. Mipmapping also works but is slower. (Been a while since I looked at this code.) You'll note the memory handling stuff is in C. The tutorial does it that way but I'm also sure I could do something like have a class and then pad the class w/ an array... This uses actual numbers though.

Code: Select all

bool Texture::loadTexture(string pfilename, bool mipmap) {

	AUX_RGBImageRec* texImage[1];
	BYTE* scaleTex = NULL;

	memset(texImage, 0, sizeof(void*)*1);

	float powerLog;
	int powerOfTwo;
	//int powerOfTwo2;
	GLenum errored = 0;

	int newWidth;
	int newHeight;
	bool scaleImage = false;

	if (!(texImage[0] = LoadBMP(pfilename))) {
		debug(("loadTexture() : LoadBMP returned null. Could not open file '" + pfilename + "' for read."));
		return false;
	}

 	glGenTextures(1, &theTexture);

	glBindTexture(GL_TEXTURE_2D, theTexture);
 
	width = texImage[0]->sizeX;
	height = texImage[0]->sizeY;
	newWidth = texImage[0]->sizeX;
	newHeight = texImage[0]->sizeY;

	if (!mipmap) {
		//See if the image is a power of two. If it's not, mipmap it.
		powerLog = log(texImage[0]->sizeX)/log(2);
		powerOfTwo = roundFloat(powerLog);
		if (powerOfTwo != powerLog) {
			if (powerOfTwo < powerLog)
				powerOfTwo++;
			newWidth = (unsigned int)pow(2, powerOfTwo);
			scaleImage = true;
		}

		powerLog = log(texImage[0]->sizeY)/log(2);
		powerOfTwo = roundFloat(powerLog);
		if (powerOfTwo != powerLog) {
			if (powerOfTwo < powerLog)
				powerOfTwo++;
			newHeight = (unsigned int)pow(2, powerOfTwo);
			scaleImage = true;
		}
	}

	if (mipmap) {

		errored = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texImage[0]->sizeX,
			texImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, texImage[0]->data);

		if (errored) {
			string str = (char*)gluErrorString(errored);
			debug("Mipmap error: " + str);
			MessageBox(NULL, "Mipmap error.", "a", MB_OK);
		}

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	} else if (scaleImage) {

		scaleTex = (BYTE*)malloc(newWidth * newHeight * 3 * sizeof(BYTE));

		if (!scaleTex) {
			MessageBox(NULL, "Error allocating texture resize.", "err", MB_OK);
			return false;
		}

		errored = gluScaleImage(GL_RGB, texImage[0]->sizeX, texImage[0]->sizeY, GL_UNSIGNED_BYTE,
			texImage[0]->data, newWidth, newHeight, GL_UNSIGNED_BYTE, scaleTex);

		if (errored) {
			string str = (char*)gluErrorString(errored);
			debug("Scale error: " + str);
			MessageBox(NULL, "Scale error.", "a", MB_OK);
		}
		//width = newWidth;
		//height = newHeight;
	
		glTexImage2D(GL_TEXTURE_2D, 0, 3, newWidth,
			newHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
			scaleTex);

		debug("Scaled " + pfilename);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		
	} else {
		glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage[0]->sizeX,
			texImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
			texImage[0]->data);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	}


	if (texImage[0]) {
		if (texImage[0]->data)
			free(texImage[0]->data);
		free(texImage[0]);
	}

	if (scaleTex)
		free(scaleTex);

	return true;

}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Nah, I think sep images is too much work. Sheets will work great.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Then what's the problem with powers of two?! ARAGHAHh
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

MarauderIIC wrote:Then what's the problem with powers of two?! ARAGHAHh
I thought we already solved that problem.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply