Disclosure of Invention
In order to overcome the technical defects, the present invention provides a method, a system and a computer readable storage medium for generating an area in a game map, which can realize the boundary generation of a map area by fast calculation and adapt to random map blocking.
The invention discloses a method for generating an area in a game map, which comprises the following steps:
selecting a game map with the length W and the width H and an area circle with the radius R;
dividing the game map into at least two map units, randomly selecting map pixels in each map unit as the center of a regional circle, and generating the regional circle by using the center of the regional circle and the radius R;
moving one or more overlapped area circles among the area circles generated in each map unit to independently distribute all the area circles in the map unit;
generating blocking area information in the game map, wherein the blocking area information comprises at least one blocking area;
acquiring the circle center of the area circle, and judging whether the circle center is positioned in any blocking area;
when the circle center is positioned in any blocking area, moving the circle center to the outside of the blocking area;
taking each circle center as an origin, and outwards expanding layer by layer based on an expansion speed to form an expansion area until the boundary of the expansion area is contacted with an adjacent expansion area or a blocking area;
a map area is formed based on the expanded area.
Preferably, the step of dividing the game map into at least two map units, randomly selecting a map pixel in each map unit as the center of a circle of the area, and generating the circle of the area with the center and the radius R includes:
dividing the game map into n map units;
randomly selecting map pixels in each map unit as the center of a regional circle, and generating regional circles by using the center of the regional circle and the radius R;
the step of moving one or more overlapping area circles among the area circles generated in each map unit to independently allocate all the area circles in the map unit includes:
calculating the acting force between each region circle overlapped with the rest one or more region circles and the overlapped region circle;
and moving the area circle to an adjusting position according to the magnitude and the direction of the acting force, wherein the area circle is separated from any other area circle at the adjusting position.
Preferably, the step of generating blocking area information in the game map, wherein the blocking area information includes at least one blocking area further includes:
comparing the area ratio of the blocking area to the area circle in each area circle with a proportional threshold, and removing the area circle when the ratio is greater than or equal to the proportional threshold;
and when the proportion is smaller than the proportion threshold value, reserving the area circle and keeping the center of the area circle.
Preferably, when the circle center is located in any blocking area, the step of moving the circle center to the outside of the blocking area comprises:
when the circle center is positioned in any blocking area, traversing pixel points in the blocking area, and collecting the distance between any pixel point and the circle center;
extracting a pixel point with the minimum distance r from the circle center, and acquiring a standard boundary where the pixel point and the circle center are connected;
and taking the normal direction of the standard boundary as a moving direction, and moving the circle center r 'units to enable the circle center to be positioned outside the blocking area, wherein r' = r + delta r.
Preferably, the step of forming the expansion area by expanding outwards layer by layer based on an expansion speed with each circle center as an origin until the boundary of the expansion area is in contact with the adjacent expansion area or the blocking area comprises the following steps:
adding each circle center to an expansion list;
traversing the expansion list, and traversing adjacent pixels of each endpoint in the expansion list;
judging whether the adjacent pixel is marked as a pixel belonging to the expansion area, when the adjacent pixel is not marked as a pixel belonging to the expansion area, marking that the pixel belongs to the expansion area same as the end point, and adding the value into an expansion list to which the value belongs;
the above steps are repeatedly performed to mark all pixels within the game map except for the blocked area with the attribution of the dilated area.
Preferably, the step of forming the expansion area by expanding outwards layer by layer based on an expansion speed with each circle center as an origin until the boundary of the expansion area is in contact with the adjacent expansion area or the blocking area further comprises:
identifying whether pixels adjacent to all boundary pixels of the blocking area belong to the same expansion area;
when the pixels adjacent to the boundary pixel of the blocking area belong to the same expansion area, all the pixels in the blocking area are marked as the same expansion area to which the pixels adjacent to the boundary pixel belong.
Preferably, the step of forming the expansion area by expanding outwards layer by layer based on an expansion speed with each circle center as an origin until the boundary of the expansion area is in contact with the adjacent expansion area or the blocking area further comprises:
when the pixels adjacent to the boundary pixels of the blocking areas do not belong to the same expansion area, acquiring the identification number of the expansion area to which the adjacent pixels of the pixels in each blocking area belong, and calculating the maximum identification number of the expansion area to which the adjacent pixels of the pixels in each blocking area belong;
marking pixels in the blocking area to belong to the expansion area corresponding to the largest identification number, and marking the pixels in the blocking area as state pixels;
traversing all pixels in the blocking area, removing the state labels of the state pixels when the identification pixels are marked as the state pixels, and classifying the pixels into the expansion area corresponding to the maximum identification number according to the maximum identification number;
the steps are repeatedly executed until all the pixels in the blocking area belong to an expansion area.
Preferably, the region generation method further includes the steps of:
recording the identification number of the map area, the identification number of the adjacent map area and the identification number of the map area to which each pixel belongs, and recording the center of a circle as the center position of the map area.
The invention also discloses a system for generating the area in the game map, which comprises the following components:
the selection module selects a game map with the length of W and the width of H and an area circle with the radius of R;
the layout module is used for dividing the game map into at least two map units, randomly selecting map pixels in each map unit as the center of a regional circle, and generating the regional circle by using the center of the regional circle and the radius R;
the distribution module moves one or more overlapped area circles among the area circles generated in each map unit so as to independently distribute all the area circles in the map units;
the generating module is used for generating blocking area information in the game map, wherein the blocking area information comprises at least one blocking area;
the processing module is used for acquiring the circle center of the area circle and judging whether the circle center is positioned in any blocking area;
the moving module moves the circle center to the outside of the blocking area when the circle center is positioned in any blocking area;
the expansion module expands outwards layer by layer to form an expansion area based on an expansion speed by taking each circle center as an origin until the boundary of the expansion area is contacted with an adjacent expansion area or a blocking area;
and a mapping module for forming a map area based on the expanded area.
The invention also discloses a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps as described above.
After the technical scheme is adopted, compared with the prior art, the method has the following beneficial effects:
1. based on the hexagonal map pixels, a map area with certain randomness can be generated quickly, and the map boundary is smooth and has no fracture, so that the game habit of a user is met;
2. aiming at the blockage in the randomly existing game map, the method can be rapidly attributed to different map areas, and the Roguelike attribute of the user on the game is met, wherein the Roguelike attribute comprises randomness generation and game nonlinearity.
Detailed Description
The advantages of the invention are further illustrated in the following description of specific embodiments in conjunction with the accompanying drawings.
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
The terminology used in the disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present disclosure. The word "if," as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination," depending on the context.
In the description of the present invention, it is to be understood that the terms "longitudinal", "lateral", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", and the like, indicate orientations or positional relationships based on those shown in the drawings, and are used merely for convenience of description and for simplicity of description, and do not indicate or imply that the referenced devices or elements must have a particular orientation, be constructed in a particular orientation, and be operated, and thus, are not to be construed as limiting the present invention.
In the description of the present invention, unless otherwise specified and limited, it is to be noted that the terms "mounted," "connected," and "connected" are to be interpreted broadly, and may be, for example, a mechanical connection or an electrical connection, a communication between two elements, a direct connection, or an indirect connection via an intermediate medium, and specific meanings of the terms may be understood by those skilled in the art according to specific situations.
In the following description, suffixes such as "module", "component", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no specific meaning in themselves. Thus, "module" and "component" may be used in a mixture.
The basic elements of the game map are hexagonal map pixels. The pixels referred to in the invention are the smallest units forming a game map or a map area, and in the embodiment of the invention, the map pixels mainly adopt regular hexagons or regular quadrilaterals. Referring to fig. 1, taking a regular hexagonal map pixel as an example, the edges of the hexagonal map pixel are defined as follows: ei represents the orientation of a certain edge of the map pixel in a regular hexagon; pi is the orientation of its six fixed points; opEi is the opposite side of Ei, and according to the characteristics of the hexagon, the definition is as follows: ei = Pi +1, and OpEi = Ei ≧ 3Ei-3, defining the side Ei of the hexagon as half, taking advantage of the axisymmetric property of the regular hexagon.
Based on the definition of the regular hexagon, a set of a plurality of map pixels is combined to form a map area in the game map, namely a set of connected map pixels which are at a certain distance from the center point of the area on the map. For gaming in general, the entire game map should be covered by all zone areas, i.e. no blank map loudness within the game map, and at the same time the map areas should be as randomly and evenly covered as possible within the game map. In view of the above, referring to fig. 2, a method for generating an area in a game map according to a preferred embodiment of the present invention includes the following steps:
s100: selecting a game map with the length of W and the width of H and an area circle with the radius of R
The dimensions of the game map are defined as: the length is W, and the width is H, or in any shape, the longest distance in the length direction is W, and the longest distance in the width direction is H. Meanwhile, for each map pixel in the game map, a region circle with the radius of R is taken, wherein the region circle is defined by P (x, y). For example, the game map size is 2100 × 1800 map pixels, and the radius R is 15, so that each area circle includes 30 map pixels in the radial direction.
S200: dividing the game map into at least two map units, randomly selecting map pixels in each map unit as the center of the area circle, and generating the area circle by using the center and the radius R
In order to generate a plurality of map areas which are not overlapped with each other and are paved on the whole game map as much as possible on the game map of W x H, the game map is firstly divided into at least two map units, map pixels are randomly selected in each map unit as a reference point, and a plurality of area circles are generated in the map units by taking the reference point as the center of a circle and R as the radius.
It is understood that in step S200, the circle of the area is generated completely randomly, and there may be a case where two or more circles are partially overlapped and completely overlapped, but the randomness is used as a basis for generating different and non-repeated map areas.
S300: moving one or more of the area circles generated within each map unit that overlap with the remaining one or more to independently allocate all area circles within the map unit
After the area circles are generated in the map unit, in order to uniformly spread the whole game map as much as possible so that no uncovered area exists in the game map, for the area circle having an overlap with the remaining one or more area circles, some or all of the area circles are moved until all the area circles are independently allocated in the map unit without any other area circles being overlapped.
It will be appreciated that the distribution density of the area circles within the map unit may vary in different embodiments. For example, when the density of the area circles distributed in a map unit is low, after the area circles are moved so that all the area circles are not overlapped, a part of the area in the map unit may not be covered by the area circles, that is, a plurality of area circles are spaced at a certain distance; on the contrary, if the density of the regional circles distributed in a map unit is high, the regional circles are moved to ensure that all the regional circles are not overlapped, and then the regional circles are closely arranged. To prevent the division of all the area circles from occurring regardless of the movement of the area circles, the number of area circles should be limited to the ratio of the area of the game map to the area of the area circles.
S400: generating blocking area information in the game map, wherein the blocking area information comprises at least one blocking area
In view of simulating the actual map condition, blocking areas that are not penetrated and touched by game objects, such as mountains, rivers, seas and the like in the game map, are generally included in the game map. For these blocked areas, the blocked areas should be removed from within the finally generated map area. Therefore, in step S400, blocking area information is generated in the game map, wherein the blocking area information includes at least one blocking area, and the blocking area can define a position covered by the blocking area in a coordinate form.
S500: acquiring the circle center of the area circle, and judging whether the circle center is positioned in any blocking area
Then, the position of the center of the area circle, namely the coordinate position of the map pixel corresponding to the center of the area circle, is obtained, and meanwhile, the coordinate position is compared with the position covered by the blocking area to judge whether the center of the circle is located in any blocking area. It is to be understood that the configuration of step S500 is to remove the situation where the blocked area is generated within the map area, and to prevent the finally generated map area from appearing within or on the blocked area.
S600: when the circle center is positioned in any blocking area, moving the circle center to the outside of the blocking area
When the determination result in step S500 is that the circle center is located outside the blocking area, the circle center is moved until the circle center is located outside the blocking area. It will be appreciated that the direction of movement and distance of movement may be arbitrary or specified, and that when the centre of the circle is outside the blocked area, the main core of the area circle will claim to be outside the blocked area of the game map, meeting the game requirements.
It should be noted that the sequence or the execution times of steps S500 and S600 are not limited, for example, all the circle centers may be moved outside the blocking area first, and then the circle centers are moved so that all the area circles do not overlap, or step S500 is executed first, then step S600 is executed, and then step S500 is executed again, so as to finally ensure that the requirements of step S500 and step S600 on the positions of the area circles are met at the same time. In addition, if the steps S500 and S600 are performed only once, it is finally achieved that all the centers of the circles are outside the blocking area, but when some circles in some areas overlap with each other, the situation is acceptable, and the situation is allowed to exist.
S700: taking each circle center as an origin, outwards expanding layer by layer based on an expansion speed to form an expansion area until the boundary of the expansion area is contacted with the adjacent expansion area or blocking area
Then, each circle center is used as an origin point, based on an expansion speed, the expansion is gradually outward, and pixels passing through in the expansion process are classified into an expansion area. As the dilation process progresses, the dilation region becomes larger until the boundaries of adjacent dilation regions touch each other, or until the dilation region touches the boundary of a blocking region, or even all map pixels on the game map except the blocking region fall within a certain dilation region.
It will also be appreciated that the manner of expansion may be on a circle-center basis, radiating circularly outward layer-by-layer, extending outward in stripes on a map-by-map pixel-by-pixel basis to expand.
S800: forming a map area based on the expanded area
When the single expansion area having the boundary is formed as a single map area after having the expansion area, a plurality of adjacent and independently divided map areas are formed on the game map. In game development, movement, motion, and the like of a game object can be arranged in a map area, and even when a map pixel is a hexagon, some edges of the map pixel at the boundary form the boundary of the map area. It can be understood that, when the map pixels are in any shape, the map area can still be generated by the area generation method of the embodiment of the present invention.
With the above configuration, a map area not limited to map pixels of any shape is generated in a random manner within a game map while the generation speed is fast, and the pixels of the game map are required to be enlarged to a hexagonal shape not limited to a common quadrangular shape.
Referring to fig. 3 and 4, in a preferred embodiment, the step S200 of dividing the game map into at least two map units, randomly selecting a map pixel in each map unit as a center of the area circle, and generating the area circle according to the center and the radius R includes:
s210: dividing the game map into n map units
In step S210, after the game map is acquired, the entire game map is divided into a plurality of map units. Taking a rectangular game map with a length W and a width H as an example, a plurality of map cells, which are likewise rectangular, can be formed by dividing equally or randomly in the longitudinal direction and the width direction. When the game map has an arbitrary shape, the map unit may be divided by searching for a rectangle having the largest shape in the game map, dividing the rectangle in the above manner, and then extending the dividing line in the rectangle to divide the rest of the game map.
S220: randomly selecting map pixels in each map unit as the center of a regional circle, and generating the map pixels by using the center and the radius R
Circle of each region
After map units are formed, in each map unit, a certain map pixel is randomly selected as the center of a regional circleAnd is generated by the circle center and the radius R
The areas are circular. Since the partial area circles in the subsequent part are moved to be independently laid out on the game map, if the game map is not divided, a large number of invalid traversals are generated in the process of checking each area circle, which results in long process time and high load requirement. Thus, by dividing the game map into a plurality of map cells (e.g., 4r × 4r per game cell), the traversal process is completed within each map cell, and as the traversal area becomes smaller, the load requirements may be reduced.
In this embodiment, the step S300 of moving one or more overlapping area circles of the area circles generated in each map unit to independently allocate all the area circles in the map unit includes:
s310: calculating the force between each circle overlapping the remaining circle or circles and the overlapping circle
To achieve independent layout of the region circles, the interaction force received by each region circle by other region circles is first calculated iteratively in step S310. The calculation mode can be obtained by the extrusion force between the area circles, the overlapping area and the simulated movement trend after the area circles are overlapped.
S320: moving the region circle to an adjustment position according to the magnitude and direction of the acting force, wherein the region circle is separated from any other region circles at the adjustment position
Based on the acting force (the resultant force and the direction applied to the area circle by the rest of the area circles partially overlapped with the area circles) received by each area circle calculated in the above steps, the area circle is moved along the direction until the circle center moves to an adjustment position, the resultant force disappears, so that the area circles are not extruded by other area circles at the adjustment position, and all the area circles are independently arranged and separated from each other.
In another preferred embodiment, the step S400 of generating blocking area information in the game map, where the blocking area information includes at least one blocking area further includes:
s410: comparing the area ratio of the blocking area to the area circle in each area circle with a ratio threshold, and removing the area circle when the ratio is larger than or equal to the ratio threshold;
the foregoing steps generate a pre-region of the map area on the map, but because of the large amount of blockage present on the game map: where game objects such as mountains, rivers, seas, etc. cannot pass, further processing of the pre-area is required to move or remove the pre-area on the barrier. Taking the removal as an example, in step S410, a proportional threshold is preset, the ratio of the area of the blocking area to the area of the area circle in each area circle is compared with the proportional threshold, and when the ratio is greater than or equal to the proportional threshold, the area circle is removed. For example, when the proportion threshold is 50%, and the proportion of the area of the blocking area to the area of the area circle is greater than 50%, the area circle is directly removed from the game map.
S420: when the proportion is smaller than the proportion threshold value, reserving the area circle and keeping the center of the area circle
And when the proportion is smaller than the proportion threshold value, the blocking area in the area circle is less, and the area circle can be regarded as an effective area circle, so that the area circle is reserved and the position of the center of the area circle is kept.
Although in the above embodiments, the blocking area within the partial area circle is smaller, so that the area circle is preserved. However, if the center of the area circle is located in the blocking area, the core area of the area circle will be an inaccessible part, and these situations cannot be allowed in the game. Therefore, referring to fig. 5, 6a, and 6b, when the circle center is located in any of the blocking areas, the step S600 of moving the circle center to an outside of the blocking area specifically includes:
s610: when the circle center is positioned in any blocking area, traversing pixel points in the blocking area, and collecting the distance between any pixel point and the circle center;
in order to move the circle center and effectively and pertinently move the circle center, when the circle center is positioned in any blocking area, pixel points in the blocking area are traversed, the distance between each pixel point and the circle center is collected, the distance is used for judging the moving direction of the circle center, and the minimum distance can be moved.
S620: extracting a pixel point with the minimum distance r from the circle center, and acquiring a standard boundary where the pixel point and the circle center are connected;
in step S620, the pixel point with the minimum distance r from the center of the circle in the blocking region is extracted, and it is known that the pixel point can be removed from the blocking region at the minimum moving distance when the center of the circle in the region is moved out of the pixel point. Therefore, with the pixel point, the standard boundary where the pixel point and the circle center are connected is obtained. Taking the pixel point as a hexagon as an example, under the condition that the pixel point is known, the shortest moving distance from He Tiaoleng side of the pixel point still needs to be calculated, so that after the center of the pixel point is connected with the center of a circle, the boundary intersected with the pixel point is extended to be the standard boundary.
S630: taking the normal direction of the standard boundary as the moving direction, moving the circle center r 'units to make the circle center located outside the blocking area, wherein r' = r + delta r
Then taking the standard boundary as a standard, taking the normal direction as a moving direction, moving the circle center r' units, and positioning the circle center outside the blocking area after moving. It can be known that, in this embodiment, r '= r + Δ r, the Δ r may be 0 or any unit larger than 0, when Δ r is 0, the center of the circle moves to the boundary of the blocking area, and to be more suitable for the user's game experience, Δ r is generally a value larger than 0, and Δ r in different area circles may be different, so that the blocking areas are different in position within the area circle. After the movement is finished, all circles are not blocked within the range of delta r, so that the blocked area in the game map really belongs to a part of the map area, but the movement of the game object is not influenced.
Referring to fig. 7 and 8, the step S700 of expanding outward layer by layer based on an expansion speed with each circle center as an origin to form expansion regions until the boundary of the expansion region contacts with an adjacent expansion region or a blocking region includes:
s710: adding each circle center to an expansion list;
the center of the area circle, i.e., the center of the circle, is added to an expanded list, such as OpenList.
S720: traversing the expansion list, and traversing adjacent pixels of each endpoint in the expansion list;
and traversing the expansion list OpenList, and traversing adjacent pixels of each endpoint (such as a circle center of a Node) in the expansion list OpenList. Taking a hexagonal map pixel as an example, the adjacent pixels are six map pixels on the periphery adjacent to six edges.
S730: judging whether the adjacent pixels are marked as pixels belonging to the expansion area or not, when the adjacent pixels are not marked as pixels belonging to the expansion area, marking the pixels belonging to the expansion area same as the end point, and adding the values into an expansion list to which the pixels belong;
after traversing the neighboring pixels, it is determined whether the neighboring pixels have been marked as belonging to pixels within the expanded region, i.e., whether the neighboring pixels have been marked as belonging to a certain map region. It will be appreciated that in this embodiment, each map pixel will be assigned a label based on the expansion process of the circle center, the label representing the map area to which the map pixel belongs. Therefore, in step S730,
s740: repeatedly executing the steps to mark all the pixels except the blocking area in the game map with the attribution of the expansion area
After the above steps S720 and S730 are continuously executed based on the center of the circle in the region circle, all the pixels of the region except the blocking region are marked with the attribution of the expansion region. And the overall expansion trend is judged by gradually going outward, and the marking of which area the map pixel belongs to is completed.
Further, step S700 may further include:
s750: identifying whether pixels adjacent to all boundary pixels of the blocking area belong to the same expansion area;
in the above steps, map pixels on the game map except for the blocked area are marked, but if the blocked area is not marked, more holes between the map areas formed by blocking on the game map are easy to appear, and the boundary line effect of the finally formed game map is influenced. Therefore, in a subsequent step, the blocking area will be area marked. Specifically, it is first identified whether pixels adjacent to all boundary pixels in any blocked area belong to the same expansion area, that is, whether the blocked area is completely included in a map area formed by expansion.
S760: when the pixels adjacent to the boundary pixel of the blocking area belong to the same expansion area, all the pixels in the blocking area are marked as the same expansion area to which the pixels adjacent to the boundary pixel belong.
If the pixels adjacent to the boundary pixel of the blocking area belong to the same expansion area under the judgment, all the pixels in the blocking area are marked as the same expansion area to which the adjacent pixels belong, namely the blocking area is phagocytosed by the expansion area, the blocking area is classified into the blocking area, but the blocking property of the blocking area still exists, and the significance of the phagocytosis or classification is to cancel the boundary between the map area and the blocking area.
Still further, step S700 may further include:
s770: when the pixels adjacent to the boundary pixels of the blocking areas do not belong to the same expansion area, acquiring the identification number of the expansion area to which the adjacent pixels of the pixels in each blocking area belong, and calculating the maximum identification number of the expansion area to which the adjacent pixels of the pixels in each blocking area belong;
if the pixels adjacent to the boundary pixels of the blocking area do not belong to the same expansion area under the judgment, that is, one blocking area is adjacent to two or more expansion areas, it is necessary to arrange that each expansion area gradually erodes the blocking area so as to classify different positions of the blocking area into different expansion areas. For this, the identification number of the expansion region to which the adjacent pixels of the pixels in each blocking region belong is obtained, that is, the pixels of the blocking region obtain the pixels (6 pixels in the case of a hexagon) adjacent to the pixels, and whether the pixels already belong to a certain expansion region, if so, what the identification number (or mark number) of the expansion region belongs to. It is to be understood that, when these pixels are the outermost pixels of the barrier region, some of the pixels adjacent thereto have identification numbers of the dilated regions, and when the pixels are pixels within the outermost pixels of the barrier region, the pixels adjacent thereto have no identification numbers of the dilated regions.
Then, counting the identification number with the largest occurrence number in the identification numbers of the expansion areas to which the adjacent pixels of the pixels of each blocking area belong. For example, in the outermost peripheral pixel of the barrier region, among 6 adjacent pixels having one pixel, there are 3 identification numbers having the expansion regions, of which 2 are the expansion regions a and 1 is the expansion region B, and then the maximum identification number of the pixel is the expansion region B. If the inner pixel of the blocking area, and the adjacent 6 pixels do not have the identification number of the expansion area, the pixel has the largest identification number (area).
S780: marking pixels in the blocking area to belong to the expansion area corresponding to the largest identification number, and marking the pixels in the blocking area as state pixels;
the pixels in the mark blocking area having the most identification number series are: belonging to the dilated area corresponding to the largest identification number, in the above example, the peripheral pixels belong to dilated area B, and the pixels in the blocked area are marked as status pixels (extra flag). The state pixels represent pixels within the blocking region, having properties attributable to a certain expansion region, as distinguished from other pixels within the blocking region that have not yet been determined to be within which expansion region. To this end, the expansion region is further expanded toward the barrier region.
S790: traversing all pixels in the blocking area, removing the state labels of the state pixels when the identification pixels are marked as the state pixels, and classifying the pixels into the expansion area corresponding to the maximum identification number according to the maximum identification number;
then, based on the state pixel, the step of expanding the region to etch the blocking region is performed. I.e. traverse all pixels within the blocking area, if a pixel has been marked as a status pixel, remove its status label and attribute it to the inflation area corresponding to the maximum identification number according to its maximum identification number, which is also marked at the same time. In other words, still taking the above example as an example, the peripheral pixels are classified into the expanded region B, and the erosion of the barrier region is completed.
S791: the steps are repeatedly executed until all the pixels in the blocking area belong to an expansion area.
By continuing the above steps until all pixels in the blocking area are classified as an expansion area, the erosion is terminated, and each blocking area is included in one or more expansion areas. No more holes are formed between the expanded areas, so that a map area is formed between the boundaries. That is, the expansion area initially includes only all pixels except the blocking area, and the map area may include both general map pixels and map pixels in the blocking area.
After the above steps are completed, the region generating method further includes:
s900: recording the identification number of the map area, the identification number of the adjacent map area and the identification number of the map area to which each pixel belongs, and recording the center of a circle as the center position of the map area
For example, all data related to a map of an area, including but not limited to: the game map is represented in an information form by an identification number (area) of a map area, an identification number (areas) of adjacent map areas, an identification number (map area X) of a map area to which each pixel belongs, a center position (center) represented by a center of a circle, an area collection (area collection) including all the map areas, and the like.
In a preferred embodiment, there is also disclosed a system for generating an area within a game map, comprising: the selection module selects a game map with the length of W and the width of H and an area circle with the radius of R; the layout module is used for dividing the game map into at least two map units, randomly selecting map pixels in each map unit as the center of a regional circle, and generating the regional circle by using the center of the regional circle and the radius R; the distribution module moves one or more overlapped area circles among the area circles generated in each map unit so as to independently distribute all the area circles in the map units; the generating module is used for generating blocking area information in the game map, wherein the blocking area information comprises at least one blocking area; the processing module is used for acquiring the circle center of the area circle and judging whether the circle center is positioned in any blocking area; the moving module moves the circle center to the outside of the blocking area when the circle center is positioned in any blocking area; the expansion module is used for outwards expanding layer by layer based on an expansion speed by taking each circle center as an origin to form an expansion area until the boundary of the expansion area is contacted with an adjacent expansion area or a blocking area; and a mapping module for forming a map area based on the expanded area.
In a further preferred embodiment, a computer-readable storage medium is also disclosed, on which a computer program is stored which, when being executed by a processor, carries out the steps as described above.
The smart terminal may be implemented in various forms. For example, the terminal described in the present invention may include an intelligent terminal such as a mobile phone, a smart phone, a notebook computer, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, etc., and a fixed terminal such as a digital TV, a desktop computer, etc. In the following, it is assumed that the terminal is a smart terminal. However, it will be understood by those skilled in the art that the configuration according to the embodiment of the present invention can be applied to a fixed type terminal in addition to elements particularly used for moving purposes.
It should be noted that the embodiments of the present invention have been described in terms of preferred embodiments, and not by way of limitation, and that those skilled in the art can make modifications and variations of the embodiments described above without departing from the spirit of the invention.