fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Drawing.Imaging;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. PictureBox pic = new PictureBox();
  21. Bitmap[] bmp = new Bitmap[2];
  22. Timer timer = new Timer();
  23. Rectangle SRect;
  24. GraphicsPath gp = new GraphicsPath();
  25. private void Form1_Load(object sender, EventArgs e)
  26. {
  27. this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  28. this.ClientSize = new Size(600, 600);
  29. pic.Dock = DockStyle.Fill;
  30. this.Controls.Add(pic);
  31.  
  32. bmp[0] = new Bitmap(600, 600, PixelFormat.Format32bppArgb);
  33. bmp[1] = new Bitmap(600, 600, PixelFormat.Format32bppArgb);
  34.  
  35. SRect = new Rectangle(0, 0, 600, 600);
  36. gp.AddEllipse(0, 0, 10, 10);
  37. pic.Click += new EventHandler(pic_Click);
  38. timer.Interval = (int)(1.0f / 30.0f * 1000.0f);
  39. timer.Tick += new EventHandler(timer_Tick);
  40. timer.Enabled = true;
  41. this.ModeSet();
  42. }
  43. void ModeSet()
  44. {
  45. this.Text = "Mode = " + Mode.ToString();
  46. allb.Clear();
  47. }
  48. int Mode = 0;
  49. void pic_Click(object sender, EventArgs e)
  50. {
  51. if (Mode == 0)
  52. {
  53. Mode = 1;
  54. }
  55. else if (Mode == 1)
  56. {
  57. Mode = 2;
  58. }
  59. else if (Mode == 2)
  60. {
  61. Mode = 0;
  62. }
  63. this.ModeSet();
  64. }
  65. int screen = 0;
  66. int SetCount = 0;
  67. List<Bullet> allb = new List<Bullet>();
  68. List<Bullet> delb = new List<Bullet>();
  69. Font stringFont = new Font(new FontFamily("メイリオ"), 20.0f);
  70. //int pppp = 0;
  71. void timer_Tick(object sender, EventArgs e)
  72. {
  73. if (Mode == 0)
  74. {
  75. }
  76. else if (Mode == 1)
  77. {
  78. //if (SetCount == 10)
  79. {
  80. //this.SetBullet(15, 5);
  81. this.SetBullet1(15, 5, SetCount);
  82. //SetCount = -1;
  83. }
  84. SetCount++;
  85. if (SetCount >= 15) SetCount = 0;
  86. //pppp++;
  87. }
  88. else if (Mode == 2)
  89. {
  90. //if (SetCount == 10)
  91. {
  92. //this.SetBullet(30, 5);
  93. this.SetBullet1(30, 5, SetCount);
  94. //SetCount = -1;
  95. }
  96. SetCount++;
  97. if (SetCount >= 30) SetCount = 0;
  98. //pppp++;
  99. }
  100. using (Graphics g = Graphics.FromImage(bmp[screen]))
  101. {
  102. g.FillRectangle(Brushes.White, SRect);
  103. Matrix m = new Matrix();
  104. foreach (Bullet b in allb)
  105. {
  106. if (!b.Move())
  107. {
  108. m.Translate(b.Lx, b.Ly);
  109. g.Transform = m;
  110. g.FillPath(Brushes.Blue, gp);
  111. m.Reset();
  112. g.Transform = m;
  113. }
  114. else
  115. {
  116. delb.Add(b);
  117. }
  118. }
  119. g.DrawString("Bullet = " + allb.Count.ToString(),
  120. stringFont, Brushes.Black, 10.0f, 10.0f);
  121. }
  122. pic.Image = bmp[screen];
  123. screen ^= 1;
  124. foreach (Bullet b in delb)
  125. {
  126. allb.Remove(b);
  127. }
  128. delb.Clear();
  129. }
  130. void SetBullet(int Num, double Vec)
  131. {
  132. if (Num < 10) Num = 10;
  133. if (Num > 360) Num = 360;
  134. double Angle = Math.PI * (360.0 / Num) /180.0;
  135. for (int i = 0; i < Num; i++)
  136. {
  137. Bullet b = new Bullet();
  138. b.DeleteTime = 100;
  139. b.Lx = 300;
  140. b.Ly = 300;
  141. b.Vx = (float)(Vec * Math.Cos(Angle * i));
  142. b.Vy = (float)(Vec * Math.Sin(Angle * i));
  143. //x' = x * cosθ - y * sinθ
  144. //y' = x * sinθ + y * cosθ
  145. //↓
  146. //x = v * cosθ
  147. //y = v * sinθ
  148. allb.Add(b);
  149. }
  150. }
  151. void SetBullet1(int Num, double Vec,int i)
  152. {
  153. if (Num < 10) Num = 10;
  154. if (Num > 360) Num = 360;
  155. double Angle = Math.PI * (360.0 / Num) / 180.0;
  156. //for (int i = 0; i < Num; i++)
  157. {
  158. Bullet b = new Bullet();
  159. b.DeleteTime = 100;
  160. b.Lx = 300;
  161. b.Ly = 300;
  162. b.Vx = (float)(Vec * Math.Cos(Angle * i));
  163. b.Vy = (float)(Vec * Math.Sin(Angle * i));
  164. //x' = x * cosθ - y * sinθ
  165. //y' = x * sinθ + y * cosθ
  166. //↓
  167. //x = v * cosθ
  168. //y = v * sinθ
  169. allb.Add(b);
  170. }
  171. }
  172. }
  173. public class Bullet
  174. {
  175. public float Lx { get; set; }
  176. public float Ly { get; set; }
  177. public Size Size { get; set; }
  178. public float Vx { get; set; }
  179. public float Vy { get; set; }
  180. public int DeleteTime { get; set; }
  181. public bool Move()
  182. {
  183. this.Lx += Vx;
  184. this.Ly += Vy;
  185. DeleteTime--;
  186. if (DeleteTime < 0) return true;
  187. return false;
  188. }
  189. }
  190. }
  191.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty