Created snake head
This commit is contained in:
parent
2993bdefd1
commit
ca7f6db077
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,3 +30,4 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
*.json
|
||||||
|
26
src/main.cpp
26
src/main.cpp
@ -1,22 +1,40 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML\Main.hpp>
|
|
||||||
#include <SFML\Graphics.hpp>
|
#include <SFML\Graphics.hpp>
|
||||||
#include <SFML\Window.hpp>
|
|
||||||
#include <SFML\System.hpp>
|
#include <SFML\System.hpp>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int videoSizeHorizontal, videoSizeVertical;
|
int videoSizeHorizontal, videoSizeVertical;
|
||||||
videoSizeHorizontal = 1280;
|
videoSizeHorizontal = 1024;
|
||||||
videoSizeVertical = 720;
|
videoSizeVertical = 725;
|
||||||
sf::RenderWindow window(sf::VideoMode(videoSizeHorizontal, videoSizeVertical), "SnakePlusPlus");
|
sf::RenderWindow window(sf::VideoMode(videoSizeHorizontal, videoSizeVertical), "SnakePlusPlus");
|
||||||
|
sf::Time delay = sf::milliseconds(100);
|
||||||
|
|
||||||
|
sf::RectangleShape snakeHead(sf::Vector2f(25,25));
|
||||||
|
snakeHead.setFillColor(sf::Color::Green);
|
||||||
|
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
sf::Vector2f snakeHeadPosition = snakeHead.getPosition();
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
|
snakeHeadPosition.x -= 25;
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
|
snakeHeadPosition.y -= 25;
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||||
|
snakeHeadPosition.y += 25;
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||||
|
snakeHeadPosition.x += 25;
|
||||||
|
snakeHead.setPosition(snakeHeadPosition.x, snakeHeadPosition.y);
|
||||||
|
window.clear();
|
||||||
|
window.draw(snakeHead);
|
||||||
|
window.display();
|
||||||
|
sf::sleep(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user