Gomoblie Flappy Source analysis: Game logic

Source: Internet
Author: User
Tags gopher

This article mainly discusses the game rule logic, the concrete drawing technique please see related article:

Gomoblie Flappy Source Analysis: Image material and size processing
Http://www.cnblogs.com/ghj1976/p/5222289.html

Draw time interval control

The drawing is drawn at a tempo of 60 fps (i.e. frames per second), Fps:frames per second (frame rate)

The control note in the code is controlled by the time under Golang.org/x/mobile/exp/sprite/clock.

Type Time Int32
The application is initialized so that the time interval at which the value is initialized to FPS can start drawing.

Now it calculates how many 1/60 seconds (Time for FPS) to date.

And then pass in the game.update.

It is recalculated only if FPS is satisfied, otherwise it is not recalculated.

G.lastcale is also a clock. The time type.

As for paint. The frequency of event events being tuned, please refer to this text: http://www.cnblogs.com/ghj1976/p/5230576.html

In a nutshell, the screen resolution is 60Hz, which is 60 times per second, which is the logic below each turn.

Scene rendering

The whole scene is drawn in the area of 19*16 tiles, the hamster is 2*2 tile size, each floor tile is 16pt*16pt. So the drawing area is 304pt*256pt.

To be able to display the full height on the phone, the height of the screen needs to be 305pt/72*2.54 = 10.76 cm, the width due to insufficient, can show the part, but the aesthetic period, should not be greater than 256pt/72*2.54 = 9.03 cm, otherwise there will be some part of the screen is not drawing.

Note that the PT value of the Android device is not exactly 1/72 inches, see for reasons: http://www.cnblogs.com/ghj1976/p/5238193.html

The entire plotting logic is as follows:

From top to bottom is the logical order:

The entire scene is initialized at a speed of 1pt per 1/60 seconds, and the speed of 0.001 increase is constantly accelerating.

For example, each time the reset game, the reel speed of 1pt;

Before the game is over, speed up 0.001 each time, so the game reels are getting faster and harder.

Whenever the reel is longer than the length of a tile, it triggers the logic that creates the new tile.

Note that the maximum value of g.scroll.x is the length of a tile, and then it is automatically subtracted, see the following code:

The location of the sprite is drawn

Flappy this game has three types of elements that need to be drawn, where they plot the logical information as follows:

The initial position of the Gopher elf

The size of the Gopher is 32pt*32pt, and its location code is defined in the following function:

Func (g *game) Scene (Eng sprite. Engine) *sprite. Node {
X-axis coordinates

The x-axis coordinates of the gopher's upper-left corner are fixed: the position of the 2pt is calculated as follows:

The parameters are described as follows:

    • Gophertile:gopher standing on that brick, note that this is the index starting at 0, and 1 for the second block. The location of the hamster, judging whether the rat was killed or not, and the location of the ground when the hamster jumped up, depended on this global constant for calculation.
    • Tilewidth: The width of each tile.

From the above, the gopher stood at 1/8 of the first tile.

Y-Axis coordinates:
The calculation formula for y-axis coordinates of plot map is: G.gopher.y-tileheight + TILEHEIGHT/4
    • G.gopher.y
At the beginning of the game, the y-axis of the gopher is defined at the 0 position. Func (g *game) reset () {
G.GOPHER.Y = 0
    • Tileheight the height of the tiles.
The location of the Gopher station needs to be less than 3/4 of the floor tile height, so that the hamster is standing on the grass.
Note: minus 3/4 of the height of the floor tile, only draw when the effect of painting, with the height of the calculation Wizard Independent.

Sprite Jump Related

Triggers the sprite to jump whenever there is a touch screen event or the SPACEBAR is pressed.

When this action occurs, if the genie is on the ground, the takeoff acceleration is

If the sprite is in the fly state, the acceleration is-1.5 (this can only be triggered once per bounce, g.gopher.flapped = True when jumping up, g.gopher.flapped = false on landing).

Note that the acceleration becomes 0 immediately, not on time.

And each time the sprite information is calculated, it is necessary to reduce the acceleration according to gravity, the value of gravity is 0.1.

According to this logic, if you only press once, the highest can jump 5+4.9+4.8+...+0.2+0.1 = 127.5 pt high. If the best operation, when jumping to the top of the press again, will jump up 1.5+1.4+1.3+...+0.2+0.1=12 PT

Whether the judgment of landing

Note: When drawing, the height of the tile is subtracted from the height of the 3/4 tiles, which is only used when drawing the effect, regardless of the height of the calculation wizard. And when it is plotted, it is subtracted, whether on the ground or not.

The judgment of the Elves ' death

Whether the genie is dead or not is judged when the background is converted, not when the genie itself jumps or lands.

Each time you need to add a new tile, the first tile added logic, and then judge whether death.

After death, the scroll speed is gradually lowered to stop.

When the genie hits a height above the tile 1/3, it triggers death.
Climbgrace = TILEHEIGHT/3

Animation of the Fairy death

Each time the death is completed, the Genie flag dies, then the sprite jumps to make the death animation, the jump speed is 1.5 times times the normal jumping speed.

The wizard's Leap y-axis transformation logic is the same as before, except that the acceleration becomes larger.

When displayed, displays the death picture while doing the death rotation animation.

For a specific rotation animation, zoom in by time, move the center point, then rotate, and then move back to the previous coordinate system.

Starting from death, 4 seconds after the game reset.

Gomoblie Flappy Source analysis: Game logic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.