forked from scraly/learning-go-by-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopher.go
75 lines (59 loc) · 1.67 KB
/
gopher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"image/color"
"machine"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
)
var (
//KeyCodes / Buttons
keyDOWN = uint16(895)
keyUP = uint16(959)
keyLEFT = uint16(991)
keyRIGHT = uint16(1007)
keyLSHOULDER = uint16(511)
keyRSHOULDER = uint16(767)
keyA = uint16(1022)
keyB = uint16(1021)
keySTART = uint16(1015)
keySELECT = uint16(1019)
// Register display
regDISPSTAT = (*volatile.Register16)(unsafe.Pointer(uintptr(0x4000004)))
// Register keypad
regKEYPAD = (*volatile.Register16)(unsafe.Pointer(uintptr(0x04000130)))
// Display from machine
display = machine.Display
// Screen resolution
screenWidth, screenHeight = display.Size()
// Colors
black = color.RGBA{}
white = color.RGBA{255, 255, 255, 255}
green = color.RGBA{0, 255, 0, 255}
red = color.RGBA{255, 0, 0, 255}
// Google colors
gBlue = color.RGBA{66, 163, 244, 255}
gRed = color.RGBA{219, 68, 55, 255}
gYellow = color.RGBA{244, 160, 0, 255}
gGreen = color.RGBA{15, 157, 88, 255}
// Coordinates
x int16 = 100 //TODO: horizontally center
y int16 = 100 //TODO: vertically center
// Global Score that also works as a time/counter
score int16 = 0
// Global state, if game is not paused
active bool = false
)
func main() {
// Set up the display
display.Configure()
// Register display status
regDISPSTAT.SetBits(1<<3 | 1<<4)
// Display Gopher text message and draw our Gophers
drawGophers()
// Creates an interrupt that will call the "update" function below, hardware way to display things on the screen
interrupt.New(machine.IRQ_VBLANK, update).Enable()
// Infinite loop to avoid exiting the application
for {
}
}