Loading OpenSpace.cpp +62 −3 Original line number Diff line number Diff line #include <iostream> #include "OpenSpace.h" OpenSpace::OpenSpace() Loading @@ -10,7 +11,7 @@ OpenSpace::OpenSpace() void OpenSpace::set_main_star_position() { Star s; for (int i = 0; i < 5000; ++i) for (int i = 0; i < 1000; ++i) { int x, y; x = rand() % 2560; Loading @@ -25,16 +26,52 @@ void OpenSpace::set_main_star_position() stars.push_back(s); } } //center 640 360 void OpenSpace::set_star_position() { for (int i = 0; i < stars.size(); ++i) { if (on_screen(stars[i].star_position_x, stars[i].star_position_y)) { move_stars(stars[i].star_position_x, stars[i].star_position_y, i); } } } // void OpenSpace::move_stars(float x, float y, int star_num) { if (star_num == 5001) { x *=3; y *=3; for (int i = 0; i < stars.size(); ++i) { stars[i].star_position_x += x; stars[i].star_position_y += y; } } //x /= 1.7; // float max = (x > y)? x : y; // float min = // if (x > y) // { // float step = x/y; // x = step; // ++y; // } // if (x < y) // { // float step = y/x; // y = step; // ++x; // } // x -= 0.001; // y -= 0.001; // stars[star_num].star_position_x = x; // stars[star_num].star_position_y = y; } void OpenSpace::draw_star(sf::RenderWindow &win) Loading @@ -46,7 +83,7 @@ void OpenSpace::draw_star(sf::RenderWindow &win) } } bool OpenSpace::on_screen(int x, int y) bool OpenSpace::on_screen(float &x, float &y) { if (x < 0 || x > 1280) return false; Loading @@ -55,4 +92,26 @@ bool OpenSpace::on_screen(int x, int y) return true; } void OpenSpace::move_all_stars(int movestars) { std::cout << movestars; switch (movestars) { case 0: move_stars(1,0,5001); break; case 22: move_stars(0,1,5001); break; case 3: move_stars(-1,0,5001); break; case 18: move_stars(0,-1,5001); break; } } OpenSpace.h +4 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <vector> #include <SFML/Graphics.hpp> enum MOVESTARS {UP = 22, DOWN = 18, LEFT = 0, RIGHT = 3}; struct Star { Loading @@ -21,8 +22,10 @@ public: OpenSpace(); void add_star(); void remove_star(); bool on_screen(int x, int y); bool on_screen(float &x, float &y); void set_main_star_position(); void move_stars(float x, float y, int star_num = 0); void move_all_stars(int movestars); void set_star_position(); void set_speed(); int get_star_count(); Loading ScreenController.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ void ScreenController::handleEvent(sf::Event &event) if(event.type == sf::Event::KeyPressed) { int key = event.key.code; std::cout << key << "\n"; std::cout << key; space.move_all_stars(key); } } main.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ int main() while (window.isOpen()) { sf::Event event; Loading @@ -26,8 +24,10 @@ int main() if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed) { ctrl.handleEvent(event); } } window.clear(sf::Color::Black); falcon.draw_falcon(window); //наисовать звёзды Loading Loading
OpenSpace.cpp +62 −3 Original line number Diff line number Diff line #include <iostream> #include "OpenSpace.h" OpenSpace::OpenSpace() Loading @@ -10,7 +11,7 @@ OpenSpace::OpenSpace() void OpenSpace::set_main_star_position() { Star s; for (int i = 0; i < 5000; ++i) for (int i = 0; i < 1000; ++i) { int x, y; x = rand() % 2560; Loading @@ -25,16 +26,52 @@ void OpenSpace::set_main_star_position() stars.push_back(s); } } //center 640 360 void OpenSpace::set_star_position() { for (int i = 0; i < stars.size(); ++i) { if (on_screen(stars[i].star_position_x, stars[i].star_position_y)) { move_stars(stars[i].star_position_x, stars[i].star_position_y, i); } } } // void OpenSpace::move_stars(float x, float y, int star_num) { if (star_num == 5001) { x *=3; y *=3; for (int i = 0; i < stars.size(); ++i) { stars[i].star_position_x += x; stars[i].star_position_y += y; } } //x /= 1.7; // float max = (x > y)? x : y; // float min = // if (x > y) // { // float step = x/y; // x = step; // ++y; // } // if (x < y) // { // float step = y/x; // y = step; // ++x; // } // x -= 0.001; // y -= 0.001; // stars[star_num].star_position_x = x; // stars[star_num].star_position_y = y; } void OpenSpace::draw_star(sf::RenderWindow &win) Loading @@ -46,7 +83,7 @@ void OpenSpace::draw_star(sf::RenderWindow &win) } } bool OpenSpace::on_screen(int x, int y) bool OpenSpace::on_screen(float &x, float &y) { if (x < 0 || x > 1280) return false; Loading @@ -55,4 +92,26 @@ bool OpenSpace::on_screen(int x, int y) return true; } void OpenSpace::move_all_stars(int movestars) { std::cout << movestars; switch (movestars) { case 0: move_stars(1,0,5001); break; case 22: move_stars(0,1,5001); break; case 3: move_stars(-1,0,5001); break; case 18: move_stars(0,-1,5001); break; } }
OpenSpace.h +4 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <vector> #include <SFML/Graphics.hpp> enum MOVESTARS {UP = 22, DOWN = 18, LEFT = 0, RIGHT = 3}; struct Star { Loading @@ -21,8 +22,10 @@ public: OpenSpace(); void add_star(); void remove_star(); bool on_screen(int x, int y); bool on_screen(float &x, float &y); void set_main_star_position(); void move_stars(float x, float y, int star_num = 0); void move_all_stars(int movestars); void set_star_position(); void set_speed(); int get_star_count(); Loading
ScreenController.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ void ScreenController::handleEvent(sf::Event &event) if(event.type == sf::Event::KeyPressed) { int key = event.key.code; std::cout << key << "\n"; std::cout << key; space.move_all_stars(key); } }
main.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ int main() while (window.isOpen()) { sf::Event event; Loading @@ -26,8 +24,10 @@ int main() if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed) { ctrl.handleEvent(event); } } window.clear(sf::Color::Black); falcon.draw_falcon(window); //наисовать звёзды Loading