-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys_spawn.go
56 lines (44 loc) · 1.07 KB
/
sys_spawn.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
package kar
import (
"kar/items"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/mlange-42/arche/ecs"
)
var (
toSpawn = []SpawnData{}
toRemove []ecs.Entity
)
func AppendToSpawnList(x, y float64, id uint8, dur int) {
toSpawn = append(
toSpawn,
SpawnData{X: x - 4, Y: y - 4, Id: id, Durability: dur},
)
}
type Spawn struct{}
func (s *Spawn) Init() {
}
func (s *Spawn) Update() error {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
x, y := CameraRes.ScreenToWorld(ebiten.CursorPosition())
p := TileMapRes.WorldToTile(x, y)
TileMapRes.Set(p.X, p.Y, items.Stone)
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
x, y := CameraRes.ScreenToWorld(ebiten.CursorPosition())
p := TileMapRes.WorldToTile(x, y)
TileMapRes.Set(p.X, p.Y, items.Air)
}
// Spawn item
for _, d := range toSpawn {
SpawnItem(d.X, d.Y, d.Id, d.Durability)
}
toSpawn = toSpawn[:0]
for _, e := range toRemove {
ECWorld.RemoveEntity(e)
}
toRemove = toRemove[:0]
return nil
}
func (s *Spawn) Draw() {
}