-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench.go
59 lines (51 loc) · 2.01 KB
/
bench.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
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/jakecoffman/cp"
"github.com/jakecoffman/cpebiten"
"log"
"math/rand"
)
func NewGame() *cpebiten.Game {
space := cp.NewSpace()
space.Iterations = 10
space.SetGravity(cp.Vector{0, 100})
space.SetCollisionSlop(0.5)
var simpleTerrainVerts = []cp.Vector{
{350.00, 425.07}, {336.00, 436.55}, {272.00, 435.39}, {258.00, 427.63}, {225.28, 420.00}, {202.82, 396.00},
{191.81, 388.00}, {189.00, 381.89}, {173.00, 380.39}, {162.59, 368.00}, {150.47, 319.00}, {128.00, 311.55},
{119.14, 286.00}, {126.84, 263.00}, {120.56, 227.00}, {141.14, 178.00}, {137.52, 162.00}, {146.51, 142.00},
{156.23, 136.00}, {158.00, 118.27}, {170.00, 100.77}, {208.43, 84.00}, {224.00, 69.65}, {249.30, 68.00},
{257.00, 54.77}, {363.00, 45.94}, {374.15, 54.00}, {386.00, 69.60}, {413.00, 70.73}, {456.00, 84.89},
{468.09, 99.00}, {467.09, 123.00}, {464.92, 135.00}, {469.00, 141.03}, {497.00, 148.67}, {513.85, 180.00},
{509.56, 223.00}, {523.51, 247.00}, {523.00, 277.00}, {497.79, 311.00}, {478.67, 348.00}, {467.90, 360.00},
{456.76, 382.00}, {432.95, 389.00}, {417.00, 411.32}, {373.00, 433.19}, {361.00, 430.02}, {350.00, 425.07},
}
offset := cp.Vector{}
for i := 0; i < len(simpleTerrainVerts)-1; i++ {
a := simpleTerrainVerts[i]
b := simpleTerrainVerts[i+1]
cpebiten.AddWall(space, space.StaticBody, a.Add(offset), b.Add(offset), 0)
}
for i := 0; i < 1000; i++ {
pos := randUnitCircle().Mult(180).Add(cp.Vector{cpebiten.ScreenWidth/2 + 10, cpebiten.ScreenHeight / 2})
const radius = 5
const mass = radius * radius / 25.0
cpebiten.AddCircle(space, pos, mass, radius)
}
return cpebiten.NewGame(space, 60)
}
func randUnitCircle() cp.Vector {
v := cp.Vector{rand.Float64()*2.0 - 1.0, rand.Float64()*2.0 - 1.0}
if v.LengthSq() < 1.0 {
return v
}
return randUnitCircle()
}
func main() {
ebiten.SetWindowSize(cpebiten.ScreenWidth, cpebiten.ScreenHeight)
ebiten.SetWindowTitle("Benchmark")
if err := ebiten.RunGame(NewGame()); err != nil {
log.Fatal(err)
}
}