public override void drawAttack(int x, int y, int targetx, int targety, ref System.Drawing.Bitmap bmap, System.Media.SoundPlayer player, ref PictureBox pictureMap, ref System.Drawing.Bitmap bmBackground, ref System.Drawing.Bitmap bmFull) { System.Threading.Thread.Sleep(150); player.SoundLocation = @"Sounds/laser1.wav"; int xmin, ymin, xmax, ymax; if (x <= targetx) { xmin = x - 5; xmax = targetx + 5; } else { xmin = targetx - 5; xmax = x + 3; } if (y <= targety) { ymin = y - 5; ymax = targety + 5; } else { ymin = targety - 5; ymax = y + 5; } Graphics g = Graphics.FromImage(bmFull); Rectangle rect; Image oldImage; rect = new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin); oldImage = bmFull.Clone(rect, bmFull.PixelFormat); Pen laserPen1 = new Pen(Color.GreenYellow, 2); player.Play(); for (int i = 0; i < 5; i++) { g.DrawLine(laserPen1, new Point(x, y), new Point(targetx + i, targety)); pictureMap.Image = bmFull; Screen_Combat.UpdateDrawing(); //System.Threading.Thread.Sleep(35); } g.DrawImage(oldImage, xmin, ymin); }
public void Move(PictureBox pictureMap, TacticSeed seed, TacticState tacticState, List <Box> completeBoxWay, int x1, int x2, int y1, int y2) { double rotateAngle; int range, dx; Graphics g = Graphics.FromImage(bmFull); int actualDeltaX0, actualDeltaY0, actualDeltaX1, actualDeltaY1; actualDeltaX0 = actualDeltaY0 = 0; int savedAngle = 0; DrawSavedImages(pictureMap, /*bmFull,*/ seed); for (int cnt = 0; cnt < completeBoxWay.Count; cnt++) { if (seed.activeShip == null) { break; } rotateAngle = FindWay.AttackAngleSearch(tacticState.cMap.boxes[completeBoxWay[cnt].id].x, tacticState.cMap.boxes[completeBoxWay[cnt].id].y, seed, tacticState); x1 = tacticState.cMap.boxes[seed.activeShip.boxId].xcenter; y1 = tacticState.cMap.boxes[seed.activeShip.boxId].ycenter; x2 = tacticState.cMap.boxes[completeBoxWay[cnt].id].xcenter; y2 = tacticState.cMap.boxes[completeBoxWay[cnt].id].ycenter; int stepLineRange = (int)Math.Sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)) * 0.35); range = (int)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); dx = range / 8; int deltax; int deltay; deltax = (x2 - x1) / 8; deltay = (y2 - y1) / 8; Image bg; Rectangle rect; int halfBoxWidth = (tacticState.cMap.boxes[0].xpoint3 - tacticState.cMap.boxes[0].xpoint2) / 2; int halfBoxHeight = (tacticState.cMap.boxes[0].ypoint6 - tacticState.cMap.boxes[0].ypoint2) / 2; //закрашиваем выделенный корабль rect = new Rectangle( seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight, halfBoxWidth + halfBoxWidth, halfBoxHeight + halfBoxHeight ); bg = bmBackground.Clone(rect, bmBackground.PixelFormat); g.DrawImage(bg, seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight); actualDeltaX1 = completeBoxWay[cnt].x - tacticState.cMap.boxes[seed.activeShip.boxId].x; actualDeltaY1 = completeBoxWay[cnt].y - tacticState.cMap.boxes[seed.activeShip.boxId].y; if (cnt > 0) { if (actualDeltaX1 != actualDeltaX0 || actualDeltaY1 != actualDeltaY0) { if (savedAngle != 0) { doShipRotate(savedAngle, -1, false, pictureMap, seed); } doShipRotate(rotateAngle, 1, false, pictureMap, seed); savedAngle = (int)rotateAngle; } } else { doShipRotate(rotateAngle, 1, false, pictureMap, seed); savedAngle = (int)rotateAngle; } for (int count1 = 0; count1 < range - 10; count1 += dx) { seed.activeShip.x += deltax; seed.activeShip.y += deltay; // запоминаем кусок картинки, на которой уже нет активного корабля rect = new Rectangle( seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight, halfBoxWidth + halfBoxWidth, halfBoxHeight + halfBoxHeight ); bg = bmFull.Clone(rect, bmFull.PixelFormat); // рисуем корабль по новым координатам g.DrawImage(seed.activeShip.objectImg, new Rectangle(seed.activeShip.x - seed.activeShip.objectImg.Width / 2, seed.activeShip.y - seed.activeShip.objectImg.Height / 2, seed.activeShip.objectImg.Width, seed.activeShip.objectImg.Height) ); pictureMap.Image = bmFull; Screen_Combat.UpdateDrawing(); //Thread.Sleep(5); g.DrawImage(bg, seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight); } seed.activeShip.moveShip(tacticState.cMap, seed.activeShip.boxId, completeBoxWay[cnt].id, 1); g.DrawImage(seed.activeShip.objectImg, new Rectangle(seed.activeShip.x - seed.activeShip.objectImg.Width / 2, seed.activeShip.y - seed.activeShip.objectImg.Height / 2, seed.activeShip.objectImg.Width, seed.activeShip.objectImg.Height)); if (cnt == completeBoxWay.Count - 1) { doShipRotate(rotateAngle, -1, true, pictureMap, seed); } actualDeltaX0 = actualDeltaX1; actualDeltaY0 = actualDeltaY1; } }