void fSystem_Shutdown() //Get''s called when the program is closing
{
delete [] cBulletSprite; //Delete the array
SDL_Quit(); //Shutdown SDL
exit(0); //Exit the program
return;
}
inline void fDrawScene()
{
if ((blPaused == false && blDead == false))
{
fDrawBGScroll(); //Inline
//Bullet stuff
for (int bulletNum = 0;bulletNum < (signed)BULLETS_MAX;bulletNum++)
{
if (cBulletSprite[bulletNum].mfGetVisible() == true)
{
cBulletSprite[bulletNum].mfDrawSprite(&cBulletBase, srfScreen);
cBulletSprite[bulletNum].mfXAdd(BULLETS_MOVEMENT);
if (cBulletSprite[bulletNum].mfGetX() > (signed)(SCREEN_WIDTH + cBulletBase.muiW))
{
cBulletSprite[bulletNum].mfNotVisible();
}
}
}
//Player stuff
cPlayerSprite.mfDrawSprite(&cPlayerBase, srfScreen);
}
SDL_Flip(srfScreen); //Update the Screen
}
inline void fAddBullet()
{
if (blFirstBullet == false)
{
if ((SDL_GetTicks() - uiLastShot) >= BULLETS_TIME_BETWEEN_SHOTS)
{
for (int bulletNum = 0;bulletNum < (signed)BULLETS_MAX;bulletNum++)
{
if (cBulletSprite[bulletNum].mfGetVisible() == false)
{
cBulletSprite[bulletNum].mfSetXY(((cPlayerSprite.mfGetX() + cPlayerBase.muiW) + cBulletBase.muiW), (cPlayerSprite.mfGetY() + (cPlayerBase.muiH / 2)));
cBulletSprite[bulletNum].mfVisible();
uiLastShot = SDL_GetTicks();
break;
}
}
}
}
else
{
for (int bulletNum = 0;bulletNum < (signed)BULLETS_MAX;bulletNum++)
{
if (cBulletSprite[bulletNum].mfGetVisible() == false)
{
cBulletSprite[bulletNum].mfSetXY(((cPlayerSprite.mfGetX() + cPlayerBase.muiW) + cBulletBase.muiW), (cPlayerSprite.mfGetY() + (cPlayerBase.muiH / 2)));
cBulletSprite[bulletNum].mfVisible();
uiLastShot = SDL_GetTicks();
break;
}
}
blFirstBullet = false;
}
}
I think that''s all you need to know, but if it isn''t tell me.
Thanks for your help.
I need help with a pointer
well as the subject tell''s i need help with a pointer...
I thought about using a vector for this to see if it would work but beside''s a couple of other thing''s I don''t know anything about vector''s so I''m not using them.
(Just for reference there is no problem if i declare it like so: CSprite cBulletSprite[BULLETS_MAX]; if i declare BULLETS_MAX, but i want to have BULLETS_MAX read in from a txt file)
the pointer is declared as CSprite *cBulletSprite;
CSprite is just a class with alot of function''s for my Sprite''s.
All of my code work''s right now, but I want to have a config file for how many Bullet''s can be on the screen at once among other thing''s.
So I read all of the data from the config file and it work''s, then I do this: cBulletSprite = new CSprite[BULLETS_MAX];
and it''s all ok, but when I start using the Sprite''s nothing work''s.
I have a boolean var mblVisible in CSprite and when I call fDrawScene() it doesn''t draw the sprite if mblVisible == false
When you hit space it call''s fAddBullet() and it set''s mblVisible to true or false.
*THE PROBLEM* is that the sprite is never Drawn onto the screen
*BULLETS_MOVEMENT is how many pixels the bullet move''s each time*
*BULLETS_TIME_BETWEEN_SHOTS is how many milliseconds to wait before the next bullet can be fired*
*SCREEN_HEIGHT/WIDTH should be easy to understand *
*SDL_GetTicks() return''s the time (in millisceonds) since the SDL Library was initialized*
*CSprite::mfNotVisible set''s the sprite''s mblVisible to false*
*CSprite::mfVisible set''s the sprite''s mblVisible to true*
*CSprite::mfToggleVisible set''s the sprite''s mblVisible to the opposite of what it is*
*CSprite::mfX/Y Add/Subtract Add''s/Subtract''s To/From the muiX/muiY var''s*
*CSprite::mfGetX/Y return''s the sprite''s muiX/muiY var''s*
*cBulletBase and cPlayerBase hold the frame''s of the sprite''s, and the height (muiH) and width (muiW), among other thing''s*
I don't know whats wrong with your code, but I will tell you how to use a vector.
If you can handle that, more vector member functions are here.
[edited by - smart_idiot on March 1, 2003 9:18:51 AM]
#include <iostream>#include <string>#include <vector>int main() { using namespace std; //vector<string> string_vector; // this will start with an empty vector vector<string> string_vector(10, "default"); // this will start with 10 strings that contain the text "default". string_vector.reserve(100); // ask the vector to reserve enough memory for 100 strings so it doesn't need create a larger array and copy everything over everytime you add something. string_vector.pop_back(); // this will remove the last string in the vector. string_vector.push_back("the end"); // this will add the string "the end" to the end of the vector. // print how many strings are in the vector. cout << "The vector contains " << string_vector.size() << " strings." << endl; // print the contents of the vector using an iterator for(vector<string>::iterator c = string_vector.begin(); c != string_vector.end(); ++c) cout << *c << endl; // print the contents of the vector using a index for(unsigned int c = 0; c < string_vector.size(); ++c) cout << string_vector[c] << endl; }
If you can handle that, more vector member functions are here.
[edited by - smart_idiot on March 1, 2003 9:18:51 AM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement