Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Audio.hpp>
- #include <SFML/Graphics.hpp>
- #include <SFML/System.hpp>
- #include <SFML/Window.hpp>
- #include <iostream>
- #include <vector>
- using namespace sf;
- using namespace std;
- int longueur = 1280;
- int hauteur = 720;
- int e = 1601;
- RenderWindow window(VideoMode(longueur, hauteur, 32), "chiass");
- class Particule {
- public:
- Particule(int x, int y, int charge = 0, int mass = 10000, int radius = 30, int vx = 0, int vy = 0, int ax = 0, int ay = 0) :
- q(charge), m(mass), vx(vx), vy(vy), x(x), y(y), ax(ax), ay(ay), radius(radius)
- {
- circle.setRadius(radius);
- circle.setPointCount(500);
- circle.setFillColor(Color(255, 99, 71));
- circle.setOrigin(radius, radius);
- circle.setPosition(x, y);
- /*const char* name;
- name = __func__;
- cout << name << endl;*/
- }
- void PrintInfo() {
- cout << "Mass = " << (*this).m << endl;
- cout << "Charge = " << (*this).q << endl;
- cout << "X position = " << (*this).x << endl;
- cout << "Y position = " << (*this).y << endl;
- cout << "Vx = " << (*this).vx << endl;
- cout << "Vy = " << (*this).vy << endl;
- cout << "Ax = " << (*this).ax << endl;
- cout << "Ay = " << (*this).ay << endl;
- }
- vector<int> infos() {
- vector <int> infos = {x, y, q, m, radius, vx, vy, ax, ay};
- return infos;
- };
- template <class T>
- void SetAcceleration(T ax, T ay) {
- (*this).ax = ax;
- (*this).ay = ay;
- }
- template <class T>
- void SetVitesse(T vx, T vy) {
- (*this).vx = vx;
- (*this).vy = vy;
- }
- void changeV() {
- vx += ax;
- vy += ay;
- }
- void changeXY() {
- x += vx;
- y += vy;
- }
- void update() {
- changeV();
- if (vx > 1) {
- vx = 1;
- }
- if (vy > 1) {
- vy = 1;
- }
- changeXY();
- if(x - radius<0) {
- x = radius;
- ax *= -1;
- vx *= -1;
- }
- if (x +radius> longueur) {
- x = longueur- radius;
- ax *= -1;
- vx *= -1;
- }
- if (y - radius< 0) {
- y = radius;
- ay *= -1;
- vy *= -1;
- }
- if (y + radius > hauteur) {
- y = hauteur - radius;
- ay *= -1;
- vy *= -1;
- }
- circle.setPosition(Vector2f(x, y));
- window.draw(circle);
- }
- void text() {
- Font font;
- if (!font.loadFromFile("arial.ttf"))
- cout << "Merde";
- vector<int> faichier = (*this).infos();
- int x = faichier[0];
- char xs[12];
- sprintf_s(xs, "%d", x);
- Text X(xs, font, 20);
- int y = faichier[1];
- char ys[12];
- sprintf_s(ys, "%d", y);
- Text Y(ys, font, 20);
- Y.setPosition(0, 20);
- window.draw(X);
- window.draw(Y);
- }
- private:
- int q;
- int m;
- int vx;
- int vy;
- int x;
- int y;
- int ax;
- int ay;
- CircleShape circle;
- int radius;
- };
- int main()
- {
- Particule electron(0, 0, -e, 9109);
- sf::ContextSettings settings;
- settings.antialiasingLevel = 32;
- electron.SetVitesse(1.5, 1.5);
- Font font;
- if (!font.loadFromFile("arial.ttf"))
- return EXIT_FAILURE;
- CircleShape circle;
- circle.setRadius(1);
- circle.setFillColor(Color(255, 255, 255));
- circle.setPointCount(1000);
- while (window.isOpen())
- {
- vector<int> faichier = electron.infos();
- Event event;
- Clock clock;
- Text infos;
- while (window.pollEvent(event))
- {
- if (event.type == Event::Closed)
- window.close();
- }
- window.clear(Color(40, 40, 40));
- circle.setPosition(faichier[0], faichier[1]);
- electron.update();
- electron.text();
- window.draw(circle);
- window.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement