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. void timer_Tick(object sender, EventArgs e)
  71. {
  72. if (Mode == 0)
  73. {
  74. }
  75. else if (Mode == 1)
  76. {
  77. if (SetCount == 10)
  78. {
  79. this.SetBullet(15,5);
  80. SetCount = -1;
  81. }
  82. SetCount++;
  83. }
  84. else if (Mode == 2)
  85. {
  86. if (SetCount == 10)
  87. {
  88. this.SetBullet(30,5);
  89. SetCount = -1;
  90. }
  91. SetCount++;
  92. }
  93. using (Graphics g = Graphics.FromImage(bmp[screen]))
  94. {
  95. g.FillRectangle(Brushes.White, SRect);
  96. Matrix m = new Matrix();
  97. foreach (Bullet b in allb)
  98. {
  99. if (!b.Move())
  100. {
  101. m.Translate(b.Lx, b.Ly);
  102. g.Transform = m;
  103. g.FillPath(Brushes.Blue, gp);
  104. m.Reset();
  105. g.Transform = m;
  106. }
  107. else
  108. {
  109. delb.Add(b);
  110. }
  111. }
  112. g.DrawString("Bullet = " + allb.Count.ToString(),
  113. stringFont, Brushes.Black, 10.0f, 10.0f);
  114. }
  115. pic.Image = bmp[screen];
  116. screen ^= 1;
  117. foreach (Bullet b in delb)
  118. {
  119. allb.Remove(b);
  120. }
  121. delb.Clear();
  122. }
  123. void SetBullet(int Num, double Vec)
  124. {
  125. if (Num < 10) Num = 10;
  126. if (Num > 360) Num = 360;
  127. double Angle = Math.PI * (360.0 / Num) /180.0;
  128. for (int i = 0; i < Num; i++)
  129. {
  130. Bullet b = new Bullet();
  131. b.DeleteTime = 100;
  132. b.Lx = 300;
  133. b.Ly = 300;
  134. b.Vx = (float)(Vec * Math.Cos(Angle * i));
  135. b.Vy = (float)(Vec * Math.Sin(Angle * i));
  136. //x' = x * cosθ - y * sinθ
  137. //y' = x * sinθ + y * cosθ
  138. //↓
  139. //x = v * cosθ
  140. //y = v * sinθ
  141. allb.Add(b);
  142. }
  143. }
  144. }
  145. public class Bullet
  146. {
  147. public float Lx { get; set; }
  148. public float Ly { get; set; }
  149. public Size Size { get; set; }
  150. public float Vx { get; set; }
  151. public float Vy { get; set; }
  152. public int DeleteTime { get; set; }
  153. public bool Move()
  154. {
  155. this.Lx += Vx;
  156. this.Ly += Vy;
  157. DeleteTime--;
  158. if (DeleteTime < 0) return true;
  159. return false;
  160. }
  161. }
  162. }
  163.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty