-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (59 loc) · 1.8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"image/color"
"log"
"sync"
"github.com/hajimehoshi/ebiten/v2"
)
const (
screenWidth, screenHeight = 640, 360
// screenWidth, screenHeight = 300, 300
boidCount = 400
viewRadius = 15
adjustmentRadius = 0.015
)
var (
green = color.RGBA{10, 255, 50, 255}
boids [boidCount]*Boid
boidMap [screenWidth + 1][screenHeight + 1]int
rWlock = sync.RWMutex{}
)
type Game struct{}
func (g *Game) Update() error {
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
for _, boid := range boids {
screen.Set(int(boid.position.x), int(boid.position.y+1), green)
screen.Set(int(boid.position.x-1), int(boid.position.y), green)
screen.Set(int(boid.position.x), int(boid.position.y-1), green)
screen.Set(int(boid.position.x), int(boid.position.y+2), green)
screen.Set(int(boid.position.x-1), int(boid.position.y), green)
screen.Set(int(boid.position.x), int(boid.position.y-2), green)
screen.Set(int(boid.position.x-1), int(boid.position.y-1), green)
// screen.Set(int(boid.position.x-1), int(boid.position.y), green)
// screen.Set(int(boid.position.x), int(boid.position.y+2), green)
// screen.Set(int(boid.position.x), int(boid.position.y-2), green)
// screen.Set(int(boid.position.x-3), int(boid.position.y), green)
// screen.Set(int(boid.position.x), int(boid.position.y+3), green)
// screen.Set(int(boid.position.x), int(boid.position.y-3), green)
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}
func main() {
for i, row := range boidMap {
for j := range row {
boidMap[i][j] = -1
}
}
for i := 0; i < boidCount; i++ {
createBoid(i)
}
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Boids")
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
}
}