~bigbes/game-prototype-ftl

ref: 3b45141687e94d35b6a12c4a6f4897d9bd741f6f game-prototype-ftl/crew.go -rw-r--r-- 861 bytes
3b451416 — Eugene Blikh docs(systems-power): record approved design 30 days ago
                                                                                
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
package main

import "image/color"

const TileTime = 0.35

type Crew struct {
	ID      int
	Name    string
	Initial rune
	Color   color.RGBA
	TileX   int
	TileY   int
	Path    [][2]int
	MoveT   float64
}

func NewStartingCrew() []Crew {
	return []Crew{
		{ID: 1, Name: "Alice", Initial: 'A', Color: color.RGBA{R: 80, G: 180, B: 170, A: 255}, TileX: 4, TileY: 10},
		{ID: 2, Name: "Bob", Initial: 'B', Color: color.RGBA{R: 220, G: 170, B: 80, A: 255}, TileX: 7, TileY: 10},
		{ID: 3, Name: "Carol", Initial: 'C', Color: color.RGBA{R: 200, G: 100, B: 170, A: 255}, TileX: 11, TileY: 10},
	}
}

func updateCrew(c *Crew, dt float64) {
	if len(c.Path) == 0 {
		return
	}
	c.MoveT += dt / TileTime
	for c.MoveT >= 1 && len(c.Path) > 0 {
		c.TileX, c.TileY = c.Path[0][0], c.Path[0][1]
		c.Path = c.Path[1:]
		c.MoveT -= 1
	}
	if len(c.Path) == 0 {
		c.MoveT = 0
	}
}