init
This commit is contained in:
46
items/item_pickup/item_pickup.gd
Normal file
46
items/item_pickup/item_pickup.gd
Normal file
@@ -0,0 +1,46 @@
|
||||
@tool
|
||||
class_name ItemPickup extends CharacterBody2D
|
||||
|
||||
signal picked_up
|
||||
|
||||
@export var item_data: ItemData :
|
||||
set = set_item_data
|
||||
|
||||
@onready var area: Area2D = $Area2D
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@onready var audio_player: AudioStreamPlayer2D = $AudioStreamPlayer2D
|
||||
|
||||
func _ready() -> void:
|
||||
update_texture()
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
area.body_entered.connect(on_body_enter)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var collision_info := move_and_collide(velocity * delta)
|
||||
if collision_info:
|
||||
velocity = velocity.bounce(collision_info.get_normal())
|
||||
velocity -= velocity * delta * 4
|
||||
|
||||
func on_body_enter(body: Node2D) -> void:
|
||||
if !item_data or body is not Player:
|
||||
return
|
||||
if PlayerManager.INVENTORY_DATA.add_item(item_data):
|
||||
item_picked_up()
|
||||
|
||||
func item_picked_up() -> void:
|
||||
area.body_entered.disconnect(on_body_enter)
|
||||
audio_player.play()
|
||||
visible = false
|
||||
picked_up.emit()
|
||||
await audio_player.finished
|
||||
queue_free()
|
||||
|
||||
func update_texture() -> void:
|
||||
if !item_data or !sprite:
|
||||
return
|
||||
sprite.texture = item_data.texture
|
||||
|
||||
func set_item_data(new_item_data: ItemData) -> void:
|
||||
item_data = new_item_data
|
||||
update_texture()
|
||||
1
items/item_pickup/item_pickup.gd.uid
Normal file
1
items/item_pickup/item_pickup.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dtuirhoxa1fkj
|
||||
107
items/item_pickup/item_pickup.tscn
Normal file
107
items/item_pickup/item_pickup.tscn
Normal file
@@ -0,0 +1,107 @@
|
||||
[gd_scene format=3 uid="uid://bd3uiuggwfq2v"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dtuirhoxa1fkj" path="res://items/item_pickup/item_pickup.gd" id="1_0g51u"]
|
||||
[ext_resource type="AudioStream" uid="uid://borbldx5nrrjp" path="res://items/item_pickup/item_pickup.wav" id="2_0rscd"]
|
||||
[ext_resource type="Texture2D" uid="uid://bxqdnnk4dqnu5" path="res://player/sprites/Shadow.png" id="2_jl14n"]
|
||||
[ext_resource type="Texture2D" uid="uid://dxf00vjmse6ab" path="res://items/sprites/items.png" id="2_tc5ok"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_0rscd"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_7rq5k"]
|
||||
atlas = ExtResource("2_tc5ok")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_jl14n"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_puw1c"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ShadowSprite:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0.5, 0.5)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_bjvna"]
|
||||
resource_name = "bounce"
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6, 0.8),
|
||||
"transitions": PackedFloat32Array(-2, -2, -2, -2, -2),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -6), Vector2(0, 0), Vector2(0, -2), Vector2(0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ShadowSprite:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6, 0.8),
|
||||
"transitions": PackedFloat32Array(-2, -2, -2, -2, -2),
|
||||
"update": 0,
|
||||
"values": [Vector2(0.5, 0.5), Vector2(0.2, 0.2), Vector2(0.5, 0.5), Vector2(0.4, 0.4), Vector2(0.5, 0.5)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_o0c3x"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_puw1c"),
|
||||
&"bounce": SubResource("Animation_bjvna")
|
||||
}
|
||||
|
||||
[node name="ItemPickup" type="CharacterBody2D" unique_id=320551238]
|
||||
collision_layer = 0
|
||||
collision_mask = 16
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_0g51u")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=1719100885]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=82383132]
|
||||
shape = SubResource("CircleShape2D_0rscd")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1485596032]
|
||||
texture = SubResource("AtlasTexture_7rq5k")
|
||||
|
||||
[node name="ShadowSprite" type="Sprite2D" parent="." unique_id=772537575]
|
||||
modulate = Color(0, 0, 0, 0.34901962)
|
||||
position = Vector2(0, 8)
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_jl14n")
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." unique_id=60991160]
|
||||
stream = ExtResource("2_0rscd")
|
||||
max_polyphony = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=721385119]
|
||||
shape = SubResource("CircleShape2D_jl14n")
|
||||
debug_color = Color(0.24937189, 0.6105543, 0.506212, 0.41960785)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1968131721]
|
||||
libraries/ = SubResource("AnimationLibrary_o0c3x")
|
||||
autoplay = &"bounce"
|
||||
BIN
items/item_pickup/item_pickup.wav
Normal file
BIN
items/item_pickup/item_pickup.wav
Normal file
Binary file not shown.
24
items/item_pickup/item_pickup.wav.import
Normal file
24
items/item_pickup/item_pickup.wav.import
Normal file
@@ -0,0 +1,24 @@
|
||||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://borbldx5nrrjp"
|
||||
path="res://.godot/imported/item_pickup.wav-cb95f6a75b96e4fc19c3e7765c534824.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://items/item_pickup/item_pickup.wav"
|
||||
dest_files=["res://.godot/imported/item_pickup.wav-cb95f6a75b96e4fc19c3e7765c534824.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=2
|
||||
Reference in New Issue
Block a user