A method and system for controlling game character status using terrain mask
By drawing grids on the terrain and marking masks, the problem that virtual objects in 3D games cannot simulate the impact of real environments is solved, and the logical control and gameplay of character states are achieved is enriched, reducing performance overhead.
Patent Information
- Application Number
- CN202111615090.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2041-12-27
AI Technical Summary
In 3D game scenes, virtual objects cannot simulate the real world environment and affect the player's character status, resulting in a single gameplay and a high overhead 3D physical collision system that is difficult to implement on low-end machines.
The terrain masking method is used to lattice drawing, mark masking, store the game terrain and set trigger events when loading the game to achieve character status change.
It enriches gameplay, reduces performance overhead, and realizes logical control of character status by virtual environments on low-end machines.
Smart Images

Figure CN114225414B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and system for controlling the state of a game character using a terrain mask. Background Art
[0002] In game design, to enrich gameplay, real-world environments are often used to influence the player's character. For example, if a person encounters a river or lake in the real world, entering it will cause them to swim. If a person encounters a large patch of grass, entering it will likely make it difficult for others to find them, and so on. In-game scenes also contain objects like rivers and grass, but these are virtual and lack the specific properties of real-world objects. When the player's character enters these virtual objects, they cannot trigger real-world reactions. Therefore, to achieve this goal, these virtual objects need to be given specific properties. However, objects in 3D game scenes are composed of vertices, which is clearly not suitable for simulating an entire ecosystem due to the high overhead involved. Summary of the Invention
[0003] To overcome the above problems, the present invention aims to provide a method for triggering the behavior and state changes of game characters through the effect of terrain mask.
[0004] The present invention is implemented by the following scheme: a method for controlling the state of a game character using a terrain mask, the method comprising the following steps:
[0005] Step S1: Draw the game terrain mask in grids, with each grid corresponding to a single mask;
[0006] Step S2: marking various masks according to grid coordinates;
[0007] Step S3: store the mask in a file and output it;
[0008] Step S4: When loading the game, the game terminal reads the mask value in the file and sets a trigger event to achieve changes in the behavior and status of the game character.
[0009] Furthermore, step S1 is further specified as follows: setting the size ratio of a single mask in the game scene, the size of the mask is an integer multiple of the game terrain unit, and drawing grid lines on the game terrain according to the terrain size, so as to facilitate the observation and annotation of the type of mask in each grid.
[0010] Furthermore, the step S2 is further specified as follows: a mask is brushed on the grid to determine whether the mask position is an attribute type affected by the environment; if so, the masks of the attribute type affected by the environment are stored as the same type; otherwise, multiple types of masks are superimposed on each other and finally stored bit by bit.
[0011] Furthermore, the step S3 is further specified as follows: the mask is stored as a DDS texture file, the game terrain page number is saved in the form of an image, each image pixel is a 32-bit value, and different types of mask values are filled in each of the 32 bits of the image pixel, thereby reducing the space occupied by the mask value.
[0012] Furthermore, the step S4 is further specified as follows: when loading the game, the game client or server first reads out the mask map, then sets the trigger event in the game area according to the mask value, and changes the behavior and status of the game character according to the trigger event.
[0013] The present invention also provides a system for controlling the state of a game character using a terrain mask, comprising a drawing module, a labeling module, a storage module, and a triggering module. The drawing module performs grid drawing on the game terrain mask, with each grid corresponding to a single mask; the labeling module labels various masks according to grid coordinates; the storage module stores the mask in a file and outputs it; the triggering module reads the mask value in the file when the game is loaded, and sets a triggering event, thereby realizing changes in the behavior and state of the game character.
[0014] Furthermore, the drawing module is further specified as follows: setting the size ratio of a single mask in the game scene, the size of the mask is an integer multiple of the game terrain unit, and drawing grid lines on the game terrain according to the terrain size, so as to facilitate the observation and annotation of the type of mask in each grid.
[0015] Furthermore, the labeling module is further specified as follows: a mask is brushed on the grid to determine whether the mask position is an attribute type affected by the environment. If yes, the masks of the attribute type affected by the environment are stored as the same type; otherwise, multiple types of masks are superimposed on each other and finally stored bit by bit.
[0016] Furthermore, the storage module is further specified as follows: the mask is stored as a DDS texture file, the game terrain page number is saved in the form of an image, each image pixel is a 32-bit value, and different types of mask values are filled in each of the 32 bits of the image pixel, thereby reducing the space occupied by the mask value.
[0017] Furthermore, when loading the game, the game client or server first reads out the mask map, then sets the trigger event in the game area according to the mask value, and changes the behavior and status of the game character according to the trigger event.
[0018] The beneficial effects of the present invention are as follows: the present invention provides a method for applying various types of masks to the terrain of a 3D scene and storing the mask values as a 32-bit image. By reading the mask information in the image, the game client or server establishes the corresponding trigger logic within the game, supplementing some difficult-to-solve logical state processing issues in 3D scene editing and enriching the gameplay. It also makes it possible for games on some low-end machines to implement collision logic without using the 3D engine's physical collision system. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a schematic flow chart of the method of the present invention.
[0020] Figure 2 It is a system principle block diagram of the present invention.
[0021] Figure 3 Schematic diagram of the operation of filling the mask into the pixel value.
[0022] Figure 4 The diagram below shows the operation of reading the space size mask value. DETAILED DESCRIPTION
[0023] The present invention will be further described below with reference to the accompanying drawings.
[0024] See also Figure 1 As shown, a method of controlling the state of a game character using a terrain mask of the present invention comprises the following steps:
[0025] Step S1: Draw the game terrain mask in grids, with each grid corresponding to a single mask;
[0026] Step S2: marking various masks according to grid coordinates;
[0027] Step S3: store the mask in a file and output it;
[0028] Step S4: When loading the game, the game terminal reads the mask value in the file and sets a trigger event to achieve changes in the behavior and status of the game character.
[0029] The present invention will be further described below by a specific embodiment:
[0030] 1. Terrain mask grid drawing:
[0031] Set the size ratio of a single mask within the scene, for example, a 0.5*0.5 terrain unit area is a mask. The mask size is an integer (positive or negative) multiple of the terrain unit. A higher precision results in more accurate triggering, but also increases program overhead. Grid lines are drawn on the terrain according to the terrain size, making it easier to identify which type of mask the corresponding grid is.
[0032] Masking: Masking involves storing multiple, relatively small values within a standard value. Using AND operations to mask the non-occupied portions allows the masked value to be read. For example, if you need to store a three-state value—state 1, state 2, and state 3—only two bits are needed in binary encoding: binary 00 represents state 1, binary 01 represents state 2, and binary 10 represents state 3. However, in C / C++ programming, a data type is required to store this value, and the smallest char is 8 bits. Therefore, the three-state value can be stored in the first two bits of the char, and the remaining six bits can be used to store the remaining values. When reading, the remaining six bits are masked, leaving only the first two bits as the three-state value. In this article, due to the large number of attribute values, the 32-bit int32 data type is used.
[0033] 2. Mark various masks according to grid coordinates:
[0034] This step is to apply a mask to the grid to determine the type of attribute affected by the environment at that location, such as water, grass, etc. Multiple types of masks can be superimposed on each other and finally stored bit by bit.
[0035] Coordinates are the coordinates of the map converted to grid coordinates. For example, if a map is 32x32, the map coordinates are between 0 and 32 on the x-axis and 0 and 32 on the y-axis. Assuming the grid has double the map precision, the grid is 64 blocks long and 64 blocks wide, with each grid being a grid coordinate. Masking a grid actually sets the mouse icon to a different brush shape based on the selected mask value. The brush-shaped graphic is then drawn on the grid where the mouse is clicked, and the mask value is stored in a variable representing the grid's attributes.
[0036] 3. Mask save file output:
[0037] Because in-game terrain files are typically grayscale images, the terrain size is the image's height and width, and the corresponding pixel value is the terrain's height at the corresponding coordinate. This is done because the way icons read terrain width and height and coordinate values is highly similar to how images are stored, eliminating the need to reinvent the wheel and write a new storage algorithm. Similarly, terrain page numbers can be stored as images, with each pixel being a 32-bit value. Different types of mask values can be assigned to each of these 32 bits, significantly reducing the space occupied by the mask value and facilitating data reading and writing.
[0038] Mask files are stored as DDS texture files in the A8R8G8B8 format, meaning each pixel has four 8-bit channels, for a total of 32 bits. In this example, based on the Dota game mask type, the mask is currently divided into 2 bits for slope, 1 bit for walkability, 1 bit for fog of war, 1 bit for water, 3 bits for grass, 3 bits for room size, 3 bits for echo, and 4 bits for footsteps. There is still room for expansion.
[0039] Let's take an example to illustrate how to write the mask value of "space size" into the pixel value: "space size" occupies 3 bits, and its value can have 2 to the power of 3 = 8 values. Suppose we brush the value 3 for "space size" in the grid coordinate (1,1), the corresponding binary value is 011. According to the order, the starting bit of "space size" is the eighth bit, so we need to shift this binary value 011 left by 32-8-3 (itself 3 bits) = 21 bits, becoming 0110000... (21 zeros), and perform an OR operation with the pixel value at position (1,1) in dds. Figure 3 As shown, the value obtained is the value after writing.
[0040] 4. The game reads the mask value and sets the trigger event:
[0041] When loading a game, the game client or server first reads the mask map. It then sets trigger events within the game area based on the mask value. These trigger events modify the behavior and state of the player-controlled character within the game. For example, if a trigger triggers entering a water area, ripples appear beneath the character's feet. If a trigger triggers entering a grassy area, the character becomes invisible, making them invisible to other hostile players and monsters. This refers to one way in which the game uses the mask. The specific ways in which a game uses the mask to modify character behavior is beyond the scope of this article. The mask provides a flag for the game to use as a judgment indicator for game control. The game can freely use the mask value to determine its actions.
[0042] Each type of mask has a corresponding trigger event, such as the character movement event and the footsteps event. For example, if the character needs to move to position (1,1), the "walkable" mask value of (1,1) can be pre-read and the value can be determined to determine whether the character moves forward or stands still. When playing footsteps, the "space size" value of the mask type of the grid where the character is located can be used to determine whether to play the footsteps in an open space or in a confined space, and so on.
[0043] See also Figure 4 As shown, the process of reading the value of the "space size" mask is as follows:
[0044] Traverse the pixels of the DDS texture map and read the pixel value of (x, y).
[0045] Perform an AND operation with the "space size" mask value to mask other mask bits, and shift the value after the AND operation to the right by 32-8-3 (its own size) bits.
[0046] The present invention is illustrated below by using specific application scenarios:
[0047] The present invention can be used in various 3D battle games, MMORPG, DOTA and other types of games. The following examples illustrate:
[0048] Application Scenario 1: In Dota-style games, brushwood is used as cover. If the player's character walks into the brushwood, they enter a stealth state. Enemy players and enemy soldiers cannot see the player and will not attack them. However, if an enemy player or soldier also walks into the brushwood, they gain the same state and can see and attack the player. This design creates a sneak attack / counter-sneak attack gameplay. The brushwood masking solution helps the game solve the problem of locating brushwood areas.
[0049] Application Scenario 2: Certain areas of the game map are off-limits to the player's character to prevent disruptions to gameplay or visual artifacts. In this case, refreshing the traversable area mask is a reliable solution. The game reads the mask file, sets it, and determines whether the player's character is moving toward masked coordinates. If so, movement is stopped. Another way to determine whether the player is using cheats or other illegal means to move the character to a non-traversable area is to simply determine whether the character's coordinates are masked against the non-traversable area.
[0050] In short, the present invention marks different types of areas on the surface. When a character enters a corresponding area, a corresponding event is triggered. The game logic judges and changes the character's behavior and state based on these events. This ensures that the character played by the player is affected by the scene environment while ensuring performance overhead.
[0051] See also Figure 2 As shown, the present invention also provides a system for controlling the state of a game character using a terrain mask, comprising a drawing module, a labeling module, a storage module and a triggering module. The drawing module performs grid drawing on the game terrain mask, with each grid corresponding to a single mask; the labeling module labels various masks according to grid coordinates; the storage module stores the mask in a file and outputs it; the triggering module reads the mask value in the file when the game is loaded, and sets a triggering event, thereby realizing changes in the behavior and state of the game character.
[0052] The drawing module is further specifically configured to: set the size ratio of a single mask in the game scene, the size of the mask is an integer multiple of the game terrain unit, and draw grid lines on the game terrain according to the terrain size to facilitate observation and annotation of the type of mask in each grid.
[0053] The marking module is further specifically as follows: a mask is brushed on the grid to determine whether the mask position is an attribute type affected by the environment. If yes, the masks of the attribute type affected by the environment are stored as the same type. If not, multiple types of masks are superimposed on each other and finally stored bit by bit.
[0054] The storage module is further specifically as follows: the mask is stored as a DDS texture file, the game terrain page number is saved in the form of an image, each image pixel is a 32-bit value, and different types of mask values are filled in each of the 32 bits of the image pixel, thereby reducing the space occupied by the mask value.
[0055] When the game client or server loads the game, it first reads the mask map, then sets the trigger event in the game area according to the mask value, and changes the behavior and status of the game character according to the trigger event.
[0056] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. A method for controlling the state of a game character using a terrain mask, characterized in that: The method comprises the following steps: Step S1: Draw the game terrain mask in grids, with each grid corresponding to a single mask; Step S2: marking various masks according to grid coordinates; Step S3: store the mask in a file and output it; Step S4: When loading the game, the game terminal reads the mask value in the file and sets a trigger event to achieve changes in the behavior and status of the game character; The step S3 is further specified as follows: the mask is stored as a DDS texture file, the game terrain page number is saved in the form of an image, each image pixel is a 32-bit value, and different types of mask values are filled in each of the 32 bits of the image pixel, thereby reducing the space occupied by the mask value.
2. The method of controlling the state of a game character using a terrain mask according to claim 1, wherein: The step S1 is further specifically as follows: setting the size ratio of a single mask in the game scene, the size of the mask is an integer multiple of the game terrain unit, and drawing grid lines on the game terrain according to the terrain size to facilitate observation and annotation of the type of mask in each grid.
3. The method of controlling the state of a game character using a terrain mask according to claim 1, wherein: The step S2 is further specifically as follows: a mask is brushed on the grid to determine whether the mask position is an attribute type affected by the environment. If yes, the masks of the attribute type affected by the environment are stored as the same type. If not, multiple types of masks are superimposed on each other and finally stored bit by bit.
4. The method of controlling the state of a game character using a terrain mask according to claim 1, wherein: The step S4 is further specifically as follows: when loading the game, the game client or server first reads out the mask map, then sets a trigger event in the game area according to the mask value, and changes the behavior and status of the game character according to the trigger event.
5. A system for controlling the state of a game character using a terrain mask, characterized in that: The system includes a drawing module, a labeling module, a storage module, and a triggering module. The drawing module draws the game terrain mask in grids, with each grid corresponding to a single mask. The labeling module labels various masks according to grid coordinates. The storage module stores the masks in a file and outputs them. The triggering module is used by the game terminal to read the mask value in the file when loading the game and set a trigger event to achieve changes in the behavior and status of the game character. The storage module is further specifically as follows: the mask is stored as a DDS texture file, the game terrain page number is saved in the form of an image, each image pixel is a 32-bit value, and different types of mask values are filled in each of the 32 bits of the image pixel, thereby reducing the space occupied by the mask value.
6. The system for controlling the state of a game character using a terrain mask according to claim 5, characterized in that: The drawing module is further specifically configured to: set the size ratio of a single mask in the game scene, the size of the mask is an integer multiple of the game terrain unit, and draw grid lines on the game terrain according to the terrain size to facilitate observation and annotation of the type of mask in each grid.
7. The system for controlling the state of a game character using a terrain mask according to claim 5, characterized in that: The marking module is further specifically as follows: a mask is brushed on the grid to determine whether the mask position is an attribute type affected by the environment. If yes, the masks of the attribute type affected by the environment are stored as the same type. If not, multiple types of masks are superimposed on each other and finally stored bit by bit.
8. The system for controlling the state of a game character using a terrain mask according to claim 5, characterized in that: When the game client or server loads the game, it first reads the mask map, then sets the trigger event in the game area according to the mask value, and changes the behavior and status of the game character according to the trigger event.
Citation Information
Patent Citations
Method and device for determining area where role is located, electronic equipment and storage medium
CN112774182A