Sign in to follow this  
Tynnhammar

Weapon fire refuses to show up!

Recommended Posts

Greetings! I'm trying doing a space invader clone, however I've run in some trouble in the process of writing the weapon code. The problems is that the bullet creates and it does enter the for loop but it doesn't show up. Please take a look at what might be wrong, because I've checked everything I know :/. full code,zipped, here
Units.cpp --> where the CBullet class exists

CBullet::CBullet()
{
	Alive = true;

	Display = SDL_GetVideoSurface();

	BulletV = 3;

	BulletIMG = SDL_LoadBMP("ship.bmp");
	
	BulletSrc.w = 47;
	BulletSrc.h = 30;
	BulletSrc.x = 0;
	BulletSrc.y = 0;

	BulletDest.w = 47;
	BulletDest.h = 30;
	BulletDest.x = 300;
	BulletDest.y = 300;
};

CBullet::~CBullet()
{
	SDL_FreeSurface(BulletIMG);
};

void CBullet::Show()
{
	SDL_BlitSurface(BulletIMG, &BulletSrc, Display, &BulletDest);
};

void CBullet::MoveUp()
{
		BulletDest.y -= BulletV;
};

void CBullet::CheckCollision()
{
	/*                  if(BulletDest.y = 20) bla bla
	{
		NOT IMPLEMENTED YET
	}
	*/
};

GAMELOOP.cpp
while(gamerunning)
{
                if(KeyHeld[SDLK_SPACE])
		{
			CBullet* newBullet = new CBullet;
			Bullets.push_back(newBullet);
		}
		if(Bullets.size() > 0)
		{	
			for(iter = Bullets.begin(); iter != Bullets.end(); ++iter)
			{
				(*iter)->MoveUp();
				(*iter)->Show();
				(*iter)->CheckCollision();
			}
		}
}

Share this post


Link to post
Share on other sites
Where is the full source? Could you give us a direct link?

You probably use doublebuffer (you use SDL_DOUBLEBUF flag at SDL_SetVideoMode). Check that you have SDL_Flip(screen) at the end of main loop (screen is your video surface (SDL_Surface *foo)).

Share this post


Link to post
Share on other sites
Ok, so it seems that you don't use double buffering(http://www.gamedev.net/dict/search.asp?Term=double+buffer). I recommend you to use it like this:

First you have to change your SDL_SetVideoMode()-function (from init.cpp):
From: Display = SDL_SetVideoMode(Width, Height, BitDepth, SDL_ANYFORMAT);
To: Display = SDL_SetVideoMode(Width, Height, BitDepth, SDL_ANYFORMAT|SDL_DOUBLEBUF);

And then add SDL_Flip(Display); line to the end of main loop (gameloop.cpp):

if(Bullets.size() > 0)
{
for(iter = Bullets.begin(); iter != Bullets.end(); ++iter)
{
(*iter)->MoveUp();
(*iter)->Show();
(*iter)->CheckCollision();
}
}

SDL_Flip(Display);






Other way is use "single buffering" and use function SDL_UpdateRect(), but double buffering is bettre way so if you want to use "single buffering", you have to read SDL_UpdateRect()'s info from SDL:s manual (www.libsdl.org).



Edit. Uups, there isn't [CODE]-tag :)
Edit2: Nice character encoding problem :) Edit3: Not anymore... intresting

Share this post


Link to post
Share on other sites
Quote:
Original post by Tynnhammar
I would like to know more of the different "modes", ie what does SDL_DOUBLEBUF and the other means?

Did you read this: http://www.gamedev.net/dict/search.asp?Term=double+buffer


You can find the full list of modes from SDL's documentation: http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this