| 1 | // Copyright 2015 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build darwin || linux |
| 6 | |
| 7 | package mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/ |
| 8 | |
| 9 | import ( |
| 10 | "imagescip-go gomod github.com/golang/go/src go1.24.0 image/" |
| 11 | "logscip-go gomod github.com/golang/go/src go1.24.0 log/" |
| 12 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 13 | "math/randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/" |
| 14 | |
| 15 | _ "image/pngscip-go gomod github.com/golang/go/src go1.24.0 `image/png`/" |
| 16 | |
| 17 | "golang.org/x/mobile/assetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/asset`/" |
| 18 | "golang.org/x/mobile/exp/f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/" |
| 19 | "golang.org/x/mobile/exp/spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/" |
| 20 | "golang.org/x/mobile/exp/sprite/clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/" |
| 21 | ) |
| 22 | |
| 23 | const ( |
| 24 | tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth., tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. = 16, 16 // width and height of each tile |
| 25 | tilesXscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesX., tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY. = 16, 16 // number of horizontal tiles |
| 26 | |
| 27 | gopherTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gopherTile. = 1 // which tile the gopher is standing on (0-indexed) |
| 28 | |
| 29 | initScrollVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/initScrollV. = 1 // initial scroll velocity |
| 30 | scrollAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/scrollA. = 0.001 // scroll acceleration |
| 31 | gravityscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gravity. = 0.1 // gravity |
| 32 | jumpVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/jumpV. = -5 // jump velocity |
| 33 | flapVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/flapV. = -1.5 // flap velocity |
| 34 | |
| 35 | deadScrollAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/deadScrollA. = -0.01 // scroll deceleration after the gopher dies |
| 36 | deadTimeBeforeResetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/deadTimeBeforeReset. = 240 // how long to wait before restarting the game |
| 37 | |
| 38 | groundChangeProbscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundChangeProb. = 5 // 1/probability of ground height change |
| 39 | groundWobbleProbscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundWobbleProb. = 3 // 1/probability of minor ground height change |
| 40 | groundMinscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundMin. = tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. * (tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY. - 2*tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY./5) |
| 41 | groundMaxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundMax. = tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. * tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY. |
| 42 | initGroundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/initGroundY. = tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. * (tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY. - 1) |
| 43 | |
| 44 | climbGracescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/climbGrace. = tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. / 3 // gopher won't die if it hits a cliff this high |
| 45 | ) |
| 46 | |
| 47 | type Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game# struct { |
| 48 | gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher. struct { |
| 49 | yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. float32 // y-offset |
| 50 | vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. float32 // velocity |
| 51 | atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest. bool // is the gopher on the ground? |
| 52 | flappedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#flapped. bool // has the gopher flapped since it became airborne? |
| 53 | deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. bool // is the gopher dead? |
| 54 | deadTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#deadTime. clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time# // when the gopher died |
| 55 | } |
| 56 | scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll. struct { |
| 57 | xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x. float32 // x-offset |
| 58 | vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. float32 // velocity |
| 59 | } |
| 60 | groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY. [tilesXscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesX. + 3]float32 // ground y-offsets |
| 61 | groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex. [tilesXscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesX. + 3]int // ground texture |
| 62 | lastCalcscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#lastCalc. clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time# // when we last calculated a frame |
| 63 | } |
| 64 | |
| 65 | func NewGamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/NewGame().() *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game# { |
| 66 | var g Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game# |
| 67 | g.resetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#reset().() |
| 68 | return &g |
| 69 | } |
| 70 | |
| 71 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) resetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#reset().() { |
| 72 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. = 0 |
| 73 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = 0 |
| 74 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x. = 0 |
| 75 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. = initScrollVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/initScrollV. |
| 76 | for i := range g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY. { |
| 77 | g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[i] = initGroundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/initGroundY. |
| 78 | g.groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex.[i] = randomGroundTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/randomGroundTexture().() |
| 79 | } |
| 80 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest. = false |
| 81 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..flappedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#flapped. = false |
| 82 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. = false |
| 83 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#deadTime. = 0 |
| 84 | } |
| 85 | |
| 86 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) Scenescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#Scene().(eng spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#) *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node# { |
| 87 | texs := loadTexturesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/loadTextures().(eng) |
| 88 | |
| 89 | scene := &spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#{} |
| 90 | eng.Registerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#Register.(scene) |
| 91 | eng.SetTransformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetTransform.(scene, f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 92 | {1, 0, 0}, |
| 93 | {0, 1, 0}, |
| 94 | }) |
| 95 | |
| 96 | newNode := func(fn arrangerFuncscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/arrangerFunc#) { |
| 97 | n := &spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#{Arrangerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#Arranger.: arrangerFuncscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/arrangerFunc#(fn)} |
| 98 | eng.Registerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#Register.(n) |
| 99 | scene.AppendChildscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#AppendChild().(n) |
| 100 | } |
| 101 | |
| 102 | // The ground. |
| 103 | for i := range g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY. { |
| 104 | i := i |
| 105 | // The top of the ground. |
| 106 | newNode(func(eng spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#, n *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { |
| 107 | eng.SetSubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetSubTex.(n, texs[g.groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex.[i]]) |
| 108 | eng.SetTransformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetTransform.(n, f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 109 | {tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth., 0, float32(i)*tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth. - g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x.}, |
| 110 | {0, tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight., g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[i]}, |
| 111 | }) |
| 112 | }) |
| 113 | // The earth beneath. |
| 114 | newNode(func(eng spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#, n *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { |
| 115 | eng.SetSubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetSubTex.(n, texs[texEarthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texEarth.]) |
| 116 | eng.SetTransformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetTransform.(n, f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 117 | {tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth., 0, float32(i)*tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth. - g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x.}, |
| 118 | {0, tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. * tilesYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tilesY., g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[i] + tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight.}, |
| 119 | }) |
| 120 | }) |
| 121 | } |
| 122 | |
| 123 | // The gopher. |
| 124 | newNode(func(eng spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#, n *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { |
| 125 | a := f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 126 | {tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth. * 2, 0, tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth.*(gopherTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gopherTile.-1) + tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth./8}, |
| 127 | {0, tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. * 2, g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. - tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. + tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight./4}, |
| 128 | } |
| 129 | var x int |
| 130 | switch { |
| 131 | case g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead.: |
| 132 | x = framescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/frame().(t, 16, texGopherDead1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead1., texGopherDead2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead2.) |
| 133 | animateDeadGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/animateDeadGopher().(&a, t-g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#deadTime.) |
| 134 | case g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. < 0: |
| 135 | x = framescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/frame().(t, 4, texGopherFlap1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap1., texGopherFlap2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap2.) |
| 136 | case g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest.: |
| 137 | x = framescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/frame().(t, 4, texGopherRun1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun1., texGopherRun2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun2.) |
| 138 | default: |
| 139 | x = framescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/frame().(t, 8, texGopherRun1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun1., texGopherRun2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun2.) |
| 140 | } |
| 141 | eng.SetSubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetSubTex.(n, texs[x]) |
| 142 | eng.SetTransformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#SetTransform.(n, a) |
| 143 | }) |
| 144 | |
| 145 | return scene |
| 146 | } |
| 147 | |
| 148 | // frame returns the frame for the given time t |
| 149 | // when each frame is displayed for duration d. |
| 150 | func framescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/frame().(t, d clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#, frames ...int) int { |
| 151 | total := int(d) * len(frames) |
| 152 | return frames[(int(t)%total)/int(d)] |
| 153 | } |
| 154 | |
| 155 | func animateDeadGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/animateDeadGopher().(a *f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { |
| 156 | dt := float32(t) |
| 157 | a.Scalescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Scale().(a, 1+dt/20, 1+dt/20) |
| 158 | a.Translatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Translate().(a, 0.5, 0.5) |
| 159 | a.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(a, dt/mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi./-8) |
| 160 | a.Translatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Translate().(a, -0.5, -0.5) |
| 161 | } |
| 162 | |
| 163 | type arrangerFuncscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/arrangerFunc# func(e spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#, n *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) |
| 164 | |
| 165 | func (a arrangerFuncscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/arrangerFunc#) Arrangescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/arrangerFunc#Arrange().(e spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#, n *spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Nodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Node#, t clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { a(e, n, t) } |
| 166 | |
| 167 | const ( |
| 168 | texGopherRun1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun1. = iota |
| 169 | texGopherRun2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun2. |
| 170 | texGopherFlap1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap1. |
| 171 | texGopherFlap2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap2. |
| 172 | texGopherDead1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead1. |
| 173 | texGopherDead2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead2. |
| 174 | texGround1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround1. |
| 175 | texGround2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround2. |
| 176 | texGround3scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround3. |
| 177 | texGround4scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround4. |
| 178 | texEarthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texEarth. |
| 179 | ) |
| 180 | |
| 181 | func randomGroundTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/randomGroundTexture().() int { |
| 182 | return texGround1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround1. + randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Intn().(4) |
| 183 | } |
| 184 | |
| 185 | func loadTexturesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/loadTextures().(eng spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#) []spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex# { |
| 186 | a, err := assetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/asset`/.Openscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/asset`/Open().("sprite.png") |
| 187 | if err != nil { |
| 188 | logscip-go gomod github.com/golang/go/src go1.24.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.24.0 log/Fatal().(err) |
| 189 | } |
| 190 | defer a.Closescip-go gomod github.com/golang/go/src go1.24.0 io/Closer#Close().() |
| 191 | |
| 192 | m, _, err := imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Decodescip-go gomod github.com/golang/go/src go1.24.0 image/Decode().(a) |
| 193 | if err != nil { |
| 194 | logscip-go gomod github.com/golang/go/src go1.24.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.24.0 log/Fatal().(err) |
| 195 | } |
| 196 | t, err := eng.LoadTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#LoadTexture.(m) |
| 197 | if err != nil { |
| 198 | logscip-go gomod github.com/golang/go/src go1.24.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.24.0 log/Fatal().(err) |
| 199 | } |
| 200 | |
| 201 | const n = 128 |
| 202 | // The +1's and -1's in the rectangles below are to prevent colors from |
| 203 | // adjacent textures leaking into a given texture. |
| 204 | // See: http://stackoverflow.com/questions/19611745/opengl-black-lines-in-between-tiles |
| 205 | return []spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{ |
| 206 | texGopherRun1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun1.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*0+1, 0, n*1-1, n)}, |
| 207 | texGopherRun2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherRun2.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*1+1, 0, n*2-1, n)}, |
| 208 | texGopherFlap1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap1.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*2+1, 0, n*3-1, n)}, |
| 209 | texGopherFlap2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherFlap2.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*3+1, 0, n*4-1, n)}, |
| 210 | texGopherDead1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead1.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*4+1, 0, n*5-1, n)}, |
| 211 | texGopherDead2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGopherDead2.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*5+1, 0, n*6-1, n)}, |
| 212 | texGround1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround1.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*6+1, 0, n*7-1, n)}, |
| 213 | texGround2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround2.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*7+1, 0, n*8-1, n)}, |
| 214 | texGround3scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround3.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*8+1, 0, n*9-1, n)}, |
| 215 | texGround4scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texGround4.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*9+1, 0, n*10-1, n)}, |
| 216 | texEarthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/texEarth.: spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/.SubTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/SubTex#{t, imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(n*10+1, 0, n*11-1, n)}, |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) Pressscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#Press().(down bool) { |
| 221 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. { |
| 222 | // Player can't control a dead gopher. |
| 223 | return |
| 224 | } |
| 225 | |
| 226 | if down { |
| 227 | switch { |
| 228 | case g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest.: |
| 229 | // Gopher may jump from the ground. |
| 230 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = jumpVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/jumpV. |
| 231 | case !g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..flappedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#flapped.: |
| 232 | // Gopher may flap once in mid-air. |
| 233 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..flappedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#flapped. = true |
| 234 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = flapVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/flapV. |
| 235 | } |
| 236 | } else { |
| 237 | // Stop gopher rising on button release. |
| 238 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. < 0 { |
| 239 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = 0 |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) Updatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#Update().(now clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/.Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#) { |
| 245 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. && now-g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#deadTime. > deadTimeBeforeResetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/deadTimeBeforeReset. { |
| 246 | // Restart if the gopher has been dead for a while. |
| 247 | g.resetscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#reset().() |
| 248 | } |
| 249 | |
| 250 | // Compute game states up to now. |
| 251 | for ; g.lastCalcscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#lastCalc. < now; g.lastCalcscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#lastCalc.++ { |
| 252 | g.calcFramescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcFrame().() |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) calcFramescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcFrame().() { |
| 257 | g.calcScrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcScroll().() |
| 258 | g.calcGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcGopher().() |
| 259 | } |
| 260 | |
| 261 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) calcScrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcScroll().() { |
| 262 | // Compute velocity. |
| 263 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. { |
| 264 | // Decrease scroll speed when the gopher dies. |
| 265 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. += deadScrollAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/deadScrollA. |
| 266 | if g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. < 0 { |
| 267 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. = 0 |
| 268 | } |
| 269 | } else { |
| 270 | // Increase scroll speed. |
| 271 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. += scrollAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/scrollA. |
| 272 | } |
| 273 | |
| 274 | // Compute offset. |
| 275 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x. += g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#v. |
| 276 | |
| 277 | // Create new ground tiles if we need to. |
| 278 | for g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x. > tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth. { |
| 279 | g.newGroundTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#newGroundTile().() |
| 280 | |
| 281 | // Check whether the gopher has crashed. |
| 282 | // Do this for each new ground tile so that when the scroll |
| 283 | // velocity is >tileWidth/frame it can't pass through the ground. |
| 284 | if !g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. && g.gopherCrashedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopherCrashed().() { |
| 285 | g.killGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#killGopher().() |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) calcGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#calcGopher().() { |
| 291 | // Compute velocity. |
| 292 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. += gravityscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gravity. |
| 293 | |
| 294 | // Compute offset. |
| 295 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. += g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. |
| 296 | |
| 297 | g.clampToGroundscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#clampToGround().() |
| 298 | } |
| 299 | |
| 300 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) newGroundTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#newGroundTile().() { |
| 301 | // Compute next ground y-offset. |
| 302 | next := g.nextGroundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#nextGroundY().() |
| 303 | nextTex := randomGroundTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/randomGroundTexture().() |
| 304 | |
| 305 | // Shift ground tiles to the left. |
| 306 | g.scrollscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#scroll..xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_df75ea82f51f2b44#x. -= tileWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileWidth. |
| 307 | copy(g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[:], g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[1:]) |
| 308 | copy(g.groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex.[:], g.groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex.[1:]) |
| 309 | last := len(g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.) - 1 |
| 310 | g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[last] = next |
| 311 | g.groundTexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundTex.[last] = nextTex |
| 312 | } |
| 313 | |
| 314 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) nextGroundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#nextGroundY().() float32 { |
| 315 | prev := g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[len(g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.)-1] |
| 316 | if change := randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Intn().(groundChangeProbscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundChangeProb.) == 0; change { |
| 317 | return (groundMaxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundMax.-groundMinscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundMin.)*randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Float32scip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Float32().() + groundMinscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundMin. |
| 318 | } |
| 319 | if wobble := randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Intn().(groundWobbleProbscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/groundWobbleProb.) == 0; wobble { |
| 320 | return prev + (randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Float32scip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Float32().()-0.5)*climbGracescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/climbGrace. |
| 321 | } |
| 322 | return prev |
| 323 | } |
| 324 | |
| 325 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) gopherCrashedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopherCrashed().() bool { |
| 326 | return g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y.+tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight.-climbGracescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/climbGrace. > g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[gopherTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gopherTile.+1] |
| 327 | } |
| 328 | |
| 329 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) killGopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#killGopher().() { |
| 330 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. = true |
| 331 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#deadTime. = g.lastCalcscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#lastCalc. |
| 332 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = jumpVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/jumpV. * 1.5 // Bounce off screen. |
| 333 | } |
| 334 | |
| 335 | func (g *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#) clampToGroundscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#clampToGround().() { |
| 336 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..deadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#dead. { |
| 337 | // Allow the gopher to fall through ground when dead. |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | // Compute the minimum offset of the ground beneath the gopher. |
| 342 | minY := g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[gopherTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gopherTile.] |
| 343 | if y := g.groundYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#groundY.[gopherTilescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/gopherTile.+1]; y < minY { |
| 344 | minY = y |
| 345 | } |
| 346 | |
| 347 | // Prevent the gopher from falling through the ground. |
| 348 | maxGopherY := minY - tileHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/tileHeight. |
| 349 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest. = false |
| 350 | if g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. >= maxGopherY { |
| 351 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..vscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#v. = 0 |
| 352 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#y. = maxGopherY |
| 353 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..atRestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#atRest. = true |
| 354 | g.gopherscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#gopher..flappedscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#$anon_0ae4af38ae072a92#flapped. = false |
| 355 | } |
| 356 | } |