diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-16 13:40:31 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-16 13:42:21 +0200 |
commit | fa199ee0a597ab7b94e866f2f160c29c671b83f7 (patch) | |
tree | 5f2a8666befcda433d5137127c61213a4531fc7b /client | |
parent | 83a98dd32ca3f7955d12285e653b512c8818ccbc (diff) | |
download | hurrycurry-fa199ee0a597ab7b94e866f2f160c29c671b83f7.tar hurrycurry-fa199ee0a597ab7b94e866f2f160c29c671b83f7.tar.bz2 hurrycurry-fa199ee0a597ab7b94e866f2f160c29c671b83f7.tar.zst |
add item animations on removal
Diffstat (limited to 'client')
-rw-r--r-- | client/game.gd | 6 | ||||
-rw-r--r-- | client/map/items/item.gd | 13 | ||||
-rw-r--r-- | client/map/tiles/tile.gd | 5 | ||||
-rw-r--r-- | client/player/player.gd | 23 |
4 files changed, 25 insertions, 22 deletions
diff --git a/client/game.gd b/client/game.gd index 8f583e9e..d83767a0 100644 --- a/client/game.gd +++ b/client/game.gd @@ -154,7 +154,7 @@ func _ready(): mp.remove_tile_item.connect(func(tile: Vector2i): var t: Tile = map.get_tile_instance(tile) - t.take_item().queue_free() + t.set_item(null) ) mp.set_player_item.connect(func(player: int, item: int): @@ -167,9 +167,7 @@ func _ready(): mp.remove_player_item.connect(func(player: int): var p: Player = players[player] - var removed = p.remove_item() - if removed != null: - removed.queue_free() + p.set_item(null) ) mp.take_item.connect(func(tile: Vector2i, player: int): diff --git a/client/map/items/item.gd b/client/map/items/item.gd index d24cd36b..710d0081 100644 --- a/client/map/items/item.gd +++ b/client/map/items/item.gd @@ -26,6 +26,8 @@ var take_sound: PlayRandom = preload("res://audio/play_random.tscn").instantiate var put_sound: PlayRandom = preload("res://audio/play_random.tscn").instantiate() var sound_id +var destroy_timeout = null + func _init(owned_by_: Node3D): progress_instance.position.y = 1 progress_instance.visible = false @@ -42,6 +44,7 @@ func _init(owned_by_: Node3D): owned_by = owned_by_ func _process(delta): + if not is_instance_valid(owned_by): return if owned_by.get_parent() is Item or owned_by is Item: return var p = owned_by.get_parent().get_parent() is Player @@ -49,6 +52,13 @@ func _process(delta): position = G.interpolate(position, owned_by.global_position, delta * ispeed) if p: rotation.y = G.interpolate_angle(rotation.y, owned_by.global_rotation.y, delta * ispeed) else: rotation.y = G.interpolate_angle_closest_quarter(rotation.y, owned_by.global_rotation.y, delta * ispeed) + if destroy_timeout != null: + if is_instance_valid(progress_instance): + progress_instance.queue_free() + destroy_timeout -= delta * 5. + scale = Vector3.ONE * destroy_timeout + if destroy_timeout <= 0: + queue_free() func progress(position_: float, speed: float, warn: bool): progress_instance.visible = true @@ -65,6 +75,9 @@ func setup_sounds(): take_sound.setup([preload("res://map/items/sounds/generic_take.ogg")]) put_sound.setup([preload("res://map/items/sounds/plate_put.ogg")]) +func remove(): + destroy_timeout = 1 + func take(): take_sound.play_random() diff --git a/client/map/tiles/tile.gd b/client/map/tiles/tile.gd index 4bee3ced..98be64aa 100644 --- a/client/map/tiles/tile.gd +++ b/client/map/tiles/tile.gd @@ -77,10 +77,9 @@ func pass_to(tile: Tile): tile.set_item(i) func set_item(i: Item): - if item != null: - item.queue_free() + if item != null: item.remove() item = i - i.owned_by = item_base + if i != null: i.owned_by = item_base func take_item() -> Item: var i = item diff --git a/client/player/player.gd b/client/player/player.gd index f418337b..6af1dd0c 100644 --- a/client/player/player.gd +++ b/client/player/player.gd @@ -90,33 +90,26 @@ func update_username_tag(state): tag.visible = state func set_item(i: Item): - i.owned_by = hand_base - if hand != null: - hand.queue_free() - if i == null: - push_error("tile is null") + if hand != null: hand.remove() + character.holding = i != null hand = i - character.holding = true + if hand != null: hand.owned_by = hand_base -func remove_item() -> Item: +func remove_item(): var i = hand - if i == null: - push_error("holding nothing") + if i == null: push_error("holding nothing") hand = null character.holding = false return i func progress(position__: float, speed: float, warn: bool): - if hand != null: - hand.progress(position__, speed, warn) + if hand != null: hand.progress(position__, speed, warn) func finish(): - if hand != null: - hand.finish() + if hand != null: hand.finish() func take_item(tile: Tile): - if hand != null: - push_error("already holding an item") + if hand != null: push_error("already holding an item") var i = tile.take_item() i.take() set_item(i) |