major rework on pickups, hud now shows the number and icon of pickup
This commit is contained in:
100
scripts/item_pickup_v2.gd
Normal file
100
scripts/item_pickup_v2.gd
Normal file
@@ -0,0 +1,100 @@
|
||||
extends RigidBody3D
|
||||
|
||||
var despawning = false
|
||||
var despawn_time_s = 10
|
||||
|
||||
var value
|
||||
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickup_type: int
|
||||
var ammo_type
|
||||
|
||||
@onready var collision_shape: CollisionShape3D = $CollisionShape3D2
|
||||
@onready var timer: Timer = $Timer
|
||||
|
||||
## MESHES
|
||||
#AMMO
|
||||
@onready var light_ammo: MeshInstance3D = $Meshes/Ammo/light_ammo
|
||||
@onready var rocket: MeshInstance3D = $Meshes/Ammo/rocket
|
||||
|
||||
@onready var stamina: MeshInstance3D = $Meshes/stamina
|
||||
@onready var health: MeshInstance3D = $Meshes/health
|
||||
@onready var money: Node3D = $Meshes/money
|
||||
|
||||
|
||||
var magnetable = true #false
|
||||
var pickupable = false
|
||||
var pick_up = false
|
||||
var rand_amt
|
||||
var player_follow
|
||||
var player
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
add_to_group("spawned")
|
||||
add_to_group("persist")
|
||||
|
||||
#Enable mesh
|
||||
|
||||
match pickup_type:
|
||||
0:
|
||||
match ammo_type:
|
||||
0:
|
||||
light_ammo.visible = true
|
||||
1:
|
||||
light_ammo.visible = true #medium
|
||||
2:
|
||||
light_ammo.visible = true #heavy
|
||||
3:
|
||||
light_ammo.visible = true #shotgun
|
||||
4:
|
||||
rocket.visible = true #rocket
|
||||
1:
|
||||
stamina.visible = true
|
||||
2:
|
||||
health.visible = true
|
||||
3:
|
||||
money.visible = true
|
||||
|
||||
|
||||
if despawning == true:
|
||||
timer.wait_time = despawn_time_s
|
||||
timer.start()
|
||||
|
||||
func _physics_process(delta):
|
||||
if player_follow != null:
|
||||
if !pick_up:
|
||||
despawning = false
|
||||
angular_velocity = lerp(angular_velocity, Vector3(0,0,0), delta)
|
||||
position = lerp(position, player.item_holder.global_position, 25 * delta)
|
||||
|
||||
if abs(position - player.item_holder.global_position) < Vector3(.5,.5,.5):
|
||||
await get_tree().create_timer(1).timeout
|
||||
position = lerp(position, player.camera.global_position, .01 * delta)
|
||||
await get_tree().create_timer(.01).timeout
|
||||
player.pickup_apply(pickup_type,ammo_type,value)
|
||||
queue_free()
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
if despawning == true:
|
||||
collision_shape.disabled = true
|
||||
await get_tree().create_timer(1).timeout
|
||||
self.queue_free()
|
||||
|
||||
func save():
|
||||
var save_dict = {
|
||||
"filename" : get_scene_file_path(),
|
||||
"parent" : get_parent().get_path(),
|
||||
"pos_x" : position.x,
|
||||
"pos_y" : position.y,
|
||||
"pos_z" : position.z,
|
||||
"rot_x" : rotation.x,
|
||||
"rot_y" : rotation.y,
|
||||
"rot_z" : rotation.z,
|
||||
"pickup_type" : pickup_type,
|
||||
"ammo_type" : ammo_type,
|
||||
"value" : value
|
||||
}
|
||||
return save_dict
|
||||
|
||||
|
||||
func _on_magnet_timer_timeout() -> void:
|
||||
magnetable = true
|
||||
Reference in New Issue
Block a user