blunderbuss working
This commit is contained in:
@@ -22,3 +22,8 @@ func hit(bullet_damage):
|
||||
number_spawn.damage_amt = bullet_damage * damage
|
||||
number_spawn.position = global_position + Vector3(0,2,0)
|
||||
get_tree().get_root().add_child(number_spawn)
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if body.is_in_group("pellet"):
|
||||
hit(body.bullet_damage)
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
|
||||
138
scripts/blunderbus.gd
Normal file
138
scripts/blunderbus.gd
Normal file
@@ -0,0 +1,138 @@
|
||||
extends Node3D
|
||||
|
||||
var start_position
|
||||
var start_rotation
|
||||
var random_spread_start
|
||||
var cycle_count_start
|
||||
var cycle_count
|
||||
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,0,0)
|
||||
@export var spread : Vector3 = Vector3(1,1,1)
|
||||
@export var kick_amount : float = 5
|
||||
@export var max_ammo = 15
|
||||
@export var start_mags = 3
|
||||
@export var pellets_per_shot = 12
|
||||
@export var bullet_damage = 1
|
||||
@export var bullet_force_mod = 5
|
||||
@export var blast_power = 50.0
|
||||
@export var bullet_speed : float = 150
|
||||
@export var bullet_drop = .3
|
||||
@export var random_spread_amt = 1.0
|
||||
@export var fire_pitch_scale_amt = .2
|
||||
@export_group("Gun Assets")
|
||||
@export_subgroup("Main Assets")
|
||||
@export var bullet : Resource
|
||||
@export_subgroup("Raycast Nodes")
|
||||
@export var anim_player : Node
|
||||
@export var barrel_raycast : Node
|
||||
@export_subgroup("Audio Clips")
|
||||
@export var audio_fire : Node
|
||||
@export var audio_empty : Node
|
||||
@export var audio_reload : Node
|
||||
|
||||
@onready var player = get_tree().current_scene.player
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var ammo_current
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var gun_index
|
||||
#var ammo_current
|
||||
var ammo_reserve
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
start_position = self.position
|
||||
start_rotation = self.rotation
|
||||
random_spread_start = random_spread_amt
|
||||
|
||||
ammo_current = level_control.ammo_current[gun_index]
|
||||
ammo_reserve = level_control.ammo_reserve[gun_index]
|
||||
|
||||
|
||||
if fire_mode == 0:
|
||||
cycle_count = 1
|
||||
cycle_count_start = 1
|
||||
elif fire_mode == 1:
|
||||
cycle_count = 1
|
||||
cycle_count_start = 1
|
||||
elif fire_mode == 2:
|
||||
cycle_count = 3
|
||||
cycle_count_start = 3
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta):
|
||||
pass
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
|
||||
|
||||
func shoot(delta):
|
||||
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
#RECOIL --- fix later to happen over a period of time
|
||||
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
anim_player.play("shoot")
|
||||
|
||||
pellet_spawn()
|
||||
player.recoil.add_recoil(Vector3(0,recoil_amount.y,recoil_amount.z),10,10)
|
||||
player.recoil.add_gun_recoil(recoil_amount.x)
|
||||
player.velocity += player.bullet_ray.global_basis * Vector3(0,0, kick_amount)
|
||||
if fire_mode != 0:
|
||||
cycle_count -= 1
|
||||
|
||||
elif !anim_player.is_playing() and cycle_count != 0:
|
||||
anim_player.play("empty")
|
||||
audio_empty.play()
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if level_control.ammo_current[gun_index] == 0:
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
else:
|
||||
level_control.ammo_current[gun_index] = 1
|
||||
|
||||
#func spawn_mag():
|
||||
#var instance_mag = mag.instantiate()
|
||||
#instance_mag.position = mag_ejector.global_position
|
||||
#instance_mag.transform.basis = mag_ejector.global_transform.basis
|
||||
#get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
func pellet_spawn():
|
||||
var pellets_remaining = pellets_per_shot
|
||||
while pellets_remaining > 0:
|
||||
var lv_x = randf_range(-spread.x,spread.x)
|
||||
var lv_y = randf_range(-spread.y,spread.y)
|
||||
# instance bullet
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = player.bullet_ray.global_position
|
||||
instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
|
||||
instance_bullet.linear_velocity += instance_bullet.transform.basis * Vector3(lv_x, lv_y, -bullet_speed) + player.velocity
|
||||
instance_bullet.bullet_damage = bullet_damage
|
||||
instance_bullet.bullet_force_mod = bullet_force_mod
|
||||
instance_bullet.player_position = player.global_position
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
pellets_remaining -= 1
|
||||
|
||||
func swapped_out():
|
||||
queue_free()
|
||||
@@ -105,7 +105,7 @@ func shoot(delta):
|
||||
anim_player.play("empty")
|
||||
audio_empty.play()
|
||||
|
||||
func reload(delta):
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
|
||||
@@ -263,7 +263,7 @@ func _physics_process(delta):
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
gun.reload(delta)
|
||||
gun.reload()
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
@@ -163,7 +163,7 @@ func fire(delta):
|
||||
player.recoil.add_gun_recoil(recoil_amount.x)
|
||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||
|
||||
func reload(delta):
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
|
||||
@@ -108,7 +108,7 @@ func shoot(delta):
|
||||
anim_player.play("empty")
|
||||
audio_empty.play()
|
||||
|
||||
func reload(delta):
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
|
||||
67
scripts/shotgun_pellet.gd
Normal file
67
scripts/shotgun_pellet.gd
Normal file
@@ -0,0 +1,67 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@export var max_bounces : int = 10
|
||||
|
||||
@onready var collision_shape: CollisionShape3D = $CollisionShape3D
|
||||
@onready var mesh: MeshInstance3D = $MeshInstance3D
|
||||
@onready var material = mesh.get_surface_override_material(0)
|
||||
|
||||
var bullet_force_mod
|
||||
var bullet_damage
|
||||
var player_position
|
||||
var bounces = 0
|
||||
var start_time
|
||||
var end_time
|
||||
|
||||
const EMISSION_MAX : float = 20
|
||||
const EMISSION_LIFETIME : float = 2 #in seconds
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
start_time = Time.get_ticks_msec()
|
||||
end_time = start_time + (EMISSION_LIFETIME * 1000)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var current_time = (Time.get_ticks_msec())/end_time
|
||||
material.emission_energy_multiplier = clamp(lerp(EMISSION_MAX,0.0,current_time),0,EMISSION_MAX)
|
||||
|
||||
var distance_from_player = abs(self.global_position - player_position)
|
||||
|
||||
if distance_from_player.length() > 1.5:
|
||||
visible = true
|
||||
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
bounces += 1
|
||||
if bounces >= max_bounces:
|
||||
despawn()
|
||||
|
||||
if body != null and !body.is_in_group("player"):
|
||||
|
||||
|
||||
if body.is_in_group("enemy_target"):
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
body.hit(bullet_damage)
|
||||
|
||||
|
||||
if body.is_in_group("switch"):
|
||||
body.hit()
|
||||
|
||||
#move rigidbodies
|
||||
if body.is_in_group("scene_rigidbody"):
|
||||
body.linear_velocity += transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
|
||||
if body.is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
body.breaking(current_velocity)
|
||||
|
||||
func despawn():
|
||||
collision_shape.disabled = true
|
||||
await get_tree().create_timer(1).timeout
|
||||
self.queue_free()
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
despawn()
|
||||
@@ -213,3 +213,7 @@ func drop_loot(number_of_drops):
|
||||
|
||||
if number_of_drops <= 0:
|
||||
can_die = true
|
||||
|
||||
|
||||
func _on_area_3d_body_entered(body: Node3D) -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
Reference in New Issue
Block a user