Game object control method and device, readable storage medium and electronic equipment

文档序号:1452583 发布日期:2020-02-21 浏览:25次 中文

阅读说明:本技术 游戏对象的控制方法、装置、可读存储介质及电子设备 (Game object control method and device, readable storage medium and electronic equipment ) 是由 *** 方波 唐路遥 于 2019-10-31 设计创作,主要内容包括:本申请涉及游戏对象的控制方法、装置、可读存储介质及电子设备,属于电子游戏技术领域,本申请的控制方法,适用于蛇形游戏模型的移动实现和增长实现;针对移动实现,在每一渲染帧前的逻辑计算中:读取模型头部节点所对应的第一数组元素;基于第一数组元素包含的坐标、方向信息,以及模型节点间的固定间距,计算得到下一渲染时刻模型头部节点的新坐标;基于新坐标对模型尾部节点所对应的第二数组元素进行更新,将更新后的该数组元素摘除并添加到节点数组中第一数组元素之前。本申请可降低移动实现中逻辑计算带来的性能消耗,减少卡顿和发热,保证用户的游戏体验。(The application relates to a control method and a device of a game object, a readable storage medium and electronic equipment, belonging to the technical field of electronic games, wherein the control method is suitable for realizing the movement and growth of a snake-shaped game model; for mobile implementation, in the logical computation before each rendered frame: reading a first array element corresponding to a model head node; calculating to obtain new coordinates of the model head node at the next rendering moment based on the coordinates and the direction information contained in the first array element and the fixed distance between the model nodes; and updating a second array element corresponding to the tail node of the model based on the new coordinates, removing the updated array element and adding the updated array element to the node array before the first array element. The method and the device can reduce performance consumption caused by logic calculation in mobile implementation, reduce blocking and heating, and ensure game experience of users.)

1. A control method of game object is suitable for realizing movement and growth of snake-shaped game model, and is characterized in that the game model is mapped into a node array, and array elements in the node array correspond to each node of the model one by one; for mobile implementation, in the logical computation before each rendered frame:

reading a first array element corresponding to a model head node;

calculating to obtain new coordinates of the model head node at the next rendering moment based on the coordinates and the direction information contained in the first array element and the fixed distance between the model nodes;

and updating a second array element corresponding to the tail node of the model based on the new coordinates, removing the updated array element and adding the updated array element to the node array before the first array element.

2. The control method according to claim 1, wherein the array element comprises a direction field for storing a direction angle of the node and a coordinate field for storing coordinates of the node, and the new coordinates of the model head node at the next rendering time are calculated based on the coordinates and direction information included in the first array position element and a fixed distance between the model nodes, specifically,

calculating sine and cosine values of the node direction angles in the first array element direction domain;

multiplying the cosine value by the fixed interval to obtain an abscissa change value, and multiplying the sine value by the fixed interval to obtain an ordinate change value;

and adding the horizontal coordinate and the vertical coordinate in the first array element coordinate domain with the horizontal coordinate change value and the vertical coordinate change value correspondingly respectively to calculate and obtain a new coordinate of the model head node at the next rendering moment.

3. The control method according to claim 2, wherein the node direction angle in the first array element direction field is an included angle between a model head node movement direction and a coordinate axis, and the model head node movement direction is determined based on a control instruction input by a user.

4. The control method according to claim 2, characterized in that the second array element corresponding to the model tail node is updated based on the new coordinates, in particular,

and updating the coordinate value in the second array element coordinate domain to be the value of the new coordinate, and updating the node direction angle value in the second array element direction domain to be the node direction angle value in the first array element direction domain.

5. Control method according to claim 1, characterized in that for a growth implementation, in the logical calculation before each rendered frame:

reading a third array element corresponding to the first position node at the tail part of the model and a fourth array element corresponding to the second position node at the tail part of the model;

determining the direction of the tail of the model according to the coordinate information contained in the third array element and the fourth array element;

calculating to obtain the coordinates of the newly added nodes according to the pointing direction, the coordinate information contained in the third array element and the fixed distance between the model nodes;

and creating an array element corresponding to the newly added node according to the coordinate of the newly added node, and adding the array element to the node array after the third array element.

6. The control method according to claim 5, wherein the direction of the model tail is determined based on the coordinate information contained in the third array element and the fourth array element, and specifically,

correspondingly calculating the difference value of the abscissa and the difference value of the ordinate of the fourth array element and the third array element;

and calculating a direction included angle between the tail direction of the model and the coordinate axis according to the obtained ratio of the longitudinal coordinate difference value to the transverse coordinate difference value on the basis of the tangent trigonometric function so as to determine the direction of the tail of the model.

7. The control method according to claim 6, wherein the coordinates of the newly added node are calculated according to the coordinate information included in the direction and the third array element and the fixed distance between the model nodes, specifically,

calculating sine and cosine values of the included angle of the directions;

multiplying the cosine value of the direction included angle with the fixed interval to obtain an abscissa increasing value, and multiplying the sine value of the direction included angle with the fixed interval to obtain an ordinate increasing value;

and respectively and correspondingly adding the horizontal coordinate and the vertical coordinate of the node contained in the third array element with the horizontal coordinate increment value and the vertical coordinate increment value to calculate to obtain the coordinate of the newly added node.

8. A control device for a game object, comprising:

the reading module is used for reading a first array element corresponding to a model head node;

the calculation module is used for calculating and obtaining new coordinates of the head nodes of the model at the next rendering moment based on the coordinates and the direction information contained in the first array elements and the fixed distance between the model nodes;

and the updating operation module is used for updating the second array element corresponding to the tail node of the model based on the new coordinates, removing the updated array element and adding the updated array element to the node array before the first array element.

9. A readable storage medium having stored thereon an executable program, wherein the executable program, when executed by a processor, performs the steps of the method of any one of claims 1-7.

10. An electronic device, comprising:

a memory having an executable program stored thereon;

a processor for executing the executable program in the memory to implement the steps of the method of any one of claims 1-7.

Technical Field

The application belongs to the technical field of electronic games, and particularly relates to a game object control method and device, a readable storage medium and electronic equipment.

Background

At present, with the development of smart phones and mobile internet, mobile phone network games become another hot field at present, and some classical mobile phone standalone games are revived after network battle development and are pursued by players. For example, a classical greedy snake game is re-developed, network fight elements are added on the basis of a traditional play method, a plurality of players operate respective greedy snakes to fight, and therefore the playability of the game is improved.

However, in the traditional implementation of the development of the greedy snake, in the implementation of the function of the greedy snake movement, the coordinates of the next position of the nodes of the snake head are calculated according to the operation direction of the player and are rendered on the screen, and the nodes behind the snake head sequentially acquire the coordinates and the direction of the previous nodes and update the coordinates and the direction of the nodes and render on the screen, so that the movement of one frame is finally completed. According to the implementation method, the longer the snake is, the longer the calculation time is, the more the game picture is stuck, and particularly for the scene of multi-snake confrontation, the game stuck can seriously affect the experience of the player.

Disclosure of Invention

In order to overcome the problems in the related art at least to a certain extent, the application provides a control method and device of a game object, a readable storage medium and an electronic device, which are beneficial to reducing the calculation amount in game implementation and efficiently realizing the movement of the game object.

In order to achieve the purpose, the following technical scheme is adopted in the application:

in a first aspect,

the application provides a control method of a game object, which is suitable for realizing the movement and growth of a snake-shaped game model, wherein the game model is mapped into a node array, and array elements in the node array correspond to nodes of the model one by one; for mobile implementation, in the logical computation before each rendered frame:

reading a first array element corresponding to a model head node;

calculating to obtain new coordinates of the model head node at the next rendering moment based on the coordinates and the direction information contained in the first array element and the fixed distance between the model nodes;

and updating a second array element corresponding to the tail node of the model based on the new coordinates, removing the updated array element and adding the updated array element to the node array before the first array element.

Optionally, the array element includes a direction field for storing a node direction angle, and a coordinate field for storing a node coordinate, and the new coordinate of the model head node at the next rendering time is calculated based on the coordinate and the direction information included in the first array position element, and the fixed distance between the model nodes, specifically,

calculating sine and cosine values of the node direction angles in the first array element direction domain;

multiplying the cosine value by the fixed interval to obtain an abscissa change value, and multiplying the sine value by the fixed interval to obtain an ordinate change value;

and adding the horizontal coordinate and the vertical coordinate in the first array element coordinate domain with the horizontal coordinate change value and the vertical coordinate change value correspondingly respectively to calculate and obtain a new coordinate of the model head node at the next rendering moment.

Optionally, the node direction angle in the first array element direction domain is an included angle between a model head node movement direction and a coordinate axis, and the model head node movement direction is determined based on a control instruction input by a user.

Optionally, the second array element corresponding to the tail node of the model is updated based on the new coordinates, specifically,

and updating the coordinate value in the second array element coordinate domain to be the value of the new coordinate, and updating the node direction angle value in the second array element direction domain to be the node direction angle value in the first array element direction domain.

Optionally, for the grow implementation, in the logical computation before each rendered frame:

reading a third array element corresponding to the first position node at the tail part of the model and a fourth array element corresponding to the second position node at the tail part of the model;

determining the direction of the tail of the model according to the coordinate information contained in the third array element and the fourth array element;

calculating to obtain the coordinates of the newly added nodes according to the pointing direction, the coordinate information contained in the third array element and the fixed distance between the model nodes;

and creating an array element corresponding to the newly added node according to the coordinate of the newly added node, and adding the array element to the node array after the third array element.

Optionally, the pointing direction of the tail of the model is determined based on the coordinate information contained in the third array element and the fourth array element, specifically,

correspondingly calculating the difference value of the abscissa and the difference value of the ordinate of the fourth array element and the third array element;

and calculating a direction included angle between the tail direction of the model and the coordinate axis according to the obtained ratio of the longitudinal coordinate difference value to the transverse coordinate difference value on the basis of the tangent trigonometric function so as to determine the direction of the tail of the model.

Optionally, the coordinates of the newly added node are obtained by calculation according to the pointing direction, the coordinate information included in the third array element, and the fixed distance between the model nodes, specifically,

calculating sine and cosine values of the included angle of the directions;

multiplying the cosine value of the direction included angle with the fixed interval to obtain an abscissa increasing value, and multiplying the sine value of the direction included angle with the fixed interval to obtain an ordinate increasing value;

and respectively and correspondingly adding the horizontal coordinate and the vertical coordinate of the node contained in the third array element with the horizontal coordinate increment value and the vertical coordinate increment value to calculate to obtain the coordinate of the newly added node.

In a second aspect of the present invention,

the application provides a control device of a game object, comprising:

the reading module is used for reading a first array element corresponding to a model head node;

the calculation module is used for calculating and obtaining new coordinates of the head nodes of the model at the next rendering moment based on the coordinates and the direction information contained in the first array elements and the fixed distance between the model nodes;

and the updating operation module is used for updating the second array element corresponding to the tail node of the model based on the new coordinates, removing the updated array element and adding the updated array element to the node array before the first array element.

In a third aspect,

the present application provides a readable storage medium having stored thereon an executable program which, when executed by a processor, performs the steps of the method described above.

In a fourth aspect of the present invention,

the application provides an electronic device, including:

a memory having an executable program stored thereon;

a processor for executing the executable program in the memory to implement the steps of the method described above.

This application adopts above technical scheme, possesses following beneficial effect at least:

aiming at the movement realization of the snake-shaped game model, the technical scheme of the invention splices the tail node of the snake to the head of the snake in each frame of movement, only relates to the head node and the tail node in logic calculation, and has no relation with the length of the snake, thereby greatly reducing the performance consumption caused by the logic calculation in the movement realization, reducing the jamming and the heating and ensuring the game experience of a user.

Additional advantages, objects, and features of the invention will be set forth in part in the description which follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.

Drawings

The accompanying drawings are included to provide a further understanding of the technology or prior art of the present application and are incorporated in and constitute a part of this specification. The drawings expressing the embodiments of the present application are used for explaining the technical solutions of the present application, and should not be construed as limiting the technical solutions of the present application.

Fig. 1 is a schematic flow chart illustrating a mobile implementation in a control method for a game object according to an embodiment of the present application;

FIG. 2 is a schematic diagram illustrating an implementation of model movement in one embodiment of the present application;

FIG. 3 is a schematic diagram illustrating an implementation of model growth in one embodiment of the present application;

FIG. 4 is a schematic structural diagram of a control device for a game object according to an embodiment of the present application;

fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.

Detailed Description

In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail below. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the examples given herein without making any creative effort, shall fall within the protection scope of the present application.

As described in the background art, in the conventional greedy snake game, the snake movement is realized, the longer the snake is, the longer the calculation time is, the more the game picture is stuck, and in the scene of multi-snake confrontation, the stuck state can seriously affect the experience of a player.

In view of the above problems in the prior art, the present application provides a method for controlling a game object, which is suitable for implementing movement and growth of a snake-shaped game model. The control method of the present invention will be described below with reference to an embodiment.

In this embodiment, the game is a greedy snake game, the game model is mapped into a node array, and the array elements in the node array correspond to the nodes of the model one to one.

It is well known that the movement and growth of in-game models enables logical computation and rendering display involving related graphics. In the technical solution of the present application, as shown in fig. 1 and fig. 2, for mobile implementation, in the logic calculation before each rendering frame, the following steps are respectively performed:

step S110, reading a first array element corresponding to a model head node 1;

step S120, calculating to obtain new coordinates of the model head node at the next rendering moment based on the coordinates and the direction information contained in the first array element and the fixed distance between the model nodes;

specifically, in this embodiment, the array elements in the node array include a direction field for storing the direction angle of the node and a coordinate field for storing the coordinates of the node. The node direction angle is an included angle between the node motion direction and a coordinate axis, and the node coordinate is an absolute coordinate of the model node in an XY plane coordinate system of the display area.

And it is easy to understand that the node direction angle in the direction domain of the first array element corresponding to the model head node 1 is the included angle between the motion direction of the model head node and the coordinate axis, and the motion direction of the model head node is determined based on the control command input by the user, that is, the motion direction is calculated and determined according to the steering control command input by the user and the original motion direction of the head node.

For example, in this embodiment, the first array element coordinate field stores node coordinates (x1, y1), the first array element direction field stores a node direction angle a (as shown in fig. 2, if the movement direction of the head node after determination is vertical and upward, a is 90 degrees), then a new coordinate of the head node of the model at the next rendering time is obtained by calculation in step S120, specifically,

calculating the sine and cosine values of the node direction angles in the first array element direction domain, namely calculating sinA and cosA;

multiplying the cosine value cosA obtained by calculation by the fixed interval to obtain an abscissa change value dx, and multiplying the sine value sinA obtained by calculation by the fixed interval to obtain an ordinate change value dy;

and adding the abscissa x1 and the ordinate y1 in the first array element coordinate domain with the abscissa change value dx and the ordinate change value dy correspondingly respectively to calculate a new coordinate of the model head node at the next rendering time. I.e. new coordinates (x1+ dx, y1+ dy) are calculated.

And then, step S130 is performed, the second array element corresponding to the model tail node 2 is updated based on the new coordinates, and the updated array element is removed and added to the node array before the first array element.

Specifically, in this embodiment, the updating the second array element specifically includes updating the coordinate values in the second array element coordinate domain to the values of the new coordinates (x1+ dx, y1+ dy), and updating the node direction angle values in the second array element direction domain to the node direction angle values a in the first array element direction domain. And then removing the updated array element and adding the updated array element to the node array before the first array element, so that the logic calculation is completed.

And after the logic calculation is finished, rendering frames, namely rendering and displaying based on the node array data corresponding to the game model. Here, as in the prior art, each array element of the logically calculated node array is rendered, and each node is correspondingly displayed in the frame based on the data information included in each array element, thereby completing the implementation of movement in one frame.

Fig. 2 is a schematic diagram illustrating the implementation of the movement, such as "before movement", to "in movement", and to "after movement" in fig. 2, the movement in one frame is implemented substantially by splicing the tail node of the snake to the head of the snake in the present application. In the splicing, the logic calculation only relates to a head node and a tail node, the length of the snake is irrelevant, and the nodes at other positions keep original shapes without calculation, so that the performance consumption caused by the logic calculation in the mobile implementation can be greatly reduced, the blocking and the heating are reduced, and the game experience of a user is ensured.

Similarly, by repeating steps S110 to S130 in the logic calculation between the rendering frames, for example, by continuously repeating steps S110 to S130 in the logic calculation after the preparation for the next frame movement in fig. 2, the game object can be continuously moved.

In the method for controlling a game object in the present application, the method further includes a growth implementation, and in the greedy snake game in this embodiment, as shown in fig. 3, in the logic calculation before each rendering frame, for the growth implementation:

firstly, reading a third array element corresponding to a first position node 3 at the tail part of the model and a fourth array element corresponding to a second position node 4 at the tail part of the model;

then, according to the coordinate information contained in the third array element and the fourth array element, determining the direction of the tail of the model (the direction of the dotted line in fig. 3);

specifically, the difference between the abscissa and the ordinate of the fourth array element and the third array element is calculated correspondingly, for example, the node coordinates included in the third array element are (x3, y3), and the node coordinates included in the third array element are (x4, y4), that is, the difference between the ordinate and the abscissa is y4-y3, and the difference between the abscissa and the abscissa is x4-x 3;

based on a tangent trigonometric function, calculating a direction included angle B between the direction of the tail of the model and the coordinate axis according to the ratio of the obtained vertical coordinate difference value delta y and the obtained horizontal coordinate difference value delta x (namely calculating B according to tanB being delta y/delta x) so as to determine the direction of the tail of the model.

Then, calculating to obtain the coordinate of the newly added node 5 according to the pointing direction, coordinate information contained in the third array element and the fixed distance between the model nodes;

specifically, calculating a sine value sinB and a cosine value cosB of the direction included angle;

multiplying the cosine value cosB of the direction included angle by the fixed distance to obtain an abscissa increasing value gx, and multiplying the sine value sinB of the direction included angle by the fixed distance to obtain an ordinate increasing value gy;

then, the abscissa x3 and the ordinate y3 of the node included in the third array element are respectively added to the abscissa gain gx and the ordinate gain gy to calculate the coordinates of the newly added node (x5 ═ x3+ gx, y5 ═ y3+ gy).

And finally, creating an array element corresponding to the newly added node according to the coordinates (x5, y5) of the newly added node, and adding the array element to a third array element in the node array, so that the logic calculation is completed.

And after the logic calculation is finished, rendering a frame, rendering each array element of the node array after the logic calculation, and correspondingly displaying each node in the frame based on the data information contained in each array element, thereby finishing the growth realization in one frame.

Fig. 3 is a schematic diagram illustrating a growth implementation, and as shown in fig. 3 from "before growth", to "during growth", to "after growth", in a frame of the present application, the growth implementation is performed in a direction determined by the last two nodes of the snake, a newly added node is added to the tail of the snake, and the snake does not have an instantaneous length change, so that the control of the player on the direction of the snake is not affected, and the problem that the steering of the player is affected by the sudden change of the length of the head in the existing growth implementation is also avoided, thereby improving the game experience of the player.

Fig. 4 is a schematic structural diagram of a control device for a game object according to an embodiment of the present application, and as shown in fig. 4, the control device 400 for a game object includes:

a reading module 401, configured to read a first array element corresponding to a model head node;

a calculating module 402, configured to calculate new coordinates of a model head node at a next rendering time based on coordinates and direction information included in the first array element and a fixed distance between model nodes;

the update operation module 403 is configured to update the second array element corresponding to the tail node of the model based on the new coordinate, remove the updated array element, and add the removed updated array element to the node array before the first array element.

With respect to the control apparatus 400 for game objects in the above-described related embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be described in detail here.

In one embodiment, the present application provides a readable storage medium having stored thereon an executable program, which when executed by a processor, performs the steps of the above-described method.

With regard to the readable storage medium in the above-mentioned embodiments, the specific manner of executing the operation by the stored program has been described in detail in the embodiments related to the method, and will not be elaborated herein.

Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application, and as shown in fig. 5, the electronic device 500 includes:

a memory 501 on which an executable program is stored;

a processor 502 for executing the executable program in the memory 501 to implement the steps of the above-described method.

With respect to the electronic device 500 in the above embodiment, the specific manner of executing the program in the memory 501 by the processor 502 thereof has been described in detail in the embodiment related to the method, and will not be elaborated herein.

The above description is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:虚拟世界中的虚拟表面判断方法、装置、设备及介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类