ok so i have made a bullet array and when i click the left button on the mouse the bullet get the player position and move from there, but the problem is whenever i click on the mouse it doesn't generate a new Bullet but it just remove the old one and get the player position again and move from there.
can you guys please help? thankx
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Zombie Game Alpha");
sf::Image PlayerImage, BulletImage;
sf::Sprite PlayerSprite, BulletSprite[10];
PlayerImage.LoadFromFile("player.png");
BulletImage.LoadFromFile("bullet.png");
PlayerSprite.SetImage(PlayerImage);
for(int x=0; x<=9; x++)
BulletSprite[x].SetImage(BulletImage);
PlayerSprite.SetPosition(200,200);
bool Draw=false;
int Counter=0;
while(Window.IsOpened())
{
sf::Event Event;
float ElapsedTime = Window.GetFrameTime();
if (Window.GetInput().IsKeyDown(sf::Key::W)) PlayerSprite.Move(0, -425 * ElapsedTime);
if (Window.GetInput().IsKeyDown(sf::Key::S)) PlayerSprite.Move(0, 425 * ElapsedTime);
if (Window.GetInput().IsKeyDown(sf::Key::A)) PlayerSprite.Move(-425 * ElapsedTime, 0);
if (Window.GetInput().IsKeyDown(sf::Key:)) PlayerSprite.Move(425 * ElapsedTime, 0);
while (Window.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Window.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Window.Close();
if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
{
Draw=true;
Counter++;
for(int x=0; x<=Counter; x++)
BulletSprite[x].SetPosition(PlayerSprite.GetPosition().x,PlayerSprite.GetPosition().y);
}
}
Window.Clear();
Window.Draw(PlayerSprite);
if(Draw==true)
{
for(int x=0; x<=Counter; x++)
{
BulletSprite[x].Move(200 * ElapsedTime, 0);
Window.Draw(BulletSprite[x]);
}
std::cout << Counter;
}
Window.Display();
}
}