blob: 838bd71e1a3886623da42e4e5e76c1e771d121cf (
plain) (
blame)
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
|
package main
import "github.com/hajimehoshi/ebiten/v2"
type Component[T any] struct {
IsEnabled bool
Value T
}
func C[T any](t T) Component[T] {
return Component[T]{IsEnabled: true, Value: t}
}
type Entity struct {
Position Component[Point]
Image Component[*ebiten.Image]
Selection Component[Selection]
Move Component[Move]
Order Component[Order]
ResourceGatherer Component[ResourceGatherer]
ResourceSource Component[ResourceSource]
ResourceStorage Component[ResourceStorage]
}
func (e Entity) Bounds() Rectangle {
return Rectangle{
e.Position.Value,
e.Position.Value.Add(e.Image.Value.Bounds().Size()),
}
}
func Draw(screen *ebiten.Image, e *Entity) {
if e.Image.IsEnabled && e.Position.IsEnabled {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(e.Position.Value.X), float64(e.Position.Value.Y))
screen.DrawImage(e.Image.Value, op)
}
}
|