Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GameDevLab1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <SFML/Graphics.hpp>
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
- sf::CircleShape shape(100.f);
- shape.setFillColor(sf::Color::Green);
- /*//make rectangle
- sf::RectangleShape rectangle(sf::Vector2f(128.0f, 128.0f));
- rectangle.setFillColor(sf::Color::Red);
- rectangle.setPosition(320, 240);*/
- sf::Texture mushroomTexture;
- mushroomTexture.loadFromFile("Mushroom.png");
- sf::Sprite mushroom(mushroomTexture);
- sf::Vector2u size = mushroomTexture.getSize();
- mushroom.setOrigin(size.x / 2.0f, size.y / 2.0f);
- sf::Vector2f increment(0.4f, 0.4f);
- /*
- //error checking for texture, returns boolean
- sf::Texture texture;
- if (!texture.loadFromFile("filename.png")) {
- }*/
- while (window.isOpen())
- {
- //load textures
- sf::Texture texture;
- texture.loadFromFile("Mushroom.png");
- sf::Sprite sprite(texture); //give the sprite the apperance of the texture
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- if((mushroom.getPosition().x + (size.x /2) > window.getSize().x && increment.x > 0)
- || (mushroom.getPosition().x - (size.x / 2) < 0 && increment.x < 0)) {
- increment.x = increment.x; //reverse direction on x axis
- }
- if ((mushroom.getPosition().y + (size.y / 2) > window.getSize().y && increment.y > 0)
- || (mushroom.getPosition().y - (size.x / 2) < 0 && increment.y < 0)) {
- increment.y = increment.y; //reverse direction on y axis
- }
- mushroom.setPosition(mushroom.getPosition() + increment);
- window.clear(sf::Color(16, 16, 16, 255));
- window.draw(mushroom);
- //set position of rectangle
- //rectangle.setOrigin(rectangle.getSize().x / 2, rectangle.getSize().y / 2);
- //clear screen
- window.clear();
- //draw objects
- window.draw(shape); //drawing order, shape first, sprite last
- //window.draw(rectangle);
- window.draw(sprite);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement