hi guys,
i'm coding a tank game and i'm stuck at the point where tank shoot bullets, below is the unit of code i used to shoot bullets i've marked up where i think my applications hanging up. Please Help
----------------------------------------------
#include <Windows.h>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <vector>
#include <thread>
using namespace sf;
using namespace std;
#define X_COL 0
#define Y_COL 1
RenderWindow window(VideoMode(600, 600, 32), "Test 32");
Texture texture;
vector<Sprite> sprite(10, Sprite(texture));
float ammo[10][2];
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
texture.loadFromFile("bullet.png");
sprite[0].setPosition(window.getSize().x / 2, window.getSize().y / 2);
sprite[0].setOrigin(texture.getSize().x / 2, texture.getSize().y / 2);
sprite[0].setRotation(360);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 2; j++)
{
ammo
[j] = -1.0f;
}
}
thread thr;
int curntRound = 0;
float angle;
while (window.isOpen())
{
Event _event;
while (window.pollEvent(_event))
{
if (_event.type == Event::Closed)
window.close();
}
if (Keyboard::isKeyPressed(Keyboard::Space))
{
ammo[curntRound][X_COL] = sprite[0].getPosition().x; // Application hang up here.
ammo[curntRound][Y_COL] = sprite[0].getPosition().y; // it only insert x y points at
// first iteration in 'ammo' array
curntRound++;
}
window.clear(Color::Black);
window.display();
}
return 0;
}
void fire()
{
for (int i = 0; i < 10; i++)
{
if (ammo[X_COL] != 1.0f && ammo[Y_COL] != -1.0f)
sprite[0].setPosition(++ammo[X_COL], ammo[Y_COL]);
window.draw(sprite[0]);
}
}