-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (51 loc) · 1.29 KB
/
main.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
package main
import (
"fmt"
"os"
"os/exec"
"math/rand"
"time"
)
func main() {
// sets up variables for the game run -- constants, background, player
MAKE_RANGE := 25
MAKE_ENEMY := 0
MAKE_CLOUD := 1
bg := initBackground()
play := initPlayer()
rand.Seed(time.Now().UnixNano())
// continuously reads from stdin asynchronously
go func() {
// disable input buffering
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
// do not display entered characters on the screen
exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
for {
var b []byte = make([]byte, 1)
os.Stdin.Read(b)
if !play.hasJumped && b[0] == 65 {
play.hasJumped = true
play.jumpPoint = 20
}
}
}()
// Infinite game loop -- updates the screen and reads user input
for {
seedDecision := rand.Intn(MAKE_RANGE)
if seedDecision == MAKE_ENEMY {
bg = insertEnemy(bg)
} else if seedDecision == MAKE_CLOUD {
bg = insertCloud(bg)
}
bg = moveBackground(bg)
if checkDead(bg, play) {
fmt.Println("Game over!! You scored: ", bg.score)
exec.Command("stty", "-F", "/dev/tty", "echo").Run()
return
}
play = jumpPlayer(play)
bg = drawPlayer(bg, play)
render(bg)
time.Sleep(100 * time.Millisecond)
}
}