-
Notifications
You must be signed in to change notification settings - Fork 0
/
lights.go
48 lines (38 loc) · 885 Bytes
/
lights.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
package main
import (
"github.com/faiface/pixel"
"github.com/faiface/pixel/imdraw"
"image/color"
)
type colorLight struct {
color color.Color
point pixel.Vec
angle float64
radius float64
spread float64
imd *imdraw.IMDraw
}
func (cl *colorLight) init() {
// create the light arc if not created already
if cl.imd == nil {
imd := imdraw.New(nil)
cl.imd = imd
}
}
func (cl *colorLight) draw(dst pixel.Target) {
cl.imd.Clear()
if playerScore.timeWindow {
cl.imd.Intensity = 0
} else {
cl.imd.Intensity = 0.1
}
cl.imd.Color = cl.color
cl.imd.SetMatrix(pixel.IM.Scaled(pixel.ZV, cl.radius).Rotated(pixel.ZV, cl.angle).Moved(cl.point))
cl.imd.Push(pixel.ZV)
cl.imd.Color = pixel.Alpha(0)
for angle := -cl.spread / 2; angle <= cl.spread/2; angle += cl.spread / 64 {
cl.imd.Push(pixel.V(1, 0).Rotated(angle))
}
cl.imd.Polygon(0)
cl.imd.Draw(dst)
}