Last active
February 29, 2024 10:11
-
-
Save kenpower/c1e58cdc435785ef5ae9e6a5facd74cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _DEBUG | |
#pragma comment(lib,"sfml-graphics-d.lib") | |
#pragma comment(lib,"sfml-audio-d.lib") | |
#pragma comment(lib,"sfml-system-d.lib") | |
#pragma comment(lib,"sfml-window-d.lib") | |
#pragma comment(lib,"sfml-network-d.lib") | |
//#pragma comment(lib,"thor-d.lib") | |
#else | |
#pragma comment(lib,"sfml-graphics.lib") | |
#pragma comment(lib,"sfml-audio.lib") | |
#pragma comment(lib,"sfml-system.lib") | |
#pragma comment(lib,"sfml-window.lib") | |
#pragma comment(lib,"sfml-network.lib") | |
//#pragma comment(lib,"thor.lib") | |
#endif | |
#pragma comment(lib,"opengl32.lib") | |
#pragma comment(lib,"glu32.lib") | |
//#pragma comment(lib,"libyaml-cppmdd") | |
#include <SFML/Graphics.hpp> | |
#include <iostream> | |
#include <Windows.h> | |
#include <SFML/Graphics.hpp> | |
class DrawableShape { | |
public: | |
virtual void draw(sf::RenderWindow& window) = 0; | |
}; | |
class CircleShape : public DrawableShape { | |
private: | |
sf::CircleShape shape; | |
public: | |
CircleShape(float radius) : shape(radius) {} | |
void setup() { | |
shape.setFillColor(sf::Color::Green); | |
shape.setRadius(100.f); | |
} | |
void draw(sf::RenderWindow& window) override { | |
window.draw(shape); | |
} | |
}; | |
class Game { | |
int screenWidth = 1200; | |
int screenHeight = 800; | |
DrawableShape* shape; // Pointer to the DrawableShape interface | |
public: | |
// Constructor now accepts a DrawableShape pointer | |
Game(DrawableShape* shape) : shape(shape) {} | |
void run() { | |
sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), "SFML Application"); | |
window.setFramerateLimit(25); | |
while (window.isOpen()) { | |
sf::Event event; | |
while (window.pollEvent(event)) { | |
if (event.type == sf::Event::Closed) | |
window.close(); | |
} | |
//shape->setPosition(rand() % screenWidth, rand() % screenHeight); | |
//shape->setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255)); | |
shape->draw(window); | |
window.display(); | |
shape->draw(window); | |
} | |
} | |
}; | |
int main() { | |
CircleShape circleShape(100.f); | |
circleShape.setup(); | |
Game game(&circleShape); // Pass the CircleShape instance to the Game constructor | |
game.run(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment