/
lights.go
76 lines (64 loc) · 1.68 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package game
import (
"github.com/co0p/tankism/game/ecs/components"
"github.com/co0p/tankism/lib"
"github.com/co0p/tankism/lib/ecs"
"github.com/co0p/tankism/lib/resource"
"github.com/co0p/tankism/lib/vector"
"github.com/co0p/tankism/resources"
"github.com/hajimehoshi/ebiten/v2"
)
var (
DEFAULT_COLOR = lib.Color{255, 255, 255, 255} // white
MUTED_COLOR = lib.Color{128, 128, 128, 128} // gray
)
func NewAmbientLight(e *ecs.Entity) {
c := &components.AmbientLight{
Color: MUTED_COLOR,
}
e.AddComponent(c)
}
func NewPointLight(e *ecs.Entity, x, y float64) {
i, err := resources.LoadImage(resources.LightPoint)
img := ebiten.NewImageFromImage(i)
if err != nil {
panic("expected LightPoint media to exist")
}
light := &components.Light{Image: img, Color: DEFAULT_COLOR}
translate := &components.Transform{
Point: vector.Vec2d{
X: x,
Y: y,
},
Scale: 2,
Rotation: 0,
}
e.AddComponents(light, translate)
}
func NewCircleLight(e *ecs.Entity, x, y float64) {
NewCircleLightWithColor(e, x, y, lib.ColorWhite)
}
func NewCircleLightWithColor(e *ecs.Entity, x, y float64, clr lib.Color) {
i, err := resources.LoadImage(resources.LightCircle)
img := ebiten.NewImageFromImage(i)
if err != nil {
panic("expected LightPoint media to exist")
}
light := &components.Light{Image: img, Color: clr}
translate := &components.Transform{
Point: vector.Vec2d{
X: x,
Y: y,
},
Scale: 2,
Rotation: 0,
}
e.AddComponents(light, translate)
}
func NewLightSpritesheet() resource.SpriteSheet {
spritesheet, err := resource.NewSpriteSheet(resources.Lights, 128, 128)
if err != nil {
panic("failed to load light spritesheet: " + err.Error())
}
return spritesheet
}