Debian Codegraph @

example/flappy/main.go

raw symbols SCIP
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 // Flappy Gopher is a simple one-button game that uses the
8 // mobile framework and the experimental sprite engine.
9 package mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/
10
11 import (
12 "math/randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/"
13 "timescip-go gomod github.com/golang/go/src go1.24.0 time/"
14
15 "golang.org/x/mobile/appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/"
16 "golang.org/x/mobile/event/keyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/"
17 "golang.org/x/mobile/event/lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/"
18 "golang.org/x/mobile/event/paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/"
19 "golang.org/x/mobile/event/sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/"
20 "golang.org/x/mobile/event/touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/"
21 "golang.org/x/mobile/exp/gl/glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/"
22 "golang.org/x/mobile/exp/spritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/"
23 "golang.org/x/mobile/exp/sprite/clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/"
24 "golang.org/x/mobile/exp/sprite/glspritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/glsprite`/"
25 "golang.org/x/mobile/glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/"
26 )
27
28 func mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/main().() {
29 randscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/.Seedscip-go gomod github.com/golang/go/src go1.24.0 `math/rand`/Seed().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.24.0 time/Time#UnixNano().())
30
31 appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/.Mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/Main().(func(a appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/.Appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#) {
32 var glctx glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#
33 var sz sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#
34 for e := range a.Eventsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Events.() {
35 switch e := a.Filterscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Filter.(e).(type) {
36 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#:
37 switch e.Crossesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#Crosses().(lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.StageVisiblescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/StageVisible.) {
38 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.CrossOnscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/CrossOn.:
39 glctx, _ = e.DrawContextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#DrawContext..(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#)
40 onStartscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onStart().(glctx)
41 a.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Send.(paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#{})
42 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.CrossOffscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/CrossOff.:
43 onStopscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onStop().()
44 glctx = nil
45 }
46 case sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#:
47 sz = e
48 case paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#:
49 if glctx == nil || e.Externalscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#External. {
50 continue
51 }
52 onPaintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onPaint().(glctx, sz)
53 a.Publishscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Publish.()
54 a.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Send.(paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#{}) // keep animating
55 case touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#:
56 if down := e.Typescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#Type. == touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/.TypeBeginscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/TypeBegin.; down || e.Typescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#Type. == touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/.TypeEndscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/TypeEnd. {
57 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)
58 }
59 case keyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/Event#:
60 if e.Codescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/Event#Code. != keyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/.CodeSpacebarscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/CodeSpacebar. {
61 break
62 }
63 if down := e.Directionscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/Event#Direction. == keyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/.DirPressscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/DirPress.; down || e.Directionscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/Event#Direction. == keyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/.DirReleasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/key`/DirRelease. {
64 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)
65 }
66 }
67 }
68 })
69 }
70
71 var (
72 startTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/startTime. = timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().()
73 imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/images. *glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/.Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#
74 engscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/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#
75 scenescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/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#
76 gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/game. *Gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/Game#
77 )
78
79 func onStartscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onStart().(glctx glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#) {
80 imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/images. = glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/.NewImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/NewImages().(glctx)
81 engscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/eng. = glspritescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/glsprite`/.Enginescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/glsprite`/Engine().(imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/images.)
82 gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/game. = NewGamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/NewGame().()
83 scenescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/scene. = 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().(engscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/eng.)
84 }
85
86 func onStopscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onStop().() {
87 engscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/eng..Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#Release.()
88 imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/images..Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#Release().()
89 gamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/game. = nil
90 }
91
92 func onPaintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/onPaint().(glctx glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#, sz sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#) {
93 glctx.ClearColorscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#ClearColor.(1, 1, 1, 1)
94 glctx.Clearscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#Clear.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.COLOR_BUFFER_BITscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/COLOR_BUFFER_BIT.)
95 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#(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Sincescip-go gomod github.com/golang/go/src go1.24.0 time/Since().(startTimescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/startTime.) * 60 / timescip-go gomod github.com/golang/go/src go1.24.0 time/.Secondscip-go gomod github.com/golang/go/src go1.24.0 time/Second.)
96 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)
97 engscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/eng..Renderscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite`/Engine#Render.(scenescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/example/flappy`/scene., now, sz)
98 }