2
« on: March 31, 2011, 07:00:56 pm »
int main()
{
sf::RenderWindow WMain(sf::VideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,WINDOW_BPP),"Title");
WMain.SetFramerateLimit(100);
sf::Image IBackGround;
IBackGround.LoadFromFile("C:\\Users\\Administrator\\Documents\\Visual Studio 2008\\Projects\\AsteroidsLG\\Release\\background.png");
sf::Sprite BackGround(IBackGround);BackGround.Resize(WINDOW_WIDTH,WINDOW_HEIGHT);
sf::Shape Hull = sf::Shape::Rectangle(0,0,HULL_W,HULL_H,sf::Color(255,255,0),1);
Hull.Move(300,300);
sf::Shape Weapon = sf::Shape::Line(0,0,WEAPON0_W,WEAPON0_H,WEAPON0_T,sf::Color(255,0,0));
const sf::Input &gInput = WMain.GetInput();
float ElTime = 0;
sf::Clock gClock;
std::vector<sf::Shape *> Balls;
float lastShot = 1;
while(WMain.IsOpened())
{
sf::Event Event;
while(WMain.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
WMain.Close();
}
ElTime = WMain.GetFrameTime();
if(gInput.IsKeyDown(sf::Key::W))
{
Hull.Move(0,ElTime * -100);
}
if(gInput.IsKeyDown(sf::Key::A))
{
Hull.Move(ElTime * -100,0);
}
if(gInput.IsKeyDown(sf::Key::D))
{
Hull.Move(ElTime * 100,0);
}
if(gInput.IsKeyDown(sf::Key::S))
{
Hull.Move(0,ElTime*100);
}
if(gInput.IsKeyDown(sf::Key::Space))
{
lastShot = gClock.GetElapsedTime();
//if(lastShot > 1)
//{
sf::Shape *s = new sf::Shape;//::Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H,
//5,sf::Color(255,255,255),1);
s->Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H,
5,sf::Color(255,255,255),1);
Balls.push_back(s);
//}
}
WMain.Clear(sf::Color(0,220,0));
Weapon.SetPosition(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H);
WMain.Draw(BackGround);
WMain.Draw(Hull);
WMain.Draw(Weapon);
for(int i = 0;i<Balls.size();i++)
{
if(Balls[i]->GetPosition().y < WINDOW_HEIGHT || Balls[i]->GetPosition().y > 0)
{
Balls[i]->Move(0,ElTime * -150);
WMain.Draw(*(Balls[i]));
//printf("%d \n",Balls.size());
}
else if(Balls[i]->GetPosition().y > WINDOW_HEIGHT || Balls[i]->GetPosition().y < 0)
{
delete Balls[i];
}
}
WMain.Display();
}
return EXIT_SUCCESS;
}
I try to make the shape an vector array so that if its out of the screen it doesn't take memory.But it just doesn't render it.
What could be the problem ?