using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Drawing.Imaging; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } PictureBox pic = new PictureBox(); Timer timer1 = new Timer(); List> Screen = new List>(); const int BaseWidth = 640; const int BaseHeight = 480; const int BaseMargin = 50; //Size BaseSize = new Size(BaseWidth + BaseMargin * 2, BaseHeight + BaseMargin * 2); //ダブルバッファ Bitmap[] bmp = new Bitmap[2]; //バッファ切り替え用 int _ScreenBuff = 0; private void Form1_Load(object sender, EventArgs e) { this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.ClientSize = new Size(BaseWidth + 50 * 2, 480 + 50 * 2); pic.Dock = DockStyle.Fill; this.Controls.Add(pic); //擬似的なダブルバッファ bmp[0] = new Bitmap(BaseWidth, BaseHeight, PixelFormat.Format32bppArgb); bmp[1] = new Bitmap(BaseWidth, BaseHeight, PixelFormat.Format32bppArgb); //オブジェクト追加 //レイヤーとして管理 for (int i = 0; i < 16; i++) { Screen.Add(new List()); } //背景を追加 Screen[0].Add( new MyObj(0,0, 0, 640, 480, -1, 0, new LinearGradientBrush(new Point(0, 0), new Point(639, 479), Color.YellowGreen, Color.Green))); Screen[0].Add( new MyObj(0,640, 0, 640, 480, -1, 0, new LinearGradientBrush(new Point(0, 0), new Point(639, 479), Color.Blue, Color.LightBlue))); //15fps timer1.Interval = (int)(1.0 / 60.0 * 100.0); timer1.Tick += new EventHandler(timer1_Tick); timer1.Enabled = true; } //ゲームループの代わり void timer1_Tick(object sender, EventArgs e) { //キー入力はチェックしない this.Key(); //画面を構成するオブジェクトすべての移動処理 this.ObjMove(); //全部のオブジェクトの移動が終えた後当たり判定、消滅判定 this.Hit(); this.ObjDraw(); } //キー入力 void Key() { } //全キャラの動き void ObjMove() { for (int i = 0; i < Screen.Count; i++) { for (int j = 0; j < Screen[i].Count; j++) { Screen[i][j].Move(); } } } //当たり判定消滅判定 void Hit() { } //全キャラの描画 void ObjDraw() { using (Graphics g = Graphics.FromImage(bmp[_ScreenBuff])) //using (Graphics g = this.CreateGraphics()) { g.FillRectangle(Brushes.Black, 0, 0, bmp[_ScreenBuff].Width, bmp[_ScreenBuff].Height); for (int i = 0; i < Screen.Count; i++) { for (int j = 0; j < Screen[i].Count; j++) { Screen[i][j].Draw(g); } } } pic.Image = bmp[_ScreenBuff]; this.Invalidate(); _ScreenBuff ^= 1; } } public class MyObj { int _MoveType; int _Count; float _X; float _Y; float _Width; float _Height; float _AddX; float _AddY; LinearGradientBrush _Brush; public MyObj(int MoveType, float X, float Y, float Width, float Height, float AddX, float AddY, LinearGradientBrush Brush) { _MoveType = MoveType; _Count = 0; _X = X; _Y = Y; _Width = Width; _Height = Height; _AddX = AddX; _AddY = AddY; _Brush = Brush; } public void Move() { switch (_MoveType) { case 0: _X += _AddX; _Y += _AddY; break; case 1: break; case 2: break; default: break; } _Count++; } public void Draw(Graphics g) { g.FillRectangle(_Brush, _X, _Y, _Width, _Height); } } }