示例#1
0
        public int attack(combatMap cMap, int pointB, ref System.Drawing.Bitmap bmap, System.Media.SoundPlayer player, ref PictureBox pictureMap, ref Bitmap bmBackground, ref Bitmap bmFull)
        {
            double dmg;
            int    flag = 0;

            if (actionsLeft >= equippedWeapon.energyСonsumption && equippedWeapon.shotsleft > 0)
            {
                equippedWeapon.drawAttack(cMap.boxes[boxId].xcenter + weaponPointX, cMap.boxes[boxId].ycenter + weaponPointY,
                                          cMap.boxes[pointB].xcenter, cMap.boxes[pointB].ycenter,
                                          ref bmap, player, ref pictureMap, ref bmBackground, ref bmFull
                                          );
                Random rand = new Random();
                dmg = (sumWeapon * rand.Next(equippedWeapon.minAttackPower * 10, equippedWeapon.maxAttackPower * 10)) / 10.0;
                cMap.boxes[pointB].spaceObject.currentHealth -= dmg;
                actionsLeft -= equippedWeapon.energyСonsumption;
                equippedWeapon.shotsleft -= 1;
                if (cMap.boxes[pointB].spaceObject.currentHealth <= 0)
                {
                    cMap.clearBox(pointB, ref bmBackground, ref bmFull);
                    flag = 1;
                }

                pictureMap.Image = bmFull;
                pictureMap.Refresh();
            }
            return(flag);
        }
示例#2
0
        public void move(combatMap cMap, Bitmap bmBackground, Bitmap bmFull)
        {
            int       newx;
            int       newy;
            int       pointB;
            Rectangle rect;
            Image     bg;

            Graphics g = Graphics.FromImage(bmFull);

            int boxWidth  = (cMap.boxes[0].xpoint3 - cMap.boxes[0].xpoint2);
            int boxHeight = (cMap.boxes[0].xpoint5 - cMap.boxes[0].ypoint3);

            newx = cMap.boxes[boxId].x + xdirection;
            newy = cMap.boxes[boxId].y + ydirection;

            rect = new Rectangle(
                x - boxWidth / 2, y - boxHeight / 2,
                boxWidth, boxHeight);

            bg = bmBackground.Clone(rect, bmBackground.PixelFormat);

            g.DrawImage(bg, x - boxWidth / 2, y - boxHeight / 2);

            if (newx < 0 || newx > cMap.width - 1 ||
                newy < 0 || newy > cMap.height * 2 - 1)
            {
                cMap.boxes[boxId].spaceObject.player = -1;
                cMap.boxes[boxId].spaceObject        = null;
                boxId = -1;
            }
            else
            {
                pointB = cMap.getBoxByCoords(newx, newy).id;

                if (cMap.boxes[pointB].spaceObject == null)
                {
                    cMap.boxes[boxId].spaceObject  = null;
                    cMap.boxes[pointB].spaceObject = this;
                    boxId = cMap.boxes[pointB].id;

                    x = cMap.boxes[boxId].xcenter;
                    y = cMap.boxes[boxId].ycenter;

                    g.DrawImage(objectImg,
                                new Rectangle(x - boxWidth / 6, y - boxHeight / 6, boxWidth / 3, boxHeight / 3));
                    g.DrawString(currentHealth.ToString(), new Font("Arial", 8.0F), Brushes.Red, new PointF(cMap.boxes[boxId].xpoint1 + 20, cMap.boxes[boxId].ypoint1 - 25));
                }
                else
                {
                    rect = new Rectangle(
                        cMap.boxes[pointB].xpoint2, cMap.boxes[pointB].ypoint2,
                        boxWidth, boxHeight + 5);

                    bg = bmBackground.Clone(rect, bmBackground.PixelFormat);
                    g.DrawImage(bg, cMap.boxes[pointB].xpoint2, cMap.boxes[pointB].ypoint2);

                    cMap.boxes[pointB].spaceObject.currentHealth -= explodeDmg;

                    if (cMap.boxes[pointB].spaceObject.currentHealth <= 0)
                    {
                        cMap.clearBox(pointB, ref bmBackground, ref bmFull);
                    }

                    else
                    {
                        if (cMap.boxes[pointB].spaceObject.objectType != Constants.METEOR)
                        {
                            g.DrawImage(cMap.boxes[pointB].spaceObject.objectImg,
                                        new Rectangle(cMap.boxes[pointB].xcenter - cMap.boxes[pointB].spaceObject.objectImg.Width / 2,
                                                      cMap.boxes[pointB].ycenter - cMap.boxes[pointB].spaceObject.objectImg.Height / 2,
                                                      cMap.boxes[pointB].spaceObject.objectImg.Width,
                                                      cMap.boxes[pointB].spaceObject.objectImg.Height));
                            cMap.boxes[pointB].spaceObject.statusRefresh(ref bmBackground, ref bmFull);
                        }
                    }
                    cMap.boxes[boxId].spaceObject.player = -1;
                    cMap.boxes[boxId].spaceObject        = null;
                    boxId = -1;
                }
            }
        }