private void frmMain_Load(object sender, EventArgs e) { imgRes = new List <Image>(); /* * imgRes.Add(Properties.Resources.shot); * imgRes.Add(Properties.Resources.player); * imgRes.Add(Properties.Resources.enemy); * imgRes.Add(Properties.Resources.crush); * imgRes.Add(Properties.Resources.explosion); */ foreach (string fn in resources) { imgRes.Add(Image.FromFile(fn)); } infShot = new infSprite(1.0f, 0.2f, imgRes[0], imgRes[3], imgRes[4]); infPlayer = new infSprite(10.0f, 0.2f, imgRes[1], imgRes[3], imgRes[4]); infEnemy = new infSprite(10.0f, 0.2f, imgRes[2], imgRes[3], imgRes[4]); sprites = new List <clsSprite>(); player = new clsPlayer(calcpos(infPlayer, 0, 0), infPlayer); sprites.Add(player); for (int j = 0; j < 3; ++j) { for (int i = 0; i < 7; ++i) { sprites.Add(new clsEnemy(calcpos(infEnemy, j + 1, i - 3), infEnemy)); } } timer1.Interval = 100; timer1.Start(); // timer1.Enabled = true; }
public clsSprite(PointF p, PointF v, infSprite inf, long life, bool vanish, bool emission) { position = new PointF(p.X, p.Y); velocity = new PointF(v.X, v.Y); acceleration = new PointF(0, 0); this.inf = inf; this.life = life; this.vanish = vanish; this.emission = emission; }
private PointF calcpos(infSprite inf, int r, int c) { float x = ClientRectangle.Width / 2.0f; float y = ClientRectangle.Height - (r + 1) * inf.img.Height; if (r > 0) { x += inf.img.Width * (1.2f + 2.2f * c - r * 2.0f / 3.0f); y -= 7 * inf.img.Height; } return(new PointF(x, y)); }
public override IEnumerable <clsShot> emit(infSprite sinf) { Size swh = new Size(sinf.img.Width, sinf.img.Height); Size ewh = wh(); float x = position.X; float y = position.Y + (ewh.Height + swh.Height) / 2.0f; PointF p = new PointF(x, y); float dx = 0; float dy = swh.Height; PointF v = new PointF(dx, dy); yield return(new clsShot(p, v, sinf)); }
public override IEnumerable <clsShot> emit(infSprite sinf) { Size swh = new Size(sinf.img.Width, sinf.img.Height); Size pwh = wh(); float x = position.X; float y = position.Y - (pwh.Height + swh.Height) / 2.0f; PointF p = new PointF(x, y); int r = swh.Height; // too short to reject crush with neighbourhood int ds = 7; // 1; to 17; // odd number int hd = ds / 2; // (i - hd) means (-hd ... 0 ... +hd) for (int i = 0; i < ds; ++i) { double ang = (double)(i - hd) / ds; //double th = Math.PI / 2.0 + 2.0 * Math.PI * ang; // circle around double th = Math.PI / 2.0 + Math.PI * ang; // half circle float dx = (float)(r * Math.Cos(th)); float dy = (float)(r * Math.Sin(th)); PointF v = new PointF(dx, -dy); yield return(new clsShot(p, v, sinf)); } }
public clsPlayer(PointF p, infSprite inf) : base(p, new PointF(0, 0), inf, -1, false, false) { }
public clsEnemy(PointF p, infSprite inf) : base(p, new PointF(0, 0), inf, -1, false, true) { }
public clsShot(PointF p, PointF v, infSprite inf) : base(p, v, inf, -1, true, false) { }
public virtual IEnumerable <clsShot> emit(infSprite inf) { // throw new IndexOutOfRangeException("emit().next"); throw new ArgumentOutOfRangeException("emit().next"); // yield return null; }