I'm relatively new to C++ and coding in general so I'm trying to make a basic Snake game to improve, I have a version of it working using ASCII characters instead of real graphics so I thought I would try SFML to make it look better. This is the code I wrote that uses SFML:
void Board::printBoard(sf::RenderWindow& window) {
for (int y = 0; y < Board::sizeOfBoardY; y++) {
for (int x = 0; x< Board::sizeOfBoardX; x++) {
//window.clear();
if (board[x][y] == 5) {
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(10, 10));
rectangle.setFillColor(sf::Color::Red);
rectangle.setPosition(x * 10, y * 10);
window.draw(rectangle);
}
else if (board[x][y] == 0) {
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(10, 10));
rectangle.setFillColor(sf::Color::White);
rectangle.setPosition(x * 10, y * 10);
window.draw(rectangle);
}
else if (board[x][y] == 9) {
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(10, 10));
rectangle.setFillColor(sf::Color::Black);
rectangle.setPosition(x * 10, y * 10);
window.draw(rectangle);
}
else {
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(10, 10));
rectangle.setFillColor(sf::Color::Green);
rectangle.setPosition(x * 10, y * 10);
window.draw(rectangle);
}
window.display();
}
}
}
It should produce a square with a black border and a white center, that you can move the snake around in and get the little red dots to grow the snake. However at the moment there are black lines appearing in the inbetween the white:
http://tinypic.com/view.php?pic=zlvp10&s=8#.U8_GS-kg9jEThe whole thing also shakes within the window and I cant figure out why, link to video of shaking below:
Any help would be greatly appreciated,
Thanks.