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.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Drawing.Drawing2D;
  10. using System.Drawing.Imaging;
  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. Timer timer1 = new Timer();
  22. List<List<MyObj>> Screen = new List<List<MyObj>>();
  23. const int BaseWidth = 640;
  24. const int BaseHeight = 480;
  25. const int BaseMargin = 50;
  26. //Size BaseSize = new Size(BaseWidth + BaseMargin * 2, BaseHeight + BaseMargin * 2);
  27. //ダブルバッファ
  28. Bitmap[] bmp = new Bitmap[2];
  29. //バッファ切り替え用
  30. int _ScreenBuff = 0;
  31. private void Form1_Load(object sender, EventArgs e)
  32. {
  33. this.SetStyle(ControlStyles.DoubleBuffer, true);
  34. this.SetStyle(ControlStyles.UserPaint, true);
  35. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  36.  
  37. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  38. this.ClientSize = new Size(BaseWidth + 50 * 2, 480 + 50 * 2);
  39. pic.Dock = DockStyle.Fill;
  40. this.Controls.Add(pic);
  41.  
  42. //擬似的なダブルバッファ
  43. bmp[0] = new Bitmap(BaseWidth, BaseHeight, PixelFormat.Format32bppArgb);
  44. bmp[1] = new Bitmap(BaseWidth, BaseHeight, PixelFormat.Format32bppArgb);
  45.  
  46. //オブジェクト追加
  47. //レイヤーとして管理
  48. for (int i = 0; i < 16; i++)
  49. {
  50. Screen.Add(new List<MyObj>());
  51. }
  52. //背景を追加
  53. Screen[0].Add( new MyObj(0,0, 0, 640, 480, -1, 0,
  54. new LinearGradientBrush(new Point(0, 0), new Point(639, 479), Color.YellowGreen, Color.Green)));
  55. Screen[0].Add( new MyObj(0,640, 0, 640, 480, -1, 0,
  56. new LinearGradientBrush(new Point(0, 0), new Point(639, 479), Color.Blue, Color.LightBlue)));
  57.  
  58. //15fps
  59. timer1.Interval = (int)(1.0 / 60.0 * 100.0);
  60. timer1.Tick += new EventHandler(timer1_Tick);
  61. timer1.Enabled = true;
  62. }
  63. //ゲームループの代わり
  64. void timer1_Tick(object sender, EventArgs e)
  65. {
  66. //キー入力はチェックしない
  67. this.Key();
  68.  
  69. //画面を構成するオブジェクトすべての移動処理
  70. this.ObjMove();
  71.  
  72. //全部のオブジェクトの移動が終えた後当たり判定、消滅判定
  73. this.Hit();
  74.  
  75. this.ObjDraw();
  76. }
  77. //キー入力
  78. void Key()
  79. {
  80. }
  81. //全キャラの動き
  82. void ObjMove()
  83. {
  84. for (int i = 0; i < Screen.Count; i++)
  85. {
  86. for (int j = 0; j < Screen[i].Count; j++)
  87. {
  88. Screen[i][j].Move();
  89. }
  90. }
  91. }
  92. //当たり判定消滅判定
  93. void Hit()
  94. {
  95. }
  96. //全キャラの描画
  97. void ObjDraw()
  98. {
  99. using (Graphics g = Graphics.FromImage(bmp[_ScreenBuff]))
  100. //using (Graphics g = this.CreateGraphics())
  101. {
  102. g.FillRectangle(Brushes.Black, 0, 0, bmp[_ScreenBuff].Width, bmp[_ScreenBuff].Height);
  103. for (int i = 0; i < Screen.Count; i++)
  104. {
  105. for (int j = 0; j < Screen[i].Count; j++)
  106. {
  107. Screen[i][j].Draw(g);
  108. }
  109. }
  110. }
  111. pic.Image = bmp[_ScreenBuff];
  112. this.Invalidate();
  113. _ScreenBuff ^= 1;
  114. }
  115. }
  116. public class MyObj
  117. {
  118. int _MoveType;
  119. int _Count;
  120. float _X;
  121. float _Y;
  122. float _Width;
  123. float _Height;
  124. float _AddX;
  125. float _AddY;
  126. LinearGradientBrush _Brush;
  127. public MyObj(int MoveType,
  128. float X, float Y,
  129. float Width, float Height,
  130. float AddX, float AddY,
  131. LinearGradientBrush Brush)
  132. {
  133. _MoveType = MoveType;
  134. _Count = 0;
  135. _X = X;
  136. _Y = Y;
  137. _Width = Width;
  138. _Height = Height;
  139. _AddX = AddX;
  140. _AddY = AddY;
  141. _Brush = Brush;
  142. }
  143. public void Move()
  144. {
  145. switch (_MoveType)
  146. {
  147. case 0:
  148. _X += _AddX;
  149. _Y += _AddY;
  150. break;
  151. case 1:
  152. break;
  153. case 2:
  154. break;
  155. default:
  156. break;
  157. }
  158. _Count++;
  159.  
  160. }
  161. public void Draw(Graphics g)
  162. {
  163. g.FillRectangle(_Brush, _X, _Y, _Width, _Height);
  164. }
  165. }
  166. }
  167.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty