aboutsummaryrefslogtreecommitdiff
path: root/person.go
blob: 3462aa19db8a582624ab9f7ee11bfef537761f86 (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
39
40
41
42
43
44
45
46
47
48
49

package main

import (
	"image/color"

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

type Person struct {
	size          Point
	Position      Point
	IsSelected    bool
	move          Move
	image         *ebiten.Image
	selectedImage *ebiten.Image
}

func NewPerson(position Point) Person {
	image := ebiten.NewImage(10, 10)
	image.Fill(color.RGBA{0xff, 0xff, 0xff, 0xff})
	selectedImage := ebiten.NewImage(12, 12)
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(1, 1)
	selectedImage.Fill(color.RGBA{0xff, 0x00, 0x00, 0xff})
	selectedImage.DrawImage(image, op)
	return Person{Position: position, size: Point{10, 10}, image: image, selectedImage: selectedImage}
}

func (p Person) Image() *ebiten.Image {
	if p.IsSelected {
		return p.selectedImage
	}
	return p.image
}

func (p Person) CollisionBounds() Rectangle {
	return Rectangle{
		p.Position.Sub(p.size.Div(2)),
		p.Position.Add(p.size.Div(2)),
	}
}

func (p *Person) MoveTo(destination Point) {
	p.move = Move{IsActive: true, Destination: destination}
}

func (p *Person) Update() {
	p.Position = p.move.Update(p.Position, 3)
}