-
Notifications
You must be signed in to change notification settings - Fork 1
/
carried_item.gd
65 lines (52 loc) · 1.71 KB
/
carried_item.gd
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
extends Sprite2D
const ItemVariant = preload("res://item_variants.gd").ItemVariant
@export var variant: ItemVariant = ItemVariant.NONE
var base_scale
const VARIANT_TO_TEXTURES = {
ItemVariant.LEAF: [
preload("res://resources/sprites/leaf_piece1.png"),
preload("res://resources/sprites/leaf_piece2.png"),
preload("res://resources/sprites/leaf_piece3.png"),
],
ItemVariant.MUSHROOM: [
preload("res://resources/sprites/mushroom_piece1.png"),
preload("res://resources/sprites/mushroom_piece2.png"),
preload("res://resources/sprites/mushroom_piece3.png"),
],
ItemVariant.STICK: [
preload("res://resources/sprites/stick_piece1.png"),
preload("res://resources/sprites/stick_piece2.png"),
preload("res://resources/sprites/stick_piece3.png"),
],
ItemVariant.ANT: [
preload("res://resources/sprites/ant_dead_carried.png"),
]
}
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
base_scale = Vector2(scale.x, scale.y) # copy (not sure if needed)
scale = Vector2.ZERO
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func set_variant(new_variant: ItemVariant) -> void:
variant = new_variant
# for None, just keep the texture and scale to 0.
if new_variant != ItemVariant.NONE:
var textures = VARIANT_TO_TEXTURES[new_variant]
texture = textures[randi() % textures.size()]
var tween = create_tween()
if new_variant != ItemVariant.NONE:
scale = Vector2.ZERO
tween.tween_property(
self,
"scale",
base_scale,
1.0,
)
else:
tween.tween_property(self, "scale", Vector2.ZERO, 0.3)
tween.tween_callback(reset_carried_item)
func reset_carried_item():
texture = null
scale = Vector2.ONE