-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacle.go
46 lines (41 loc) · 1.15 KB
/
obstacle.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
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
"math"
)
const (
NameChaosOrb = "Chaos Orb"
NameCoin = "Coin"
NameIce = "Ice"
NameFire = "Fire"
)
type ObstacleType struct {
Id uint32
Name string
Tex rl.Texture2D
}
type Obstacle struct {
Coord Vec2
Board uint32
Typ uint32
}
func (o *Obstacle) Render(index int, total int) {
const scale = 0.6
var typ = sandbox.GetObstacleType(o.Typ)
var halfsize = Vec2{X: int(float32(typ.Tex.Width) * scale / 2), Y: int(float32(typ.Tex.Height) * scale / 2)}
var tileCenter = GetBoardOrigo().Add(o.Coord.Scale(TileSize)).Add(ONEONE.Scale(TileSize / 2))
if total == 1 {
rl.DrawTextureEx(typ.Tex, tileCenter.Sub(halfsize).ToRlVec(), 0, scale, rl.White)
return
}
const offset = 0.165
var angleBase = math.Pi / 2
if total%2 == 0 {
angleBase = -math.Pi * 3 / 4
}
var angleStep = 2 * math.Pi / float64(total)
var angle = angleBase + angleStep*float64(index)
var offsetVec = Vec2{X: int(math.Cos(angle) * offset * TileSize), Y: int(math.Sin(angle) * offset * TileSize)}
var pos = tileCenter.Add(offsetVec).Sub(halfsize)
rl.DrawTextureEx(typ.Tex, pos.ToRlVec(), 0, scale, rl.White)
}