-
Notifications
You must be signed in to change notification settings - Fork 0
/
die.go
57 lines (51 loc) · 1.23 KB
/
die.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
package main
import (
"encoding/json"
"net/http"
"strings"
"time"
rl "github.com/gen2brain/raylib-go/raylib"
)
type DieScreen struct {
menu *Button
}
func (d *DieScreen) draw() {
drawCenteredText(dieReason, screenWidt/2, screenHeight/2-20, 32, rl.Red)
d.menu.draw()
}
func (d *DieScreen) init() {
lastGametime = time.Now().Unix() - lastGametime
deaths++
if score != 0 {
if username != "" || password != "" {
a := map[string]interface{}{
"name": username,
"pass": password,
"points": score,
"gameOpened": gameOpened,
"lastGametime": lastGametime,
"deaths": deaths,
}
data, err := json.Marshal(a)
if err != nil {
panic("Something went wrong")
}
go http.Post("https://go-snake-backend.fly.dev/write?version="+gameVersion, "application/json", strings.NewReader(string(data)))
}
}
d.menu = &Button{
x: screenWidt / 2,
y: screenHeight/2 + 30,
fontSize: 40,
grownFontSize: 50,
normalFontSize: 40,
color: rl.White,
defaultColor: rl.White,
activeColor: rl.Beige,
text: "MENU",
callback: func() {
menuscreen.init()
state = 0
},
}
}