godot-mota/scripts/KeySprite.gd

46 lines
1.4 KiB
GDScript

tool
extends Sprite
class_name KeySprite
enum KeyType { Yellow,Blue,Red,Green }
# 钥匙类型
export(KeyType) var key_type = KeyType.Yellow setget set_key_type
func _init():
self.texture = load("res://images/mota.png")
self.region_enabled = true
func set_key_type(value):
key_type = value
match value:
KeyType.Yellow:
region_rect = Rect2(96,448,32,32)
KeyType.Blue:
region_rect = Rect2(128,448,32,32)
KeyType.Red:
region_rect = Rect2(160,448,32,32)
KeyType.Green:
region_rect = Rect2(192,448,32,32)
# 触碰钥匙回调
func _on_Area2D_body_entered(body):
if not body is PlayerKinematicBody2D:
return
match key_type:
KeyType.Yellow:
GameArchiveManager.player_info.yellow_key += 1
$"/root/Main/UI/KeyBackground/YellowKeyCountLabel".text = GameArchiveManager.player_info.yellow_key as String
KeyType.Blue:
GameArchiveManager.player_info.blue_key += 1
$"/root/Main/UI/KeyBackground/BlueKeyCountLabel".text = GameArchiveManager.player_info.blue_key as String
KeyType.Red:
GameArchiveManager.player_info.red_key += 1
$"/root/Main/UI/KeyBackground/RedKeyCountLabel".text = GameArchiveManager.player_info.red_key as String
KeyType.Green:
GameArchiveManager.player_info.green_key += 1
$"/root/Main/UI/KeyBackground/GreenKeyCountLabel".text = GameArchiveManager.player_info.green_key as String
queue_free()
GameArchiveManager.add_used_item(get_path())