1
0
mirror of https://gitee.com/freeyz/godot-mota.git synced 2024-12-23 06:49:22 +08:00
godot-mota/scripts/KeySprite.gd

47 lines
1.4 KiB
GDScript3
Raw Normal View History

2020-07-23 15:47:32 +08:00
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())
2020-07-23 22:12:08 +08:00
AffectAudioPlayer.play_item()