pickups distributed through level manager. need to fix drop amount
This commit is contained in:
@@ -8,6 +8,7 @@ var rot_amount : float
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
minions = self.get_children()
|
||||
add_to_group("enemy_hivemind")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
@@ -13,10 +13,10 @@ extends Node3D
|
||||
@export var health_drop_enabled = true
|
||||
@export var money_drop_enabled = true
|
||||
|
||||
var ammo_drop = load("res://assets/ammo_pickup.tscn")
|
||||
var stamina_drop = load("res://assets/stamina_pickup.tscn")
|
||||
var health_drop = load("res://assets/health_pickup.tscn")
|
||||
var money_drop = load("res://assets/money_pickup.tscn")
|
||||
var ammo_drop = [[load("res://assets/ammo_pickup.tscn")],["ammo"]]
|
||||
var stamina_drop = [[load("res://assets/stamina_pickup.tscn")],["stamina"]]
|
||||
var health_drop = [[load("res://assets/health_pickup.tscn")],["health"]]
|
||||
var money_drop = [[load("res://assets/money_pickup.tscn")],["money"]]
|
||||
const CLEARED_ANNOUNCE = preload("res://assets/cleared_announce.tscn")
|
||||
const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
|
||||
|
||||
@@ -35,6 +35,10 @@ func _ready():
|
||||
#global randomize function
|
||||
randomize()
|
||||
|
||||
#clear spawned in objects
|
||||
for node in get_tree().get_nodes_in_group("spawned"):
|
||||
node.queue_free()
|
||||
|
||||
#assign pickups to array
|
||||
if ammo_drop_enabled == true:
|
||||
pickups.append(ammo_drop)
|
||||
@@ -42,8 +46,8 @@ func _ready():
|
||||
pickups.append(stamina_drop)
|
||||
if health_drop_enabled == true:
|
||||
pickups.append(health_drop)
|
||||
if ammo_drop_enabled == true:
|
||||
pickups.append(ammo_drop)
|
||||
if money_drop_enabled == true:
|
||||
pickups.append(money_drop)
|
||||
|
||||
#Set up starting guns and ammo
|
||||
held_guns = [gun_1]
|
||||
@@ -100,11 +104,10 @@ func enemy_count():
|
||||
cleared()
|
||||
|
||||
func cleared():
|
||||
Engine.time_scale = .05
|
||||
var clearedmsg = CLEARED_ANNOUNCE.instantiate()
|
||||
get_parent().add_child(clearedmsg)
|
||||
await get_tree().create_timer(.3).timeout
|
||||
get_tree().reload_current_scene()
|
||||
await get_tree().create_timer(1).timeout
|
||||
clearedmsg.queue_free()
|
||||
|
||||
func die():
|
||||
Engine.time_scale = .05
|
||||
@@ -118,5 +121,11 @@ func die():
|
||||
#get_tree().get_root().add_child(instance_dead)
|
||||
|
||||
func pickup_spawn():
|
||||
pickups.pick_random()
|
||||
print(pickups.pick_random())
|
||||
var item_type = pickups.pick_random()
|
||||
var item_spawn = item_type[0][0].instantiate()
|
||||
var item_name = item_type[1][0]
|
||||
|
||||
|
||||
print(item_name)
|
||||
item_spawn.rand_amt = randi_range(25,100)
|
||||
return item_spawn
|
||||
|
||||
@@ -10,6 +10,7 @@ var changed_size
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
add_to_group("spawned")
|
||||
viewportWidth = get_viewport().size.x
|
||||
viewportHeight = get_viewport().size.y
|
||||
start_size = Vector2(size.x, size.y)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -239,63 +239,9 @@ func _headbob(time) -> Vector3:
|
||||
func _on_pick_up_detection_body_entered(body):
|
||||
|
||||
if body.is_in_group("pickup"):
|
||||
if body.pickupType == "stamina":
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "stamina"
|
||||
get_parent().add_child(pickupmsg)
|
||||
remaining_stamina += (body.rand_amt/100) * MAX_STAMINA
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
body.queue_free()
|
||||
elif body.pickupType == "ammo":
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "ammo"
|
||||
get_parent().add_child(pickupmsg)
|
||||
level_control.ammo_reserve[level_control.current_gun_index] += clamp(int((body.rand_amt/100) * gun.max_ammo), 1, gun.max_ammo)
|
||||
picked_up = true
|
||||
picked_up_text = "ammo"
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
body.queue_free()
|
||||
elif body.pickupType == "money":
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "$" + str(int(body.rand_amt))
|
||||
get_parent().add_child(pickupmsg)
|
||||
level_control.money += int(body.rand_amt)
|
||||
picked_up = true
|
||||
picked_up_text = "ammo"
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
body.queue_free()
|
||||
elif body.pickupType == "health":
|
||||
level_control.health += 1
|
||||
picked_up = true
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
body.queue_free()
|
||||
elif body.pickupType == "jump":
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "jump"
|
||||
get_parent().add_child(pickupmsg)
|
||||
double_jump = true
|
||||
picked_up = true
|
||||
picked_up_text = "double jump"
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
body.queue_free()
|
||||
elif body.pickupType == "weapon":
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
pickup_sound.play()
|
||||
level_control.held_guns.append(body.gun_resource)
|
||||
var instance_gun = body.gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
level_control.ammo_reserve.append(instance_gun.max_ammo * instance_gun.start_mags)
|
||||
body.queue_free()
|
||||
var weapon_id = level_control.held_guns.size() - 1
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(weapon_id)
|
||||
|
||||
|
||||
body.picked_up()
|
||||
|
||||
|
||||
func ladder_collide(is_climbing):
|
||||
|
||||
if is_climbing == true:
|
||||
@@ -305,7 +251,7 @@ func ladder_collide(is_climbing):
|
||||
|
||||
func _on_pick_up_magnet_body_entered(body):
|
||||
if body.is_in_group("pickup") and body.is_in_group("magnet"):
|
||||
body.player = self
|
||||
body.player_follow = self
|
||||
|
||||
func weapon_tilt(input_x, delta):
|
||||
if weapon_holder:
|
||||
|
||||
@@ -57,6 +57,8 @@ func explode():
|
||||
body.velocity += clamp(blast_velocity,Vector3(-7,-7,-7),Vector3(7,7,7))
|
||||
if body.is_in_group("enemy"):
|
||||
body.knocked = true
|
||||
body.stunned = true
|
||||
print("knocked")
|
||||
body.knocked_timer.start()
|
||||
body.stunned_timer.start()
|
||||
body.velocity += blast_velocity
|
||||
|
||||
@@ -27,6 +27,7 @@ const MAX_AV = 10
|
||||
@onready var prefire_timer = $Timers/prefire_timer
|
||||
@onready var postfire_timer = $Timers/postfire_timer
|
||||
@onready var knocked_timer = $Timers/knocked_timer
|
||||
@onready var stunned_timer = $Timers/stunned_timer
|
||||
@onready var turret_look_next = $TurretLookNext
|
||||
@onready var spider_look_next = $SpiderLookNext
|
||||
@onready var body = $body
|
||||
@@ -52,7 +53,8 @@ var body_look_to
|
||||
var distance_to_player
|
||||
var hive_velocity
|
||||
var hive_nav_point
|
||||
var knocked
|
||||
var knocked = false
|
||||
var stunned = false
|
||||
|
||||
func _ready():
|
||||
player = get_node(player_path)
|
||||
@@ -69,20 +71,19 @@ func _process(delta):
|
||||
if !knocked:
|
||||
velocity = hive_velocity
|
||||
|
||||
#FIX BODY ROTATION
|
||||
spider_look_next.look_at(Vector3(player.global_position.x, 0, player.global_position.z), Vector3.UP)
|
||||
body.rotation.y = lerp(body.rotation.y, spider_look_next.rotation.y, delta * 1)
|
||||
|
||||
turret_look_next.look_at(player.global_position,Vector3.UP)
|
||||
turret_look.rotation = lerp(turret_look.rotation,turret_look_next.rotation,delta * turret_look_speed)
|
||||
|
||||
#distance_to_player = abs(self.global_position - player.global_position)
|
||||
if !stunned:
|
||||
spider_look_next.look_at(Vector3(player.global_position.x, 0, player.global_position.z), Vector3.UP)
|
||||
body.rotation.y = lerp(body.rotation.y, spider_look_next.rotation.y, delta * 1)
|
||||
turret_look_next.look_at(player.global_position,Vector3.UP)
|
||||
turret_look.rotation = lerp(turret_look.rotation,turret_look_next.rotation,delta * turret_look_speed)
|
||||
else:
|
||||
body.rotation.y = lerp(body.rotation.y, body.rotation.y + 10, delta * .5)
|
||||
turret_look.rotation.y = lerp(turret_look.rotation.y,turret_look.rotation.y - 5,delta * 1)
|
||||
|
||||
#apply gravity
|
||||
if !is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
#if distance_to_player.x > 4 or distance_to_player.z > 4:
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
@@ -100,8 +101,7 @@ func _on_area_3d_body_part_hit(dam,bullet_damage):
|
||||
|
||||
#pickup drop
|
||||
while number_of_drops > 0:
|
||||
level_control.pickup_spawn()
|
||||
var rand_selector = rng.randi_range(1,4)
|
||||
var rand_item = level_control.pickup_spawn()
|
||||
var lv_x = rng.randf_range(-MAX_LV,MAX_LV)
|
||||
var lv_y = rng.randf_range(0,MAX_LV)
|
||||
var lv_z = rng.randf_range(-MAX_LV,MAX_LV)
|
||||
@@ -109,17 +109,8 @@ func _on_area_3d_body_part_hit(dam,bullet_damage):
|
||||
var av_y = rng.randf_range(-MAX_AV,MAX_AV)
|
||||
var av_z = rng.randf_range(-MAX_AV,MAX_AV)
|
||||
|
||||
match rand_selector:
|
||||
1:
|
||||
rand_select = stamina
|
||||
2:
|
||||
rand_select = ammo
|
||||
3:
|
||||
rand_select = money
|
||||
4:
|
||||
rand_select = health_pickup
|
||||
# Random Item Drop
|
||||
rand_item = rand_select.instantiate()
|
||||
#rand_item = rand_select.instantiate()
|
||||
rand_item.position = self.global_position
|
||||
rand_item.transform.basis = self.global_transform.basis
|
||||
rand_item.linear_velocity += self.global_transform.basis * Vector3(lv_x,lv_y,lv_z)
|
||||
@@ -168,7 +159,7 @@ func _on_prefire_timer_timeout():
|
||||
|
||||
|
||||
func _on_postfire_timer_timeout():
|
||||
if turret_look_next.is_colliding() and turret_look_next.get_collider().is_in_group("player"):
|
||||
if turret_look_next.is_colliding() and turret_look_next.get_collider().is_in_group("player") and !stunned:
|
||||
prefire_timer.start()
|
||||
turret_material.emission_enabled = true
|
||||
else:
|
||||
@@ -179,3 +170,8 @@ func _on_knocked_timer_timeout():
|
||||
print("KNOCK TIMEOUT")
|
||||
velocity = Vector3(0,0,0)
|
||||
knocked = false
|
||||
|
||||
|
||||
func _on_stunned_timer_timeout():
|
||||
print("STUN TIMEOUT")
|
||||
stunned = false
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@export var gun_resource : Resource
|
||||
@export var pickupType: String
|
||||
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickupType: int
|
||||
@export var collision_shape : Node
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
@@ -12,3 +14,13 @@ func _ready():
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func picked_up():
|
||||
level_control.held_guns.append(gun_resource)
|
||||
var instance_gun = gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
level_control.ammo_reserve.append(instance_gun.max_ammo * instance_gun.start_mags)
|
||||
var weapon_id = level_control.held_guns.size() - 1
|
||||
level_control.player.gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(weapon_id)
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user