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<List<MyObj>> Screen = new List<List<MyObj>>();
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<MyObj>());
}
//背景を追加
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);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRGF0YTsKdXNpbmcgU3lzdGVtLkRyYXdpbmc7CnVzaW5nIFN5c3RlbS5MaW5xOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLldpbmRvd3M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iAgICAgICAgICAgIHRoaXMuU2V0U3R5bGUoQ29udHJvbFN0eWxlcy5Vc2VyUGFpbnQsIHRydWUpOwogICAgICAgICAgICB0aGlzLlNldFN0eWxlKENvbnRyb2xTdHlsZXMuQWxsUGFpbnRpbmdJbldtUGFpbnQsIHRydWUpOwoKICAgICAgICAgICAgdGhpcy5Gb3JtQm9yZGVyU3R5bGUgPSBTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Gb3JtQm9yZGVyU3R5bGUuRml4ZWRUb29sV2luZG93OwogICAgICAgICAgICB0aGlzLkNsaWVudFNpemUgPSBuZXcgU2l6ZShCYXNlV2lkdGggKyA1MCAqIDIsIDQ4MCArIDUwICogMik7CiAgICAgICAgICAgIHBpYy5Eb2NrID0gRG9ja1N0eWxlLkZpbGw7ICAgICAgICAgICAKICAgICAgICAgICAgdGhpcy5Db250cm9scy5BZGQocGljKTsKCiAgICAgICAgICAgIC8v5pOs5Ly855qE44Gq44OA44OW44Or44OQ44OD44OV44KhCiAgICAgICAgICAgIGJtcFswXSA9IG5ldyBCaXRtYXAoQmFzZVdpZHRoLCBCYXNlSGVpZ2h0LCBQaXhlbEZvcm1hdC5Gb3JtYXQzMmJwcEFyZ2IpOwogICAgICAgICAgICBibXBbMV0gPSBuZXcgQml0bWFwKEJhc2VXaWR0aCwgQmFzZUhlaWdodCwgUGl4ZWxGb3JtYXQuRm9ybWF0MzJicHBBcmdiKTsKCiAgICAgICAgICAgIC8v44Kq44OW44K444Kn44Kv44OI6L+95YqgCiAgICAgICAgICAgIC8v44Os44Kk44Ok44O844Go44GX44Gm566h55CGCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgMTY7IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgU2NyZWVuLkFkZChuZXcgTGlzdDxNeU9iaj4oKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy/og4zmma/jgpLov73liqAKICAgICAgICAgICAgU2NyZWVuWzBdLkFkZCggbmV3IE15T2JqKDAsMCwgMCwgNjQwLCA0ODAsIC0xLCAwLAogICAgICAgICAgICAgICAgbmV3IExpbmVhckdyYWRpZW50QnJ1c2gobmV3IFBvaW50KDAsIDApLCBuZXcgUG9pbnQoNjM5LCA0NzkpLCBDb2xvci5ZZWxsb3dHcmVlbiwgQ29sb3IuR3JlZW4pKSk7CiAgICAgICAgICAgIFNjcmVlblswXS5BZGQoIG5ldyBNeU9iaigwLDY0MCwgMCwgNjQwLCA0ODAsIC0xLCAwLAogICAgICAgICAgICAgICAgbmV3IExpbmVhckdyYWRpZW50QnJ1c2gobmV3IFBvaW50KDAsIDApLCBuZXcgUG9pbnQoNjM5LCA0NzkpLCBDb2xvci5CbHVlLCBDb2xvci5MaWdodEJsdWUpKSk7CgogICAgICAgICAgICAvLzE1ZnBzCiAgICAgICAgICAgIHRpbWVyMS5JbnRlcnZhbCA9IChpbnQpKDEuMCAvIDYwLjAgKiAxMDAuMCk7CiAgICAgICAgICAgIHRpbWVyMS5UaWNrICs9IG5ldyBFdmVudEhhbmRsZXIodGltZXIxX1RpY2spOwogICAgICAgICAgICB0aW1lcjEuRW5hYmxlZCA9IHRydWU7CiAgICAgICAgfQogICAgICAgIC8v44Ky44O844Og44Or44O844OX44Gu5Luj44KP44KKCiAgICAgICAgdm9pZCB0aW1lcjFfVGljayhvYmplY3Qgc2VuZGVyLCBFdmVudEFyZ3MgZSkKICAgICAgICB7CiAgICAgICAgICAgIC8v44Kt44O85YWl5Yqb44Gv44OB44Kn44OD44Kv44GX44Gq44GECiAgICAgICAgICAgIHRoaXMuS2V5KCk7CgogICAgICAgICAgICAvL+eUu+mdouOCkuani+aIkOOBmeOCi+OCquODluOCuOOCp+OCr+ODiOOBmeOBueOBpuOBruenu+WLleWHpueQhgogICAgICAgICAgICB0aGlzLk9iak1vdmUoKTsKCiAgICAgICAgICAgIC8v5YWo6YOo44Gu44Kq44OW44K444Kn44Kv44OI44Gu56e75YuV44GM57WC44GI44Gf5b6M5b2T44Gf44KK5Yik5a6a44CB5raI5ruF5Yik5a6aCiAgICAgICAgICAgIHRoaXMuSGl0KCk7CgogICAgICAgICAgICB0aGlzLk9iakRyYXcoKTsKICAgICAgICB9CiAgICAgICAgLy/jgq3jg7zlhaXlipsKICAgICAgICB2b2lkIEtleSgpCiAgICAgICAgewogICAgICAgIH0KICAgICAgICAvL+WFqOOCreODo+ODqeOBruWLleOBjQogICAgICAgIHZvaWQgT2JqTW92ZSgpCiAgICAgICAgewogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IFNjcmVlbi5Db3VudDsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IFNjcmVlbltpXS5Db3VudDsgaisrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIFNjcmVlbltpXVtqXS5Nb3ZlKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgLy/lvZPjgZ/jgorliKTlrprmtojmu4XliKTlrpoKICAgICAgICB2b2lkIEhpdCgpCiAgICAgICAgewogICAgICAgIH0KICAgICAgICAvL+WFqOOCreODo+ODqeOBruaPj+eUuwogICAgICAgIHZvaWQgT2JqRHJhdygpCiAgICAgICAgewogICAgICAgICAgICB1c2luZyAoR3JhcGhpY3MgZyA9IEdyYXBoaWNzLkZyb21JbWFnZShibXBbX1NjcmVlbkJ1ZmZdKSkKICAgICAgICAgICAgLy91c2luZyAoR3JhcGhpY3MgZyA9IHRoaXMuQ3JlYXRlR3JhcGhpY3MoKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZy5GaWxsUmVjdGFuZ2xlKEJydXNoZXMuQmxhY2ssIDAsIDAsIGJtcFtfU2NyZWVuQnVmZl0uV2lkdGgsIGJtcFtfU2NyZWVuQnVmZl0uSGVpZ2h0KTsKICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgU2NyZWVuLkNvdW50OyBpKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBTY3JlZW5baV0uQ291bnQ7IGorKykKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIFNjcmVlbltpXVtqXS5EcmF3KGcpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBwaWMuSW1hZ2UgPSBibXBbX1NjcmVlbkJ1ZmZdOwogICAgICAgICAgICB0aGlzLkludmFsaWRhdGUoKTsKICAgICAgICAgICAgX1NjcmVlbkJ1ZmYgXj0gMTsKICAgICAgICB9CiAgICB9CiAgICBwdWJsaWMgY2xhc3MgTXlPYmoKICAgIHsKICAgICAgICBpbnQgX01vdmVUeXBlOwogICAgICAgIGludCBfQ291bnQ7CiAgICAgICAgZmxvYXQgX1g7CiAgICAgICAgZmxvYXQgX1k7CiAgICAgICAgZmxvYXQgX1dpZHRoOwogICAgICAgIGZsb2F0IF9IZWlnaHQ7CiAgICAgICAgZmxvYXQgX0FkZFg7CiAgICAgICAgZmxvYXQgX0FkZFk7CiAgICAgICAgTGluZWFyR3JhZGllbnRCcnVzaCBfQnJ1c2g7CiAgICAgICAgcHVibGljIE15T2JqKGludCBNb3ZlVHlwZSwKICAgICAgICAgICAgZmxvYXQgWCwgZmxvYXQgWSwKICAgICAgICAgICAgZmxvYXQgV2lkdGgsIGZsb2F0IEhlaWdodCwKICAgICAgICAgICAgZmxvYXQgQWRkWCwgZmxvYXQgQWRkWSwKICAgICAgICAgICAgTGluZWFyR3JhZGllbnRCcnVzaCBCcnVzaCkKICAgICAgICB7CiAgICAgICAgICAgIF9Nb3ZlVHlwZSA9IE1vdmVUeXBlOwogICAgICAgICAgICBfQ291bnQgPSAwOwogICAgICAgICAgICBfWCA9IFg7CiAgICAgICAgICAgIF9ZID0gWTsKICAgICAgICAgICAgX1dpZHRoID0gV2lkdGg7CiAgICAgICAgICAgIF9IZWlnaHQgPSBIZWlnaHQ7CiAgICAgICAgICAgIF9BZGRYID0gQWRkWDsKICAgICAgICAgICAgX0FkZFkgPSBBZGRZOwogICAgICAgICAgICBfQnJ1c2ggPSBCcnVzaDsKICAgICAgICB9CiAgICAgICAgcHVibGljIHZvaWQgTW92ZSgpCiAgICAgICAgewogICAgICAgICAgICBzd2l0Y2ggKF9Nb3ZlVHlwZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgICAgIF9YICs9IF9BZGRYOwogICAgICAgICAgICAgICAgICAgIF9ZICs9IF9BZGRZOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBfQ291bnQrKzsKICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIHB1YmxpYyB2b2lkIERyYXcoR3JhcGhpY3MgZykKICAgICAgICB7CiAgICAgICAgICAgIGcuRmlsbFJlY3RhbmdsZShfQnJ1c2gsIF9YLCBfWSwgX1dpZHRoLCBfSGVpZ2h0KTsKICAgICAgICB9CiAgICB9Cn0K