/
start.go
66 lines (57 loc) · 1.36 KB
/
start.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
package main
import (
"image/color"
oak "github.com/oakmound/oak/v2"
"github.com/oakmound/oak/v2/collision"
"github.com/oakmound/oak/v2/entities"
"github.com/oakmound/oak/v2/event"
"github.com/oakmound/oak/v2/key"
"github.com/oakmound/oak/v2/physics"
"github.com/oakmound/oak/v2/render"
"github.com/oakmound/oak/v2/scene"
)
// Collision labels
const (
Enemy collision.Label = 1
Player collision.Label = 2
)
var (
playerAlive = true
)
func main() {
oak.Add("tds", func(string, interface{}) {
playerAlive = true
char := entities.NewMoving(100, 100, 32, 32,
render.NewColorBox(32, 32, color.RGBA{0, 255, 0, 255}),
nil, 0, 0)
char.Speed = physics.NewVector(5, 5)
render.Draw(char.R)
char.Bind(func(id int, _ interface{}) int {
char := event.GetEntity(id).(*entities.Moving)
char.Delta.Zero()
if oak.IsDown(key.W) {
char.Delta.ShiftY(-char.Speed.Y())
}
if oak.IsDown(key.A) {
char.Delta.ShiftX(-char.Speed.X())
}
if oak.IsDown(key.S) {
char.Delta.ShiftY(char.Speed.Y())
}
if oak.IsDown(key.D) {
char.Delta.ShiftX(char.Speed.X())
}
char.ShiftPos(char.Delta.X(), char.Delta.Y())
hit := char.HitLabel(Enemy)
if hit != nil {
playerAlive = false
}
return 0
}, event.Enter)
}, func() bool {
return playerAlive
}, func() (string, *scene.Result) {
return "tds", nil
})
oak.Init("tds")
}