-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys_item.go
75 lines (61 loc) · 1.79 KB
/
sys_item.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package kar
import (
"github.com/mlange-42/arche/ecs"
)
var SinspaceLen int = len(Sinspace) - 1
type Item struct {
toRemoveComponent []ecs.Entity
}
func (i *Item) Init() {}
func (i *Item) Update() error {
q := FilterCollisionDelayer.Query(&ECWorld)
for q.Next() {
delayer := q.Get()
delayer.Duration -= Tick
}
// dropped items collisions and animations
if ECWorld.Alive(CurrentPlayer) {
itemSize := &Size{DropItemSize.W, DropItemSize.H}
if !GameDataRes.CraftingState {
playerPos, playerSize := MapRect.GetUnchecked(CurrentPlayer)
itemQuery := FilterDroppedItem.Query(&ECWorld)
for itemQuery.Next() {
itemID, itemPos, timers, delayer, durability := itemQuery.Get()
itemEntity := itemQuery.Entity()
// Check player-item collision
if delayer == nil {
if Overlaps(playerPos, playerSize, itemPos, itemSize) {
// if Durability component exists, pass durability
if durability != nil {
if InventoryRes.AddItemIfEmpty(itemID.ID, durability.Durability) {
toRemove = append(toRemove, itemEntity)
}
} else {
if InventoryRes.AddItemIfEmpty(itemID.ID, 0) {
toRemove = append(toRemove, itemEntity)
}
}
onInventorySlotChanged()
}
} else {
// delayer.Duration -= Tick
if delayer.Duration < 0 {
i.toRemoveComponent = append(i.toRemoveComponent, itemEntity)
}
}
// vertical item sine animation
dy := Collider.CollideY(itemPos.X, itemPos.Y+6, itemSize.W, itemSize.H, ItemGravity)
itemPos.Y += dy
timers.Index = (timers.Index + 1) % SinspaceLen
}
}
}
// Remove MapCollisionDelayer components
for _, entity := range i.toRemoveComponent {
MapCollisionDelayer.Remove(entity)
}
i.toRemoveComponent = i.toRemoveComponent[:0]
return nil
}
func (i *Item) Draw() {
}