Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. #include<Siv3D.hpp>
  2. #include<algorithm>
  3.  
  4. typedef std::pair<double, double> point;
  5. typedef point size;
  6. double& x(point& p)
  7. {
  8. return p.first;
  9. }
  10. double& y(point& p)
  11. {
  12. return p.second;
  13. }
  14. template<class T>void clamp(T& v, T const& min, T const& max)
  15. {
  16. if (v < min)
  17. {
  18. v = min;
  19. }
  20. if (v > max)
  21. {
  22. v = max;
  23. }
  24. }
  25.  
  26. double ball_scale = 0.05;
  27. double figure_scale = 0.2;
  28. double default_angle = 0.08;
  29. double soccer_speed = 12.0;
  30. double hand_speed = 11.0;
  31. double soccer_angle = 0.06;
  32. double hand_angle = 0.005;
  33. int way = 25;
  34. int curves_count = 25;
  35. int soccer_count = 15;
  36. int hand_count = 7;
  37. int figure_max_x = 280;
  38. int figure_max_y = 300;
  39. int figure_min_x = 200;
  40. int figure_min_y = 220;
  41. double kumitaisou_scale = .08;
  42.  
  43. template<class T, class Pred>void remove_if(std::vector<T>& vec, Pred pred)
  44. {
  45. auto result = std::remove_if(vec.begin(), vec.end(), pred);
  46. vec.erase(result, vec.end());
  47. }
  48.  
  49. class ball
  50. {
  51. std::reference_wrapper<s3d::Texture> texture;
  52. point pos;
  53. size speed;
  54. double angle;
  55. int count;
  56. public:
  57. ball(s3d::Texture& texture_, point point_, size speed_, double angle_, int count_) :
  58. texture(std::ref(texture_)),
  59. pos(point_),
  60. speed(speed_),
  61. angle(angle_),
  62. count(count_)
  63. {
  64.  
  65. }
  66. bool run()
  67. {
  68. if (count)
  69. {
  70. --count;
  71. double x_ = x(speed)*cos(angle) - y(speed)*sin(angle);
  72. double y_ = x(speed)*sin(angle) + y(speed)*cos(angle);
  73. x(speed) = x_;
  74. y(speed) = y_;
  75. }
  76. x(pos) += x(speed);
  77. y(pos) += y(speed);
  78. texture.get().scale(ball_scale).drawAt(x(pos), y(pos));
  79. return
  80. (x(pos) < -texture.get().size.x*ball_scale) ||
  81. (y(pos) < -texture.get().size.y*ball_scale) ||
  82. (x(pos) > 480 + texture.get().size.x*ball_scale) ||
  83. (y(pos) > 640 + texture.get().size.x*ball_scale);
  84. }
  85.  
  86. };
  87.  
  88. class goal_figure
  89. {
  90. s3d::Point pos;
  91. std::vector<ball> balls;
  92. s3d::Image soccer_ball;
  93. s3d::Texture soccer_texture;
  94. s3d::Image hand_ball;
  95. s3d::Texture hand_texture;
  96. int soccer_next;
  97. int hand_next;
  98. double now_soccer_angle;
  99. double now_hand_angle;
  100. s3d::Image figure;
  101. s3d::Texture figure_texture;
  102. public:
  103. goal_figure(s3d::Point pos_, s3d::Image&& soccer, s3d::Image&& hand, s3d::Image&& fig):
  104. pos(pos_),
  105. balls{},
  106. soccer_ball(std::move(soccer)),
  107. soccer_texture(soccer_ball),
  108. hand_ball(std::move(hand)),
  109. hand_texture(hand_ball),
  110. soccer_next(soccer_count),
  111. hand_next(hand_count),
  112. now_soccer_angle(),
  113. now_hand_angle(),
  114. figure(std::move(fig)),
  115. figure_texture(figure)
  116. {
  117.  
  118. }
  119. void move()
  120. {
  121. if (s3d::RandomBool((s3d::Time::GetMillisec() % 6000) < 3000 ? .25 : .75))
  122. {
  123. ++pos.x;
  124. }
  125. else
  126. {
  127. --pos.x;
  128. }
  129. if (s3d::RandomBool((s3d::Time::GetMillisec() % 6000) < 3000 ? .25 : .75))
  130. {
  131. ++pos.y;
  132. }
  133. else
  134. {
  135. --pos.y;
  136. }
  137. clamp(pos.x, figure_min_x, figure_max_x);
  138. clamp(pos.y, figure_min_y, figure_max_y);
  139. }
  140.  
  141. void run()
  142. {
  143. --soccer_next;
  144. --hand_next;
  145. if (soccer_next == 0)
  146. {
  147. size speed(soccer_speed, 0);
  148. {
  149. double a = now_soccer_angle;
  150. double x_ = x(speed)*cos(a) - y(speed)*sin(a);
  151. double y_ = x(speed)*sin(a) + y(speed)*cos(a);
  152. x(speed) = x_;
  153. y(speed) = y_;
  154. }
  155. double b = 2 * s3d::Math::Pi / way;
  156. for (int i{};i < way;++i)
  157. {
  158. balls.emplace_back(soccer_texture, point(pos.x, pos.y), speed, default_angle, curves_count);
  159. double x_ = x(speed)*cos(b) - y(speed)*sin(b);
  160. double y_ = x(speed)*sin(b) + y(speed)*cos(b);
  161. x(speed) = x_;
  162. y(speed) = y_;
  163. }
  164. soccer_next = soccer_count;
  165. }
  166. if (hand_next == 0)
  167. {
  168. {
  169. size speed(hand_speed, 0);
  170. {
  171. double a = now_hand_angle;
  172. double x_ = x(speed)*cos(a) - y(speed)*sin(a);
  173. double y_ = x(speed)*sin(a) + y(speed)*cos(a);
  174. x(speed) = x_;
  175. y(speed) = y_;
  176. }
  177. double b = 2 * s3d::Math::Pi / 4;
  178. for (int i{};i < 4;++i)
  179. {
  180. balls.emplace_back(hand_texture, point(pos.x, pos.y), speed, 0, 0);
  181. double x_ = x(speed)*cos(b) - y(speed)*sin(b);
  182. double y_ = x(speed)*sin(b) + y(speed)*cos(b);
  183. x(speed) = x_;
  184. y(speed) = y_;
  185. }
  186. }
  187. {
  188. size speed(hand_speed, 0);
  189. {
  190. double a = -now_hand_angle;
  191. double x_ = x(speed)*cos(a) - y(speed)*sin(a);
  192. double y_ = x(speed)*sin(a) + y(speed)*cos(a);
  193. x(speed) = x_;
  194. y(speed) = y_;
  195. }
  196. double b = -2 * s3d::Math::Pi / 4;
  197. for (int i{};i < 4;++i)
  198. {
  199. balls.emplace_back(hand_texture, point(pos.x, pos.y), speed, 0, 0);
  200. double x_ = x(speed)*cos(b) - y(speed)*sin(b);
  201. double y_ = x(speed)*sin(b) + y(speed)*cos(b);
  202. x(speed) = x_;
  203. y(speed) = y_;
  204. }
  205. }
  206.  
  207. hand_next = hand_count;
  208. }
  209. now_soccer_angle += soccer_angle;
  210. now_hand_angle += hand_angle;
  211. if (now_soccer_angle > s3d::Math::Pi)
  212. {
  213. now_soccer_angle -= s3d::Math::Pi;
  214. }
  215. if (now_hand_angle > s3d::Math::Pi)
  216. {
  217. now_hand_angle -= s3d::Math::Pi;
  218. }
  219. remove_if(balls, [](ball& b) {return b.run();});
  220. move();
  221. figure_texture.scale(figure_scale).drawAt(pos);
  222. }
  223.  
  224. auto balls_size()const
  225. {
  226. return balls.size();
  227. }
  228.  
  229. };
  230.  
  231. class kumitaisou
  232. {
  233. s3d::Point pos;
  234. s3d::Image image;
  235. s3d::Texture texture;
  236. public:
  237. kumitaisou(s3d::Image&& i) :
  238. pos(240, 560),
  239. image(std::move(i)),
  240. texture(image)
  241. {
  242.  
  243. }
  244. void run()
  245. {
  246. if (s3d::Input::KeyLeft.pressed)
  247. {
  248. --pos.x;
  249. }
  250. if (s3d::Input::KeyRight.pressed)
  251. {
  252. ++pos.x;
  253. }
  254. if (s3d::Input::KeyUp.pressed)
  255. {
  256. --pos.y;
  257. }
  258. if (s3d::Input::KeyDown.pressed)
  259. {
  260. ++pos.y;
  261. }
  262. texture.scale(kumitaisou_scale).drawAt(pos);
  263. }
  264. };
  265.  
  266. void Main()
  267. {
  268. const s3d::Font font{ 12,s3d::Typeface::Regular,s3d::FontStyle::Regular };
  269. bool print = true;
  270. int flag = 0;
  271. bool pro = true;
  272. s3d::Window::Resize(480, 640);
  273. font.changeOutlineStyle(s3d::TextOutlineStyle(s3d::Palette::Black, s3d::Palette::White, 1.0));
  274.  
  275. goal_figure figure{
  276. s3d::Point(240,260),
  277. s3d::Image(L"soccer_ball.png"),
  278. s3d::Image(L"handball_ball.png"),
  279. s3d::Image(L"goal_figure.png") };
  280. kumitaisou kumitai{
  281. s3d::Image(L"undoukai_kumitaisou_red.png")
  282. };
  283.  
  284. while (s3d::System::Update())
  285. {
  286. if (s3d::Input::KeyEnter.clicked)
  287. {
  288. print = !print;
  289. }
  290. if (s3d::Input::KeySpace.clicked)
  291. {
  292. pro = !pro;
  293. }
  294. if (s3d::Input::KeyX.clicked)
  295. {
  296. flag = (flag + 1) % 16;
  297. }
  298. if (s3d::Input::KeyS.clicked)
  299. {
  300. flag = (flag + 15) % 16;
  301. }
  302. bool z = s3d::Input::KeyZ.clicked;
  303. bool c = s3d::Input::KeyC.clicked;
  304. if (z || c)
  305. {
  306. switch (flag)
  307. {
  308. case 0:{
  309. ball_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
  310. }break;
  311. case 1: {
  312. figure_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
  313. }break;
  314. case 2: {
  315. default_angle += (.001)*(static_cast<int>(c) - static_cast<int>(z));
  316. }break;
  317. case 3: {
  318. soccer_speed += (.1)*(static_cast<int>(c) - static_cast<int>(z));
  319. }break;
  320. case 4: {
  321. hand_speed += (.1)*(static_cast<int>(c) - static_cast<int>(z));
  322. }break;
  323. case 5: {
  324. soccer_angle += (0.001)*(static_cast<int>(c) - static_cast<int>(z));
  325. }break;
  326. case 6: {
  327. hand_angle += (0.001)*(static_cast<int>(c) - static_cast<int>(z));
  328. }break;
  329. case 7: {
  330. way += (static_cast<int>(c) - static_cast<int>(z));
  331. }break;
  332. case 8: {
  333. curves_count += (static_cast<int>(c) - static_cast<int>(z));
  334. }break;
  335. case 9: {
  336. soccer_count += (static_cast<int>(c) - static_cast<int>(z));
  337. }break;
  338. case 10: {
  339. hand_count += (static_cast<int>(c) - static_cast<int>(z));
  340. }break;
  341. case 11: {
  342. figure_max_x += (static_cast<int>(c) - static_cast<int>(z));
  343. }break;
  344. case 12: {
  345. figure_max_y += (static_cast<int>(c) - static_cast<int>(z));
  346. }break;
  347. case 13: {
  348. figure_min_x += (static_cast<int>(c) - static_cast<int>(z));
  349. }break;
  350. case 14: {
  351. figure_min_y += (static_cast<int>(c) - static_cast<int>(z));
  352. }break;
  353. case 15: {
  354. kumitaisou_scale += (.01)*(static_cast<int>(c) - static_cast<int>(z));
  355. }break;
  356.  
  357. }
  358. }
  359. kumitai.run();
  360. figure.run();
  361. if (print)
  362. {
  363. font(L"______ball_scale: ", ball_scale).draw(0, 24 * 0);
  364. font(L"____figure_scale: ", figure_scale).draw(0, 24 * 1);
  365. font(L"___default_angle: ", default_angle).draw(0, 24 * 2);
  366. font(L"____soccer_speed: ", soccer_speed).draw(0, 24 * 3);
  367. font(L"______hand_speed: ", hand_speed).draw(0, 24 * 4);
  368. font(L"____soccer_angle: ", soccer_angle).draw(0, 24 * 5);
  369. font(L"______hand_angle: ", hand_angle).draw(0, 24 * 6);
  370. font(L"_____________way: ", way).draw(0, 24 * 7);
  371. font(L"____curves_count: ", curves_count).draw(0, 24 * 8);
  372. font(L"____soccer_count: ", soccer_count).draw(0, 24 * 9);
  373. font(L"______hand_count: ", hand_count).draw(0, 24 * 10);
  374. font(L"____figure_max_x: ", figure_max_x).draw(0, 24 * 11);
  375. font(L"____figure_max_y: ", figure_max_y).draw(0, 24 * 12);
  376. font(L"____figure_min_x: ", figure_min_x).draw(0, 24 * 13);
  377. font(L"____figure_min_y: ", figure_min_y).draw(0, 24 * 14);
  378. font(L"kumitaisou_scale: ", kumitaisou_scale).draw(0, 24 * 15);
  379. }
  380. if(pro)
  381. {
  382. font(figure.balls_size()).drawAt(440, 596);
  383. font(s3d::Profiler::FPS()).drawAt(440, 620);
  384. }
  385.  
  386. }
  387. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement