aboutsummaryrefslogtreecommitdiff
path: root/entity.go
blob: a9fd0ff898c7a55bcc6ed04fa4ecb4be10df8a5d (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

package main

import (
	"age_of_empires/ecs"
	"age_of_empires/physics"

	"github.com/hajimehoshi/ebiten/v2"
)

type Entity struct {
	Position         ecs.Component[physics.Point]
	Image            ecs.Component[*ebiten.Image]
	Selection        ecs.Component[Selection]
	Move             ecs.Component[physics.Move]
	Order            ecs.Component[Order]
	ResourceGatherer ecs.Component[ResourceGatherer]
	ResourceSource   ecs.Component[ResourceSource]
	ResourceStorage  ecs.Component[ResourceStorage]
}

func (e Entity) Bounds() physics.Rectangle {
	return physics.Rectangle{
		Min: e.Position.Value,
		Max: e.Position.Value.Add(e.Image.Value.Bounds().Size()),
	}
}

func Draw(screen *ebiten.Image, e *Entity) {
	if !e.Image.IsEnabled || !e.Position.IsEnabled {
		return
	}
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(e.Position.Value.X), float64(e.Position.Value.Y))
	screen.DrawImage(e.Image.Value, op)
}