pickups distributed through level manager. need to fix drop amount
This commit is contained in:
@@ -3,15 +3,23 @@ extends RigidBody3D
|
||||
@export var collision_shape = Node
|
||||
@export var despawning = false
|
||||
@export var despawn_time_s = 10
|
||||
@export var pickupType: String
|
||||
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickupType: int
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var rand_amt
|
||||
var player_follow
|
||||
var player
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
rand_amt = rng.randf_range(10.0,100.0)
|
||||
add_to_group("pickup")
|
||||
#find player
|
||||
player = level_control.player
|
||||
|
||||
rand_amt = rng.randi_range(25,100)
|
||||
|
||||
if despawning == true:
|
||||
await get_tree().create_timer(despawn_time_s).timeout
|
||||
collision_shape.disabled = true
|
||||
@@ -19,6 +27,25 @@ func _ready():
|
||||
self.queue_free()
|
||||
|
||||
func _physics_process(delta):
|
||||
if player != null:
|
||||
var float_direction = player.global_position - self.position
|
||||
if player_follow != null:
|
||||
var float_direction = (player.global_position - self.position)
|
||||
self.set_linear_velocity(float_direction * 10)
|
||||
|
||||
func picked_up():
|
||||
player.pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
player.pickup_sound.play()
|
||||
match pickupType:
|
||||
# Ammo
|
||||
0:
|
||||
level_control.ammo_reserve[level_control.current_gun_index] += clamp((rand_amt/100) * player.gun.max_ammo, 1, player.gun.max_ammo)
|
||||
# Stamina
|
||||
1:
|
||||
player.remaining_stamina += (rand_amt/100) * player.MAX_STAMINA
|
||||
# Health
|
||||
2:
|
||||
level_control.health += 1
|
||||
# Money
|
||||
3:
|
||||
level_control.money += int(rand_amt)
|
||||
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user