Skip to main content
GameDev.net gamedev.net
🔒 Locked

slight bug in my code...

Started by iAmCodeMonkey Jan 2, 2011 at 4:13 PM 2 replies 1.4k views
Original Post
iAmCodeMonkey
iAmCodeMonkey
Hey!

I have encountered a slight bug in my game code, and I want some suggestions on how to track down the cause...

I am loading in my level data from a text file with this format:

AMOUNT 12
asteroid 600 400
asteroid 1400 200
asteroid 1000 600
asteroid 1600 600
asteroid 1400 600
asteroid 1200 200
asteroid 1600 400
asteroid 400 200
asteroid 200 300
asteroid 400 600
asteroid 1100 300
asteroid 1500 300
...

where AMOUNT denotes that the total amount of entities for the level is beside that marker, and below that is the entity name and the x\y co-ordinates for each instance.

The problem that I am having is that my code does not seem to be rendering all of the entities in the file, after having loaded them into an STL vector. I am keeping track of the number of entities killed by the player, and I decrement that value each time an asteroid gets destroyed. But the number being rendered on screen, the amount\number specified in the text file, and the entity counter do not match up.

For example, I had 12 asteroids in the file to start off with, and after I killed them all, my entity counter was at 4... where did the other entities go???

-CodeMonkey
bobofjoe
bobofjoe
Good places to look are where your asteroids are destroyed, when you load the asteroids, and anywhere else that has access to the asteroid vector. Beyond that, you might want to post some code. We're not psychics here :D
[size=1]Visit my website, rawrrawr.com
rip-off
rip-off
What is your entity counter? Is it different from the size() of the vector<> containing the entities? If so, why? Keeping extra data in sync is hard, you have to be careful every time you modify the vector that the counter is correctly handled. Are you sure this is the case?
iAmCodeMonkey
iAmCodeMonkey
Here is a snippet of my level loading code, to show how I populate the asteroid vector...

/* look for enemy\other entities and get their offsets */while ( (inputFile.eof() != true) ) {	inputFile >> entityName;	/* get the total number of entites in the file, and move to the next line */	if ( (entityName == "AMOUNT") ) {		inputFile >> amount;		numberOfEntities = amount;		inputFile.ignore();	} /* end if */	/* look for asteroids */	if ( (entityName == "asteroid") ) {		/* load sprite image and get offsets */		asteroidFrames = image.imageLoader(asteroidBMP);		inputFile >> offset_X >> offset_Y;		/* add entity to container for storage and assign offsets */		asteroids.push_back(new asteroid());		asteroids[count]->set_X(offset_X);		asteroids[count]->set_Y(offset_Y);		/* make sure count is equal to amount specified */		if ( (count == amount) ) {			break;		} /* end if */		/* go to the next line and increment counter */		inputFile.ignore();		count++; /* should say ++ at the end */	} /* end if */} /* end while */


Here is a small snippet of my asteroid AI code, to show where my global entity counter (int numberOfEntities) is used...

/* if asteroid health is zero, destroy it */if ( (asteroidHealth == NULL) ) {	audio.playSoundFX(2, explosionSound, 0);	isCreated = false; /* do not render bullets */	isAlive = false;	isDestroyed = true;	numberOfEntities--;	bulletRef.setCollisionBox_X(-LEVEL_WIDTH);	playerScore = (playerScore + ASTEROID_POINT);	enemyKillCount++; /* should say ++ at the end */} /* end if */


Here is a snippet of my checkStatus() method, used to see if the player is dead\run out of lives, and if the enemies have been destroyed...

/* have all of the enemies been dispatched? */if ( (numberOfEntities == NULL) ) {	/* if so, go to the next level */	SDL_Delay(100);	audio.stopMusicTrack();	setNextState(END_LEVEL_STATE);} /* end if */


Wish me luck on finding the root cause! :D

-CodeMonkey

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.