From 1623d468a37dab4a09c5780c008b598b0b4a0fbc Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Wed, 4 Dec 2024 17:02:57 -0700 Subject: [PATCH] Club angle & power are properties of the club --- src/equipment/clubs/club.gd | 3 + src/equipment/clubs/drivers/debug_driver.tres | 2 + src/equipment/clubs/irons/debug_iron.tres | 2 + src/equipment/clubs/putters/debug_putter.tres | 2 + src/equipment/clubs/wedges/debug_wedge.tres | 2 + src/player/shot_setup/shot_setup.gd | 59 +++++++++---------- src/player/shot_setup/shot_setup.tscn | 32 +--------- src/player/shot_setup/shot_sfx.gd | 4 +- .../shot_hud/club_selector/club_selector.gd | 2 +- 9 files changed, 43 insertions(+), 65 deletions(-) diff --git a/src/equipment/clubs/club.gd b/src/equipment/clubs/club.gd index e263843..475e8c8 100644 --- a/src/equipment/clubs/club.gd +++ b/src/equipment/clubs/club.gd @@ -14,6 +14,9 @@ enum Type { @export var type: Club.Type @export var _model: PackedScene +@export_range(-360, 360, 0.001, "radians") var angle := 0.0 +@export var power := 1.0 + ## Global typesafe accessor for club catalog static var catalog: ClubCatalogType: get: diff --git a/src/equipment/clubs/drivers/debug_driver.tres b/src/equipment/clubs/drivers/debug_driver.tres index 567139b..3715d06 100644 --- a/src/equipment/clubs/drivers/debug_driver.tres +++ b/src/equipment/clubs/drivers/debug_driver.tres @@ -8,3 +8,5 @@ script = ExtResource("1_7mcyu") name = "DEBUG Driver" type = 1 _model = ExtResource("1_ug675") +angle = 0.785398 +power = 1.0 diff --git a/src/equipment/clubs/irons/debug_iron.tres b/src/equipment/clubs/irons/debug_iron.tres index 4fe46c1..42570a6 100644 --- a/src/equipment/clubs/irons/debug_iron.tres +++ b/src/equipment/clubs/irons/debug_iron.tres @@ -8,3 +8,5 @@ script = ExtResource("1_6ksva") name = "DEBUG Iron" type = 2 _model = ExtResource("1_5wgil") +angle = 0.785398 +power = 0.6 diff --git a/src/equipment/clubs/putters/debug_putter.tres b/src/equipment/clubs/putters/debug_putter.tres index d89fff0..9330141 100644 --- a/src/equipment/clubs/putters/debug_putter.tres +++ b/src/equipment/clubs/putters/debug_putter.tres @@ -8,3 +8,5 @@ script = ExtResource("1_qlirk") name = "DEBUG Putter" type = 4 _model = ExtResource("1_ghpah") +angle = 0.0 +power = 0.8 diff --git a/src/equipment/clubs/wedges/debug_wedge.tres b/src/equipment/clubs/wedges/debug_wedge.tres index e9ce791..2937f59 100644 --- a/src/equipment/clubs/wedges/debug_wedge.tres +++ b/src/equipment/clubs/wedges/debug_wedge.tres @@ -8,3 +8,5 @@ script = ExtResource("1_gy3nk") name = "DEBUG Wedge" type = 3 _model = ExtResource("1_voves") +angle = 1.39626 +power = 0.8 diff --git a/src/player/shot_setup/shot_setup.gd b/src/player/shot_setup/shot_setup.gd index df5e435..d38c2fa 100644 --- a/src/player/shot_setup/shot_setup.gd +++ b/src/player/shot_setup/shot_setup.gd @@ -48,7 +48,7 @@ const EXPLOSIVE_FORCE_FACTOR := 0.12 @export var driving_range := false ## Initially-selected club -@export var initial_club: Club.Type = Club.Type.DRIVER +@export var initial_club_type: Club.Type = Club.Type.DRIVER ## Initially-selected ball type @export var initial_ball: GameBall.Type = GameBall.Type.BASIC @@ -92,11 +92,15 @@ var phase: Phase = Phase.FINISHED: var hud: ShotHUD -var club: Club.Type: +var club_type: Club.Type: set(value): - if value != club: + if value != club_type: _on_club_change(value) - club = value + club_type = value + +var club: Club: + get: + return player.get_club(club_type) if player else null var ball_type: GameBall.Type: set(value): @@ -105,8 +109,6 @@ var ball_type: GameBall.Type: ball_point.spawn_ball(value) ball_type = value -var shot_ref: Node3D - var shot_power: float: set(value): hud.power_bar.value = value @@ -149,13 +151,9 @@ var _tracking_camera: OrbitalCamera @onready var ball_point: BallPoint = %BallPoint -@onready var drive_ref: RayCast3D = %DriveRef @onready var drive_arrow: Node3D = %DriveArrow -@onready var wedge_ref: RayCast3D = %WedgeRef @onready var wedge_arrow: Node3D = %WedgeArrow -@onready var iron_ref: RayCast3D = %IronRef @onready var iron_arrow: Node3D = %IronArrow -@onready var putt_ref: RayCast3D = %PuttRef @onready var putt_arrow: Node3D = %PuttArrow @onready var downswing_timer: Timer = %DownswingTimer @@ -180,7 +178,7 @@ func _ready() -> void: hud = ShotHUD.create(player) world.ui.add_player_hud(hud) ball_type = initial_ball - club = initial_club + club_type = initial_club_type character.set_color(player.color) # Set up player 3D label @@ -240,21 +238,22 @@ func finish_downswing() -> void: func get_shot_impulse(meter_pct: float) -> Vector3: - return -shot_ref.global_basis.z * base_power * meter_pct + return ( + -direction.global_basis.rotated(direction.global_basis.x, club.angle).z + * club.power + * base_power + * meter_pct + ) func take_shot() -> void: - # Impact screenshake & hitlag + # Impact screenshake if game: if shot_power > BIG_POWER_THRESHOLD: - #game.viewport.hit_lag_big() var shake_intensity: float = ( 10.0 * (shot_power - BIG_POWER_THRESHOLD) / (1.0 - BIG_POWER_THRESHOLD) ) game.viewport.screen_shake(shake_intensity, 1.0) - else: - pass - #game.viewport.hit_lag_small() print_debug("WHACK!\nPower: ", shot_power, "\nCurve: ", shot_curve) @@ -263,7 +262,7 @@ func take_shot() -> void: print_debug("Shot impulse: ", impulse, "; ", impulse.length(), " N*s") # Curve the curve - var curve := shot_ref.global_basis.x.normalized() * shot_curve + var curve := direction.global_basis.x.normalized() * shot_curve # Position where the ball is hit (imparts spin) var offset := curve * 0.001 @@ -272,12 +271,12 @@ func take_shot() -> void: impulse = impulse.rotated(Vector3.UP, -shot_curve * CURVE_INFLUENCE * shot_power) if game_ball: - game_ball.iron_ball = club == Club.Type.IRON + game_ball.iron_ball = club_type == Club.Type.IRON game_ball.freeze = false game_ball.apply_impulse(impulse, offset) # Play SFX - shot_sfx.play_shot_sfx(club, is_shot_good(), shot_power) + shot_sfx.play_shot_sfx(club_type, is_shot_good(), shot_power) # Use a ball if a limited type is selected if player.get_balls(ball_type) > 0: @@ -289,9 +288,9 @@ func _show_shot_projection() -> void: if not game_ball: return - shot_projection.putt_projection = club == Club.Type.PUTTER + shot_projection.putt_projection = club_type == Club.Type.PUTTER shot_projection.initial_speed = 1 - shot_projection.basis = shot_ref.basis.orthonormalized() + shot_projection.basis = Basis.from_euler(Vector3(club.angle, 0, 0)) var shot_speed := get_shot_impulse(1.0).length() / game_ball.mass var tween := get_tree().create_tween() tween.tween_property(shot_projection, "initial_speed", shot_speed, CAMERA_SNAP_TIME).set_trans( @@ -401,20 +400,16 @@ func _on_club_change(new_club_type: Club.Type) -> void: character.hold_right(new_club.get_model()) match new_club_type: Club.Type.DRIVER: - shot_ref = drive_ref drive_arrow.show() Club.Type.PUTTER: - shot_ref = putt_ref putt_arrow.show() Club.Type.WEDGE: - shot_ref = wedge_ref wedge_arrow.show() Club.Type.IRON: - shot_ref = iron_ref iron_arrow.show() Club.Type.SPECIAL: # TODO figure this out - shot_ref = drive_ref + pass _: print_debug("Not sure how to equip club type: ", new_club) @@ -522,15 +517,15 @@ func _process(delta: float) -> void: # Club select if Input.is_action_just_pressed("select_driver"): - club = Club.Type.DRIVER + club_type = Club.Type.DRIVER if Input.is_action_just_pressed("select_iron"): - club = Club.Type.IRON + club_type = Club.Type.IRON if Input.is_action_just_pressed("select_wedge"): - club = Club.Type.WEDGE + club_type = Club.Type.WEDGE if Input.is_action_just_pressed("select_special"): - club = Club.Type.SPECIAL + club_type = Club.Type.SPECIAL if Input.is_action_just_pressed("select_putter"): - club = Club.Type.PUTTER + club_type = Club.Type.PUTTER # Ball select if Input.is_action_just_pressed("ball_next"): diff --git a/src/player/shot_setup/shot_setup.tscn b/src/player/shot_setup/shot_setup.tscn index 9df01a7..682250d 100644 --- a/src/player/shot_setup/shot_setup.tscn +++ b/src/player/shot_setup/shot_setup.tscn @@ -348,36 +348,8 @@ transform = Transform3D(-0.311543, -0.0687373, 0.947743, 0, 0.99738, 0.0723374, [node name="Direction" type="Node3D" parent="."] unique_name_in_owner = true -[node name="DriveRef" type="RayCast3D" parent="Direction"] -unique_name_in_owner = true -transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, 0.08, 0) -enabled = false -target_position = Vector3(0, 0, -1) -collision_mask = 0 -collide_with_bodies = false -debug_shape_thickness = 4 - -[node name="WedgeRef" type="RayCast3D" parent="Direction"] -unique_name_in_owner = true -transform = Transform3D(0.7, 0, 0, 0, 0.181173, -0.676148, 0, 0.676148, 0.181173, 0, 0.08, 0) -enabled = false -target_position = Vector3(0, 0, -1) -collision_mask = 0 -collide_with_bodies = false -debug_shape_thickness = 4 - -[node name="IronRef" type="RayCast3D" parent="Direction"] -unique_name_in_owner = true -transform = Transform3D(0.7, 0, 0, 0, 0.449952, -0.536231, 0, 0.536231, 0.449952, 0, 0.08, 0) -enabled = false -target_position = Vector3(0, 0, -1) -collision_mask = 0 -collide_with_bodies = false -debug_shape_thickness = 4 - -[node name="PuttRef" type="RayCast3D" parent="Direction"] -unique_name_in_owner = true -transform = Transform3D(0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, 0, 0.08, 0) +[node name="ShotRef" type="RayCast3D" parent="Direction"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.08, 0) enabled = false target_position = Vector3(0, 0, -1) collision_mask = 0 diff --git a/src/player/shot_setup/shot_sfx.gd b/src/player/shot_setup/shot_sfx.gd index fa888c0..b04ae06 100644 --- a/src/player/shot_setup/shot_sfx.gd +++ b/src/player/shot_setup/shot_sfx.gd @@ -13,9 +13,9 @@ func _attenuate_volume(power: float) -> float: return lerpf(BASE_VOLUME, MAX_VOLUME, power) -func play_shot_sfx(club: Club.Type, good: bool, power: float) -> void: +func play_shot_sfx(club_type: Club.Type, good: bool, power: float) -> void: var player: AudioStreamPlayer3D - match club: + match club_type: Club.Type.PUTTER: player = putt_sfx_player _: diff --git a/src/ui/shot_hud/club_selector/club_selector.gd b/src/ui/shot_hud/club_selector/club_selector.gd index aa0b933..04310e7 100644 --- a/src/ui/shot_hud/club_selector/club_selector.gd +++ b/src/ui/shot_hud/club_selector/club_selector.gd @@ -35,7 +35,7 @@ func set_state_for_player(player: WorldPlayer) -> void: special_label.set_enabled(player.special != null) putter_label.set_enabled(player.putter != null) if player.shot_setup: - value = player.shot_setup.club + value = player.shot_setup.club_type func _get_club_label(club: Club.Type) -> Label: