pickup item values are assigned through level editor and spawn correctly, now need to implement non random spawns
This commit is contained in:
@@ -13,6 +13,7 @@ extends Node3D
|
||||
@export var health_drop_enabled = true
|
||||
@export var money_drop_enabled = true
|
||||
|
||||
@onready var item_pickup = preload("res://assets/item_pickup.tscn")
|
||||
@onready var crown = preload("res://assets/crown.tscn")
|
||||
var ammo_drop = [[load("res://assets/ammo_pickup.tscn")],["ammo"]]
|
||||
var stamina_drop = [[load("res://assets/stamina_pickup.tscn")],["stamina"]]
|
||||
@@ -185,13 +186,17 @@ func die():
|
||||
player.health_indicator.color = Color(0.471, 0, 0, 0)
|
||||
|
||||
|
||||
|
||||
func pickup_spawn():
|
||||
var item_type = pickups.pick_random()
|
||||
var item_spawn = item_type[0][0].instantiate()
|
||||
#var item_name = item_type[1][0]
|
||||
item_spawn.rand_amt = randi_range(25,100)
|
||||
return item_spawn
|
||||
##SET VARIABLES
|
||||
var type = randi_range(0,3)
|
||||
var ammo_type
|
||||
var value
|
||||
|
||||
if type == 0:
|
||||
ammo_type = randi_range(0,4)
|
||||
value = randi_range(1,10)
|
||||
|
||||
return {"pickup_type" : type,"ammo_type" : ammo_type,"value" : value}
|
||||
|
||||
func save_quit():
|
||||
SaveLoad.save_game_data(level_name)
|
||||
|
||||
@@ -10,6 +10,7 @@ extends Node3D
|
||||
@onready var cannonparticles = $cannonparticles
|
||||
@onready var cannon_dir = $RayCast3D
|
||||
@onready var fire_audio = $Audio/FireAudio
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
var fire = true
|
||||
|
||||
@@ -33,12 +34,11 @@ func _on_timer_timeout():
|
||||
|
||||
# Shoot that shit
|
||||
var pickup_spawn = item_pickup.instantiate()
|
||||
var item_stats = level_control.pickup_spawn()
|
||||
##SET VARIABLES
|
||||
var type = randi_range(0,3)
|
||||
pickup_spawn.pickup_type = type
|
||||
if type == 0:
|
||||
pickup_spawn.ammo_type = randi_range(0,4)
|
||||
pickup_spawn.value = randi_range(1,10)
|
||||
pickup_spawn.pickup_type = item_stats["pickup_type"]
|
||||
pickup_spawn.ammo_type = item_stats["ammo_type"]
|
||||
pickup_spawn.value = item_stats["value"]
|
||||
|
||||
pickup_spawn.position = cannon_dir.global_position
|
||||
pickup_spawn.transform.basis = cannon_dir.global_transform.basis
|
||||
|
||||
@@ -206,7 +206,15 @@ func quiet_remove():
|
||||
func drop_loot(number_of_drops):
|
||||
#pickup drop
|
||||
while number_of_drops > 0:
|
||||
var rand_item = level_control.pickup_spawn()
|
||||
|
||||
var pickup_spawn = level_control.item_pickup.instantiate()
|
||||
var item_stats = level_control.pickup_spawn()
|
||||
|
||||
##SET VARIABLES
|
||||
pickup_spawn.pickup_type = item_stats["pickup_type"]
|
||||
pickup_spawn.ammo_type = item_stats["ammo_type"]
|
||||
pickup_spawn.value = item_stats["value"]
|
||||
|
||||
var lv_x = randf_range(-MAX_LV,MAX_LV)
|
||||
var lv_y = randf_range(0,MAX_LV)
|
||||
var lv_z = randf_range(-MAX_LV,MAX_LV)
|
||||
@@ -215,12 +223,12 @@ func drop_loot(number_of_drops):
|
||||
var av_z = randf_range(-MAX_AV,MAX_AV)
|
||||
|
||||
# Random Item Drop
|
||||
rand_item.position = self.global_position + Vector3(0,2,0) #added height to spawn location since origin is on the ground
|
||||
rand_item.transform.basis = self.global_transform.basis
|
||||
rand_item.linear_velocity += self.global_transform.basis * Vector3(lv_x,lv_y,lv_z)
|
||||
rand_item.angular_velocity += self.global_transform.basis * Vector3(av_x,av_y,av_z)
|
||||
pickup_spawn.position = self.global_position + Vector3(0,2,0) #added height to spawn location since origin is on the ground
|
||||
pickup_spawn.transform.basis = self.global_transform.basis
|
||||
pickup_spawn.linear_velocity += self.global_transform.basis * Vector3(lv_x,lv_y,lv_z)
|
||||
pickup_spawn.angular_velocity += self.global_transform.basis * Vector3(av_x,av_y,av_z)
|
||||
await get_tree().create_timer(.05).timeout
|
||||
get_tree().get_root().add_child(rand_item)
|
||||
get_tree().get_root().add_child(pickup_spawn)
|
||||
number_of_drops -= 1
|
||||
|
||||
if number_of_drops <= 0:
|
||||
|
||||
@@ -6,18 +6,16 @@ extends Node3D
|
||||
@onready var anim_player = $AnimationPlayer
|
||||
@onready var vend_ray = $VendRay
|
||||
@onready var label_3d = $Label3D
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
var active = true
|
||||
var level_control
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
level_control = get_tree().current_scene
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
if active == true:
|
||||
label_3d.text = str(item_price)
|
||||
else:
|
||||
label_3d.text = "offline"
|
||||
|
||||
func interact():
|
||||
if active == true:
|
||||
@@ -39,3 +37,17 @@ func vend():
|
||||
active = false
|
||||
label_3d.text = "offline"
|
||||
get_parent().add_child(item_vend)
|
||||
|
||||
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,
|
||||
"active" : active
|
||||
}
|
||||
return save_dict
|
||||
|
||||
Reference in New Issue
Block a user