mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-23 21:35:29 +00:00
✨ Weapon reload mechanics and reticle first-pass
This commit is contained in:
parent
b3f8c203e5
commit
8fc00e4bdf
2 changed files with 52 additions and 22 deletions
|
|
@ -86,3 +86,40 @@ offset_right = 21.0
|
|||
offset_bottom = -10.0
|
||||
grow_vertical = 0
|
||||
script = SubResource("GDScript_w8l21")
|
||||
|
||||
[node name="Reticle" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="LineBottom" type="Line2D" parent="Reticle"]
|
||||
position = Vector2(13, 4)
|
||||
points = PackedVector2Array(7, 19, 7, 31)
|
||||
width = 2.0
|
||||
|
||||
[node name="LineLeft" type="Line2D" parent="Reticle"]
|
||||
position = Vector2(36, 13)
|
||||
rotation = 1.5708
|
||||
points = PackedVector2Array(7, 19, 7, 31)
|
||||
width = 2.0
|
||||
|
||||
[node name="LineTop" type="Line2D" parent="Reticle"]
|
||||
position = Vector2(13, -14)
|
||||
points = PackedVector2Array(7, 19, 7, 31)
|
||||
width = 2.0
|
||||
|
||||
[node name="LineRight" type="Line2D" parent="Reticle"]
|
||||
position = Vector2(54, 13)
|
||||
rotation = 1.5708
|
||||
points = PackedVector2Array(7, 19, 7, 31)
|
||||
width = 2.0
|
||||
|
|
|
|||
|
|
@ -1,37 +1,30 @@
|
|||
extends Node3D
|
||||
class_name SpaceGun
|
||||
|
||||
signal shoot(projectile, velocity, initial_location, initial_rotation)
|
||||
|
||||
const PROJECTILE = preload("res://weapons/space_gun/projectile.tscn")
|
||||
|
||||
@onready var nozzle = $Nozzle
|
||||
@onready var inventory = get_parent()
|
||||
|
||||
const ammo_max : int = 20
|
||||
var ammo : int = ammo_max
|
||||
enum WeaponState { WEAPON_READY, WEAPON_RELOADING }
|
||||
|
||||
var inheritance : float = 100.0 # percent
|
||||
var weapon_state : WeaponState = WeaponState.WEAPON_READY
|
||||
|
||||
func print_node_properties(node):
|
||||
var properties = node.get_property_list()
|
||||
for prop in properties:
|
||||
prints(prop.name, node.get(prop.name))
|
||||
|
||||
func _ready():
|
||||
shoot.connect(_on_shoot)
|
||||
const inheritance : float = .5 # ratio
|
||||
const reload_time : float = 1. # seconds
|
||||
|
||||
func fire_primary():
|
||||
if weapon_state != WeaponState.WEAPON_READY:
|
||||
return
|
||||
|
||||
var projectile = PROJECTILE.instantiate()
|
||||
shoot.emit(projectile, nozzle, inventory.owner)
|
||||
|
||||
|
||||
func _on_shoot(projectile, origin, player):
|
||||
projectile.position = origin.global_position
|
||||
projectile.rotation = origin.global_rotation
|
||||
projectile.velocity = origin.global_basis.z.normalized() * projectile.speed
|
||||
var inheritance_factor = clamp(inheritance, 0., 100.) / 100.
|
||||
projectile.velocity += (player.linear_velocity * inheritance_factor)
|
||||
projectile.transform = nozzle.global_transform
|
||||
projectile.velocity = nozzle.global_basis.z.normalized() * projectile.speed
|
||||
var inheritance_factor = clamp(inheritance, 0., 1.)
|
||||
projectile.velocity += (inventory.owner.linear_velocity * inheritance_factor)
|
||||
inventory.owner.add_sibling(projectile)
|
||||
var collider = projectile.shape_cast
|
||||
collider.add_exception(player)
|
||||
collider.add_exception(inventory.owner)
|
||||
weapon_state = WeaponState.WEAPON_RELOADING
|
||||
await get_tree().create_timer(reload_time).timeout
|
||||
weapon_state = WeaponState.WEAPON_READY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue