Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<Siv3D.hpp>
- #include<algorithm>
- typedef std::pair<double, double> point;
- typedef point size;
- double& x(point& p)
- {
- return p.first;
- }
- double& y(point& p)
- {
- return p.second;
- }
- template<class T>void clamp(T& v, T const& min, T const& max)
- {
- if (v < min)
- {
- v = min;
- }
- if (v > max)
- {
- v = max;
- }
- }
- double ball_scale = 0.05;
- double figure_scale = 0.2;
- double default_angle = 0.08;
- double soccer_speed = 12.0;
- double hand_speed = 11.0;
- double soccer_angle = 0.06;
- double hand_angle = 0.005;
- int way = 25;
- int curves_count = 25;
- int soccer_count = 15;
- int hand_count = 7;
- int figure_max_x = 280;
- int figure_max_y = 300;
- int figure_min_x = 200;
- int figure_min_y = 220;
- double kumitaisou_scale = .08;
- template<class T, class Pred>void remove_if(std::vector<T>& vec, Pred pred)
- {
- auto result = std::remove_if(vec.begin(), vec.end(), pred);
- vec.erase(result, vec.end());
- }
- class ball
- {
- std::reference_wrapper<s3d::Texture> texture;
- point pos;
- size speed;
- double angle;
- int count;
- public:
- ball(s3d::Texture& texture_, point point_, size speed_, double angle_, int count_) :
- texture(std::ref(texture_)),
- pos(point_),
- speed(speed_),
- angle(angle_),
- count(count_)
- {
- }
- bool run()
- {
- if (count)
- {
- --count;
- double x_ = x(speed)*cos(angle) - y(speed)*sin(angle);
- double y_ = x(speed)*sin(angle) + y(speed)*cos(angle);
- x(speed) = x_;
- y(speed) = y_;
- }
- x(pos) += x(speed);
- y(pos) += y(speed);
- texture.get().scale(ball_scale).drawAt(x(pos), y(pos));
- return
- (x(pos) < -texture.get().size.x*ball_scale) ||
- (y(pos) < -texture.get().size.y*ball_scale) ||
- (x(pos) > 480 + texture.get().size.x*ball_scale) ||
- (y(pos) > 640 + texture.get().size.x*ball_scale);
- }
- };
- class goal_figure
- {
- s3d::Point pos;
- std::vector<ball> balls;
- s3d::Image soccer_ball;
- s3d::Texture soccer_texture;
- s3d::Image hand_ball;
- s3d::Texture hand_texture;
- int soccer_next;
- int hand_next;
- double now_soccer_angle;
- double now_hand_angle;
- s3d::Image figure;
- s3d::Texture figure_texture;
- public:
- goal_figure(s3d::Point pos_, s3d::Image&& soccer, s3d::Image&& hand, s3d::Image&& fig):
- pos(pos_),
- balls{},
- soccer_ball(std::move(soccer)),
- soccer_texture(soccer_ball),
- hand_ball(std::move(hand)),
- hand_texture(hand_ball),
- soccer_next(soccer_count),
- hand_next(hand_count),
- now_soccer_angle(),
- now_hand_angle(),
- figure(std::move(fig)),
- figure_texture(figure)
- {
- }
- void move()
- {
- if (s3d::RandomBool((s3d::Time::GetMillisec() % 6000) < 3000 ? .25 : .75))
- {
- ++pos.x;
- }
- else
- {
- --pos.x;
- }
- if (s3d::RandomBool((s3d::Time::GetMillisec() % 6000) < 3000 ? .25 : .75))
- {
- ++pos.y;
- }
- else
- {
- --pos.y;
- }
- clamp(pos.x, figure_min_x, figure_max_x);
- clamp(pos.y, figure_min_y, figure_max_y);
- }
- void run()
- {
- --soccer_next;
- --hand_next;
- if (soccer_next == 0)
- {
- size speed(soccer_speed, 0);
- {
- double a = now_soccer_angle;
- double x_ = x(speed)*cos(a) - y(speed)*sin(a);
- double y_ = x(speed)*sin(a) + y(speed)*cos(a);
- x(speed) = x_;
- y(speed) = y_;
- }
- double b = 2 * s3d::Math::Pi / way;
- for (int i{};i < way;++i)
- {
- balls.emplace_back(soccer_texture, point(pos.x, pos.y), speed, default_angle, curves_count);
- double x_ = x(speed)*cos(b) - y(speed)*sin(b);
- double y_ = x(speed)*sin(b) + y(speed)*cos(b);
- x(speed) = x_;
- y(speed) = y_;
- }
- soccer_next = soccer_count;
- }
- if (hand_next == 0)
- {
- {
- size speed(hand_speed, 0);
- {
- double a = now_hand_angle;
- double x_ = x(speed)*cos(a) - y(speed)*sin(a);
- double y_ = x(speed)*sin(a) + y(speed)*cos(a);
- x(speed) = x_;
- y(speed) = y_;
- }
- double b = 2 * s3d::Math::Pi / 4;
- for (int i{};i < 4;++i)
- {
- balls.emplace_back(hand_texture, point(pos.x, pos.y), speed, 0, 0);
- double x_ = x(speed)*cos(b) - y(speed)*sin(b);
- double y_ = x(speed)*sin(b) + y(speed)*cos(b);
- x(speed) = x_;
- y(speed) = y_;
- }
- }
- {
- size speed(hand_speed, 0);
- {
- double a = -now_hand_angle;
- double x_ = x(speed)*cos(a) - y(speed)*sin(a);
- double y_ = x(speed)*sin(a) + y(speed)*cos(a);
- x(speed) = x_;
- y(speed) = y_;
- }
- double b = -2 * s3d::Math::Pi / 4;
- for (int i{};i < 4;++i)
- {
- balls.emplace_back(hand_texture, point(pos.x, pos.y), speed, 0, 0);
- double x_ = x(speed)*cos(b) - y(speed)*sin(b);
- double y_ = x(speed)*sin(b) + y(speed)*cos(b);
- x(speed) = x_;
- y(speed) = y_;
- }
- }
- hand_next = hand_count;
- }
- now_soccer_angle += soccer_angle;
- now_hand_angle += hand_angle;
- if (now_soccer_angle > s3d::Math::Pi)
- {
- now_soccer_angle -= s3d::Math::Pi;
- }
- if (now_hand_angle > s3d::Math::Pi)
- {
- now_hand_angle -= s3d::Math::Pi;
- }
- remove_if(balls, [](ball& b) {return b.run();});
- move();
- figure_texture.scale(figure_scale).drawAt(pos);
- }
- auto balls_size()const
- {
- return balls.size();
- }
- };
- class kumitaisou
- {
- s3d::Point pos;
- s3d::Image image;
- s3d::Texture texture;
- public:
- kumitaisou(s3d::Image&& i) :
- pos(240, 560),
- image(std::move(i)),
- texture(image)
- {
- }
- void run()
- {
- if (s3d::Input::KeyLeft.pressed)
- {
- --pos.x;
- }
- if (s3d::Input::KeyRight.pressed)
- {
- ++pos.x;
- }
- if (s3d::Input::KeyUp.pressed)
- {
- --pos.y;
- }
- if (s3d::Input::KeyDown.pressed)
- {
- ++pos.y;
- }
- texture.scale(kumitaisou_scale).drawAt(pos);
- }
- };
- void Main()
- {
- const s3d::Font font{ 12,s3d::Typeface::Regular,s3d::FontStyle::Regular };
- bool print = true;
- int flag = 0;
- bool pro = true;
- s3d::Window::Resize(480, 640);
- font.changeOutlineStyle(s3d::TextOutlineStyle(s3d::Palette::Black, s3d::Palette::White, 1.0));
- goal_figure figure{
- s3d::Point(240,260),
- s3d::Image(L"soccer_ball.png"),
- s3d::Image(L"handball_ball.png"),
- s3d::Image(L"goal_figure.png") };
- kumitaisou kumitai{
- s3d::Image(L"undoukai_kumitaisou_red.png")
- };
- while (s3d::System::Update())
- {
- if (s3d::Input::KeyEnter.clicked)
- {
- print = !print;
- }
- if (s3d::Input::KeySpace.clicked)
- {
- pro = !pro;
- }
- if (s3d::Input::KeyX.clicked)
- {
- flag = (flag + 1) % 16;
- }
- if (s3d::Input::KeyS.clicked)
- {
- flag = (flag + 15) % 16;
- }
- bool z = s3d::Input::KeyZ.clicked;
- bool c = s3d::Input::KeyC.clicked;
- if (z || c)
- {
- switch (flag)
- {
- case 0:{
- ball_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 1: {
- figure_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 2: {
- default_angle += (.001)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 3: {
- soccer_speed += (.1)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 4: {
- hand_speed += (.1)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 5: {
- soccer_angle += (0.001)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 6: {
- hand_angle += (0.001)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 7: {
- way += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 8: {
- curves_count += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 9: {
- soccer_count += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 10: {
- hand_count += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 11: {
- figure_max_x += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 12: {
- figure_max_y += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 13: {
- figure_min_x += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 14: {
- figure_min_y += (static_cast<int>(c) - static_cast<int>(z));
- }break;
- case 15: {
- kumitaisou_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
- }break;
- }
- }
- kumitai.run();
- figure.run();
- if (print)
- {
- font(L"______ball_scale: ", ball_scale).draw(0, 24 * 0);
- font(L"____figure_scale: ", figure_scale).draw(0, 24 * 1);
- font(L"___default_angle: ", default_angle).draw(0, 24 * 2);
- font(L"____soccer_speed: ", soccer_speed).draw(0, 24 * 3);
- font(L"______hand_speed: ", hand_speed).draw(0, 24 * 4);
- font(L"____soccer_angle: ", soccer_angle).draw(0, 24 * 5);
- font(L"______hand_angle: ", hand_angle).draw(0, 24 * 6);
- font(L"_____________way: ", way).draw(0, 24 * 7);
- font(L"____curves_count: ", curves_count).draw(0, 24 * 8);
- font(L"____soccer_count: ", soccer_count).draw(0, 24 * 9);
- font(L"______hand_count: ", hand_count).draw(0, 24 * 10);
- font(L"____figure_max_x: ", figure_max_x).draw(0, 24 * 11);
- font(L"____figure_max_y: ", figure_max_y).draw(0, 24 * 12);
- font(L"____figure_min_x: ", figure_min_x).draw(0, 24 * 13);
- font(L"____figure_min_y: ", figure_min_y).draw(0, 24 * 14);
- font(L"kumitaisou_scale: ", kumitaisou_scale).draw(0, 24 * 15);
- }
- if(pro)
- {
- font(figure.balls_size()).drawAt(440, 596);
- font(s3d::Profiler::FPS()).drawAt(440, 620);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement