Exemplo n.º 1
0
        public Meteor meteorCreate(combatMap cMap)
        {
            int    flag       = 1;
            int    box4meteor = 0;
            int    meteorHealth;
            int    meteorDmg;
            int    xWay      = Constants.RIGHT;
            int    yWay      = Constants.MEDIUM_TOP;
            Meteor newMeteor = null;
            int    i;

            Random rand      = new Random();
            int    randomNum = rand.Next(1, 100) % 4;

            // место появления и направление полёта
            switch (randomNum)
            {
            case 1:      // left
                box4meteor = rand.Next(0, cMap.height);
                for (i = 0; i < 10; i++)
                {
                    if (cMap.boxes[box4meteor].spaceObject != null)
                    {
                        box4meteor += 1;
                        if (box4meteor >= cMap.height - 1)
                        {
                            box4meteor = 0;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (i == 10)
                {
                    flag = 0;
                }
                xWay = Constants.RIGHT;
                if (rand.Next(1, 100) > 50)
                {
                    yWay = Constants.MEDIUM_TOP;
                }
                else
                {
                    yWay = Constants.MEDIUM_BOTTOM;
                }
                break;

            case 2:     // top
                box4meteor = cMap.getBoxByCoords(rand.Next(0, cMap.width / 2 - 1) * 2, 0).id;
                for (i = 0; i < 10; i++)
                {
                    if (cMap.boxes[box4meteor].spaceObject != null)
                    {
                        box4meteor += cMap.height * 2;
                        if (box4meteor > cMap.width + 1)
                        {
                            box4meteor = 0;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (i == 10)
                {
                    flag = 0;
                }
                if (rand.Next(1, 100) > 50)
                {
                    xWay = Constants.RIGHT;
                }
                else
                {
                    xWay = Constants.LEFT;
                }
                yWay = Constants.MEDIUM_BOTTOM;
                break;

            case 3:     // right
                box4meteor = rand.Next(cMap.boxes.Count - 1 - cMap.height, cMap.boxes.Count - 1);
                for (i = 0; i < 10; i++)
                {
                    if (cMap.boxes[box4meteor].spaceObject != null)
                    {
                        box4meteor += 1;
                        if (box4meteor > cMap.boxes.Count - 1)
                        {
                            box4meteor = cMap.boxes.Count - cMap.height;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (i == 10)
                {
                    flag = 0;
                }
                xWay = Constants.LEFT;
                if (rand.Next(1, 100) > 50)
                {
                    yWay = Constants.MEDIUM_TOP;
                }
                else
                {
                    yWay = Constants.MEDIUM_BOTTOM;
                }
                break;

            case 0:     // bottom
                box4meteor = cMap.getBoxByCoords(rand.Next(0, cMap.width / 2 - 1) * 2 + 1, cMap.height * 2 - 1).id;
                for (i = 0; i < 10; i++)
                {
                    if (cMap.boxes[box4meteor].spaceObject != null)
                    {
                        box4meteor += cMap.height * 2;
                        if (box4meteor > cMap.boxes.Count - 1)
                        {
                            box4meteor = cMap.height - 1;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (i == 10)
                {
                    flag = 0;
                }
                if (rand.Next(1, 100) > 50)
                {
                    xWay = Constants.RIGHT;
                }
                else
                {
                    xWay = Constants.LEFT;
                }
                yWay = Constants.MEDIUM_TOP;
                break;
            }

            if (flag == 1)
            {
                meteorHealth = rand.Next(1, 150);
                meteorDmg    = meteorHealth / 4;

                newMeteor = new Meteor(cMap, box4meteor, meteorHealth, meteorDmg, xWay, yWay);
                meteors.Add(newMeteor);
                cMap.boxes[box4meteor].spaceObject = newMeteor;
            }
            return(newMeteor);
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 3
0
        public Box getNextWaybox(Box currentBox, Box baseBox, ref List <int> priority, ref List <Box> previousBoxes)
        {
            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 = cMap.boxes[currentBox.id - 1];
                    break;

                case Constants.MOVE_RIGHT_TOP:
                    if (currentBox.y == 0 || currentBox.x == cMap.width - 1)
                    {
                        continue;
                    }
                    nextWaybox = cMap.getBoxByCoords(currentBox.x + 1, currentBox.y - 1);
                    break;

                case Constants.MOVE_RIGHT_BOTTOM:
                    if (currentBox.x == cMap.width - 1 || currentBox.y == cMap.height * 2 - 1)
                    {
                        continue;
                    }
                    nextWaybox = cMap.getBoxByCoords(currentBox.x + 1, currentBox.y + 1);
                    break;

                case Constants.MOVE_BOTTOM:
                    if (currentBox.y >= cMap.height * 2 - 2)
                    {
                        continue;
                    }
                    nextWaybox = cMap.boxes[currentBox.id + 1];
                    break;

                case Constants.MOVE_LEFT_BOTTOM:
                    if (currentBox.x == 0 || currentBox.y == cMap.height * 2 - 1)
                    {
                        continue;
                    }
                    nextWaybox = cMap.getBoxByCoords(currentBox.x - 1, currentBox.y + 1);
                    break;

                case Constants.MOVE_LEFT_TOP:
                    if (currentBox.x == 0 || currentBox.y == 0)
                    {
                        continue;
                    }
                    nextWaybox = 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);
        }