Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define _CRT_SECURE_NO_WARNINGS
- //
- //#include <cstdio>
- //#include <cstdlib>
- //#include <cstdint>
- //#include <cstring>
- //
- //int main(void)
- //{
- // const size_t SUDOKU_WIDTH = 9;
- // const size_t SUDOKU_SIZE = SUDOKU_WIDTH * SUDOKU_WIDTH;
- // FILE* sudoku_file = fopen("sudoku.txt", "r+");
- // uint8_t sudoku[SUDOKU_SIZE];
- // const size_t MAX_LINE_SIZE = 25;
- // size_t i = 0;
- //
- // char line[MAX_LINE_SIZE], * p;
- //
- // while (fgets(line, MAX_LINE_SIZE, sudoku_file) != NULL)
- // {
- // p = strtok(line, " .|-\n\t");
- //
- // while (p != NULL && i < SUDOKU_SIZE)
- // {
- // sudoku[i++] = *p - '0';
- // p = strtok(NULL, ".|- ");
- // };
- // }
- //
- // for (i = 0; i < SUDOKU_SIZE; ++i)
- // {
- // printf("[%d]", (int)sudoku[i]);
- // if ((i + 1) % SUDOKU_WIDTH == 0) putchar('\n');
- //
- // fflush(stdout);
- // }
- //
- // system("PAUSE");
- // return EXIT_SUCCESS;
- //}
- int main() {
- sf::RenderWindow window(sf::VideoMode(512, 512), "feet", sf::Style::Close | sf::Style::Titlebar);
- sf::RectangleShape player(sf::Vector2f(100, 100));
- player.setFillColor(sf::Color::Red);
- player.setOrigin(50.0f, 50.0f);
- player.setPosition(100, 100);
- const float Gravity = 1;
- int groundHeight = 440;
- float moveSpeed = 1.0f, jumpSpeed = 10.0f;
- sf::Vector2f velocity(sf::Vector2f(0, 0)), position(velocity);
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- switch (event.type)
- {
- case sf::Event::Closed:
- window.close();
- break;
- }
- }
- // player.move(0, player.getPosition().y + .5f);
- /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)){
- player.move(0.5f,0.0f);
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)){
- player.move(-0.5f,0.0f);
- }*/
- /*if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
- sf::Vector2i mousePos = sf::Mouse::getPosition(window);
- player.setPosition((float)mousePos.x, (float)mousePos.y);
- }*/
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- velocity.x = moveSpeed;
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- velocity.x - moveSpeed;
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- velocity.y = -jumpSpeed;
- player.move(velocity.x, velocity.y);
- if (player.getPosition().y + player.getSize().y < groundHeight || velocity.y < 0)
- {
- velocity.y += Gravity;
- }
- else {
- player.setPosition(player.getPosition().x, groundHeight - player.getSize().y);
- velocity.y = 0;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
- window.close();
- }
- window.clear(sf::Color(150, 150, 150));
- window.draw(player);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement