/// <summary> /// Main CTOR of bullet shape /// </summary> /// <param name="center"></param> public ShapeBullet(PointF center, ShapeShip ship) : base(center) { //this is a bullet item _eItem = eItemType.Shot; //bullet characteristics: color, radius _itemColor = Color.White; _fOpacity = 255; Radius = 6; //calculate location of initial bullet based on //the location of the center of the ship float radRotation = (float)((ship._fRotation - 90) * Math.PI / 180); float x = (float)(ship.Location.X + ship.Radius * Math.Cos(radRotation)); float y = (float)(ship.Location.Y + ship.Radius * Math.Sin(radRotation)); Location = new PointF(x, y); //manual parameters of velocity radRotation = (float)(ship._fRotation * Math.PI / 180); _fXSpeed = (float)(Math.Sin(radRotation) * (int)bulletType); _fYSpeed = (float)(Math.Cos(radRotation) * (int)bulletType * -1); //graphicpath _bulletPath = MakeBullet(Radius); _bombPath = MakeBullet(Radius * (int)eBulletType.Bomb); }
/// <summary> /// Main CTOR of this shape, link to base shape /// </summary> /// <param name="center">center of this shape</param> /// <param name="ship">current airship instance</param> public ShapeThruster(PointF center, ShapeShip ship) : base(center) { //make path _gpThruster = MakeThruster(Radius, 3); //use ship angle to calculate thruster rotation _fRotation = ship._fRotation + 90; }
/// <summary> /// Child function of async method that create a ship in specific time /// </summary> /// <param name="time">input time</param> /// <param name="size"></param> private void MakeAShip(int time, SizeF size) { //delay inside method, use stopwatch to get exact timing System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); while (sw.ElapsedMilliseconds < time) { ; } //random location Point center = new Point(ClientRectangle.Width / 2, ClientRectangle.Height / 2); lock (_oLock) { _Airship = new ShapeShip(center); _Airship.IsMarkedForDeath = false; _Thruster = new ShapeThruster(_Airship.Location, _Airship); } }