// возвращает битмап с кораблями и косм. объектами public Bitmap DrawShips(PictureBox pictureMap, TacticSeed seed, TacticState tacticState) { Bitmap tmpBitmap = new Bitmap(pictureMap.Width, pictureMap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(tmpBitmap); for (int i = 0; i < seed.allShips.Count; i++) { //g.DrawImage(seed.allShips[i].objectImg,); g.DrawImage(seed.allShips[i].objectImg, new Rectangle(seed.allShips[i].x - seed.allShips[i].objectImg.Width / 2, seed.allShips[i].y - seed.allShips[i].objectImg.Height / 2, seed.allShips[i].objectImg.Width, seed.allShips[i].objectImg.Height)); g.DrawString(seed.allShips[i].actionsLeft.ToString(), new Font("Arial", 8.0F), Brushes.Blue, new PointF(seed.allShips[i].x + 10, seed.allShips[i].y + 26)); g.DrawString(seed.allShips[i].currentHealth.ToString(), new Font("Arial", 8.0F), Brushes.Red, new PointF(seed.allShips[i].x - 20, seed.allShips[i].y + 26)); } for (int i = 0; i < tacticState.objectManager.meteors.Count; i++) { g.DrawImage(tacticState.objectManager.meteors[i].objectImg, new Rectangle(tacticState.objectManager.meteors[i].x - seed.boxWidth / 6, tacticState.objectManager.meteors[i].y - seed.boxHeight / 6, seed.boxWidth / 3, seed.boxHeight / 3)); g.DrawString(tacticState.objectManager.meteors[i].currentHealth.ToString(), new Font("Arial", 8.0F), Brushes.Red, new PointF(tacticState.cMap.boxes[tacticState.objectManager.meteors[i].boxId].xpoint1 + 20, tacticState.cMap.boxes[tacticState.objectManager.meteors[i].boxId].ypoint1 - 25)); } return(tmpBitmap); }
// возвращает битмап с задним фоном public Bitmap DrawBackground(PictureBox pictureMap, TacticState tacticState) { Bitmap tmpBitmap; tmpBitmap = new Bitmap(pictureMap.Width, pictureMap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(tmpBitmap); g.DrawImage(Image.FromFile(@"Sprites/background/bg1.jpg"), new Rectangle(0, 0, pictureMap.Width, pictureMap.Height)); Pen boxPen = new Pen(Color.Purple, 1); for (int i = 0; i < tacticState.cMap.boxes.Count; i++) { Point[] myPointArrayHex = //точки для отрисовки шестиугольника { new Point(tacticState.cMap.boxes[i].xpoint1, tacticState.cMap.boxes[i].ypoint1), new Point(tacticState.cMap.boxes[i].xpoint2, tacticState.cMap.boxes[i].ypoint2), new Point(tacticState.cMap.boxes[i].xpoint3, tacticState.cMap.boxes[i].ypoint3), new Point(tacticState.cMap.boxes[i].xpoint4, tacticState.cMap.boxes[i].ypoint4), new Point(tacticState.cMap.boxes[i].xpoint5, tacticState.cMap.boxes[i].ypoint5), new Point(tacticState.cMap.boxes[i].xpoint6, tacticState.cMap.boxes[i].ypoint6) }; g.DrawPolygon(boxPen, myPointArrayHex); } return(tmpBitmap); }
public void DrawMeteor(TacticSeed seed, TacticState tacticState, Meteor newMeteor) { Graphics g = Graphics.FromImage(bmFull); g.DrawImage(newMeteor.objectImg, new Rectangle(newMeteor.x - seed.boxWidth / 6, newMeteor.y - seed.boxHeight / 6, seed.boxWidth / 3, seed.boxHeight / 3)); g.DrawString(newMeteor.currentHealth.ToString(), new Font("Arial", 8.0F), Brushes.Red, new PointF(tacticState.cMap.boxes[newMeteor.boxId].xpoint1 + 20, tacticState.cMap.boxes[newMeteor.boxId].ypoint1 - 25)); }
public int Attack(PictureBox pictureMap, TacticSeed seed, TacticState tacticState, Bitmap combatBitmap, System.Media.SoundPlayer player) { int ret = 0; if (seed.activeShip.actionsLeft >= seed.activeShip.equippedWeapon.energyСonsumption && seed.activeShip.equippedWeapon.shotsleft > 0) // если у корабля остались очки действий { double angle, targetx, targety; targetx = tacticState.cMap.boxes[seed.select].x; targety = tacticState.cMap.boxes[seed.select].y; angle = FindWay.AttackAngleSearch(targetx, targety, seed, tacticState); doShipRotate(angle, 1, true, pictureMap, seed); // отрисовка атаки //Thread.Sleep(150); ret = seed.activeShip.attack(tacticState.cMap, tacticState.cMap.boxes[seed.select].id, ref combatBitmap, player, ref pictureMap, ref bmBackground, ref bmFull); // возвращаем корабль в исходное положение doShipRotate(angle, -1, false, pictureMap, seed); } return(ret); }
public static double AttackAngleSearch(double targetx, double targety, TacticSeed seed, TacticState tacticState) { double angle = 0; double shipx, shipy; if (seed.activeShip != null) { shipx = tacticState.cMap.boxes[seed.activeShip.boxId].x; // координаты выделенного корабля shipy = tacticState.cMap.boxes[seed.activeShip.boxId].y; if (shipx == targetx) // избегаем деления на ноль { if (shipy > targety) { angle = -90; } else { angle = 90; } if (seed.activePlayer != 1) { angle = -angle; } } else // находим угол, на который нужно повернуть корабль (если он не равен 90 градусов) { angle = Math.Atan((targety - shipy) / (targetx - shipx)) * 180 / Math.PI; } // дальше идет коррекция, не пытайся разобраться как это работает, просто оставь как есть if (seed.activePlayer == 1) { if (shipy == targety && shipx > targetx) { angle = 180; } else if (shipx > targetx && shipy < targety) { angle += 180; } else if (shipx > targetx && shipy > targety) { angle = angle - 180; } } else if (seed.activePlayer != 1) { if (shipy == targety && shipx < targetx) { angle = 180; } else if (shipx < targetx && shipy < targety) { angle -= 180; } else if (shipx < targetx && shipy > targety) { angle += 180; } } } return(angle); }
public static Box GetNextWaybox(Box currentBox, Box baseBox, ref List <int> priority, ref List <Box> previousBoxes, TacticState tacticState) { Box nextWaybox = null; int j; for (int i = 0; i < 6; i++) { switch (priority[i]) { case Constants.MOVE_TOP: if (currentBox.y <= 1) { continue; } nextWaybox = tacticState.cMap.boxes[currentBox.id - 1]; break; case Constants.MOVE_RIGHT_TOP: if (currentBox.y == 0 || currentBox.x == tacticState.cMap.width - 1) { continue; } nextWaybox = tacticState.cMap.getBoxByCoords(currentBox.x + 1, currentBox.y - 1); break; case Constants.MOVE_RIGHT_BOTTOM: if (currentBox.x == tacticState.cMap.width - 1 || currentBox.y == tacticState.cMap.height * 2 - 1) { continue; } nextWaybox = tacticState.cMap.getBoxByCoords(currentBox.x + 1, currentBox.y + 1); break; case Constants.MOVE_BOTTOM: if (currentBox.y >= tacticState.cMap.height * 2 - 2) { continue; } nextWaybox = tacticState.cMap.boxes[currentBox.id + 1]; break; case Constants.MOVE_LEFT_BOTTOM: if (currentBox.x == 0 || currentBox.y == tacticState.cMap.height * 2 - 1) { continue; } nextWaybox = tacticState.cMap.getBoxByCoords(currentBox.x - 1, currentBox.y + 1); break; case Constants.MOVE_LEFT_TOP: if (currentBox.x == 0 || currentBox.y == 0) { continue; } nextWaybox = tacticState.cMap.getBoxByCoords(currentBox.x - 1, currentBox.y - 1); break; } //if (nextWaybox != null && nextWaybox.id != previousBox.id && nextWaybox.spaceObject == null) if (nextWaybox != null && nextWaybox.id != baseBox.id && nextWaybox.spaceObject == null) { for (j = 0; j < previousBoxes.Count; j++) { if (nextWaybox.id == previousBoxes[j].id) { break; } } if (j == previousBoxes.Count) { break; } } } if (nextWaybox.spaceObject != null) { nextWaybox = null; } return(nextWaybox); }
public static int GetBoxway(Box currentBox, Box baseBox, Box targetBox, ref List <Box> boxWay, int maxLength, int k, TacticState tacticState) { if (maxLength > 0 && (int)Math.Sqrt((targetBox.x - currentBox.x) * (targetBox.x - currentBox.x) + ((targetBox.y - currentBox.y) * (targetBox.y - currentBox.y)) * 0.35) <= maxLength) { //boxDescription.Text = "" + currentBox.id; int currentDirection = FindDirection(currentBox.x, targetBox.x, currentBox.y, targetBox.y); if (k != 0) { currentDirection = (currentDirection + k) % 6; if (currentDirection == 0) { currentDirection = 6; } } List <int> currentPriority = new List <int>(); FindPriority(currentDirection, ref currentPriority); Box nextWaybox = GetNextWaybox(currentBox, baseBox, ref currentPriority, ref boxWay, tacticState); if (nextWaybox == null) { return(-1); } boxWay.Add(nextWaybox); if (nextWaybox.id == targetBox.id) { return(0); } else { if (GetBoxway(nextWaybox, baseBox, targetBox, ref boxWay, maxLength - 1, 0, tacticState) == -1) { int i = 1; for (i = 1; i < 6; i++) { if (GetBoxway(nextWaybox, baseBox, targetBox, ref boxWay, maxLength - 1, i, tacticState) == -1) { continue; } else { return(0); } } boxWay.Remove(boxWay[boxWay.Count - 1]); //txtRedShips.Text = txtRedShips.Text + "\nоп\n"; return(-1); } else { return(0); } } } else { return(-1); } }
// отрисовывает рамку вокруг активного корабля и вражеских кораблей в зоне поражения public void DrawActiveShipFrames(PictureBox pictureMap, /*Bitmap bmFull,*/ TacticSeed seed, TacticState tacticState) { Bitmap tmpBitmap = new Bitmap(pictureMap.Width, pictureMap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmFull); Rectangle rect; // размер части изображения, которую нужно сохранить Image oldImage; // часть изображения, которую нужно сохранить rect = new Rectangle( tacticState.cMap.boxes[seed.activeShip.boxId].xpoint1, tacticState.cMap.boxes[seed.activeShip.boxId].ypoint2, tacticState.cMap.boxes[seed.activeShip.boxId].xpoint4 - tacticState.cMap.boxes[seed.activeShip.boxId].xpoint1, tacticState.cMap.boxes[seed.activeShip.boxId].ypoint6 - tacticState.cMap.boxes[seed.activeShip.boxId].ypoint2 ); oldImage = bmFull.Clone(rect, bmFull.PixelFormat); seed.savedImages.Add(new SavedImage(oldImage, tacticState.cMap.boxes[seed.activeShip.boxId].xpoint1, tacticState.cMap.boxes[seed.activeShip.boxId].ypoint2, seed.activeShip)); g.DrawEllipse(new Pen(Color.Yellow, 2), seed.activeShip.x - 27, seed.activeShip.y - 27, 54, 54); for (int shipCount = 0; shipCount < seed.allShips.Count; shipCount++) { if (seed.allShips[shipCount] != null && seed.allShips[shipCount].player != seed.activePlayer) { double x1 = tacticState.cMap.boxes[seed.activeShip.boxId].x; double y1 = tacticState.cMap.boxes[seed.activeShip.boxId].y; double x2 = tacticState.cMap.boxes[seed.allShips[shipCount].boxId].x; double y2 = tacticState.cMap.boxes[seed.allShips[shipCount].boxId].y; double range; range = Math.Sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)) * 0.35); if ((int)range <= seed.activeShip.equippedWeapon.attackRange) { rect = new Rectangle( tacticState.cMap.boxes[seed.allShips[shipCount].boxId].xpoint1, tacticState.cMap.boxes[seed.allShips[shipCount].boxId].ypoint2, tacticState.cMap.boxes[seed.allShips[shipCount].boxId].xpoint4 - tacticState.cMap.boxes[seed.allShips[shipCount].boxId].xpoint1, tacticState.cMap.boxes[seed.allShips[shipCount].boxId].ypoint6 - tacticState.cMap.boxes[seed.allShips[shipCount].boxId].ypoint2 ); oldImage = bmFull.Clone(rect, bmFull.PixelFormat); seed.savedImages.Add(new SavedImage(oldImage, tacticState.cMap.boxes[seed.allShips[shipCount].boxId].xpoint1, tacticState.cMap.boxes[seed.allShips[shipCount].boxId].ypoint2, seed.allShips[shipCount])); g.DrawEllipse(new Pen(Color.Red, 2), seed.allShips[shipCount].x - 27, seed.allShips[shipCount].y - 27, 54, 54); } } } pictureMap.Image = bmFull; }
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; } }
public void New(PictureBox pictureMap, TacticSeed seed, TacticState tacticState) { bmBackground = DrawBackground(pictureMap, tacticState); bmShips = DrawShips(pictureMap, seed, tacticState); bmFull = ImageRefrash(bmBackground, bmShips, pictureMap); }
private void SetState(TacticState state) { this.state = state; NotifyStateChanged(); }