From 40a1b3548ac2be7055c27f5fc5bed9649fc9f075 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Mon, 18 Nov 2024 12:57:11 -0700 Subject: [PATCH] Players can damage one another --- src/equipment/balls/physics_ball/game_ball.gd | 3 +++ src/game/game.gd | 1 + src/player/shot_setup/hitbox.gd | 19 +++++++++++++++++++ src/player/shot_setup/shot_setup.gd | 7 ++++++- src/player/shot_setup/shot_setup.tscn | 15 ++++++++++++++- .../shot_hud/club_selector/club_selector.gd | 2 ++ src/world/world.tscn | 18 ++++++++++++++++-- 7 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/player/shot_setup/hitbox.gd diff --git a/src/equipment/balls/physics_ball/game_ball.gd b/src/equipment/balls/physics_ball/game_ball.gd index f077778..c99ab43 100644 --- a/src/equipment/balls/physics_ball/game_ball.gd +++ b/src/equipment/balls/physics_ball/game_ball.gd @@ -22,6 +22,9 @@ const IRON_DAMPING := 9999.0 physics_material_override = normal_physics iron_ball = value +## Base damage inflicted on impact with a player +@export var base_damage := 15.0 + var _zones: Array[BallZone] = [] @onready var normal_physics: PhysicsMaterial = preload( diff --git a/src/game/game.gd b/src/game/game.gd index d62245b..542b9d3 100644 --- a/src/game/game.gd +++ b/src/game/game.gd @@ -35,6 +35,7 @@ class ScenePromise: extends Promise func resolve(res: Variant) -> void: + @warning_ignore("unsafe_cast") var instance: Node = (res as PackedScene).instantiate() super.resolve(instance) diff --git a/src/player/shot_setup/hitbox.gd b/src/player/shot_setup/hitbox.gd new file mode 100644 index 0000000..0de869b --- /dev/null +++ b/src/player/shot_setup/hitbox.gd @@ -0,0 +1,19 @@ +extends Area3D +## World player hitbox + +signal ball_collision(ball: GameBall) + +@export var ignored_balls: Array[GameBall] = [] + +@onready var shot_setup: ShotSetup = $".." +@onready var physics_ball: GameBall = %PhysicsBall + + +func _on_ball_entered(ball: GameBall) -> void: + if not ball in ignored_balls: + ball_collision.emit(ball) + + +func _on_body_entered(body: Node3D) -> void: + if body is GameBall: + _on_ball_entered(body as GameBall) diff --git a/src/player/shot_setup/shot_setup.gd b/src/player/shot_setup/shot_setup.gd index 3203580..b60c903 100644 --- a/src/player/shot_setup/shot_setup.gd +++ b/src/player/shot_setup/shot_setup.gd @@ -161,7 +161,7 @@ func _init_deferred() -> void: func _ready() -> void: - call_deferred("_init_deferred") + _init_deferred.call_deferred() func _set_camera_distance(value: float) -> void: @@ -524,6 +524,11 @@ func _on_ball_return_timer_timeout() -> void: return_ball() +func _on_hitbox_ball_collision(ball: GameBall) -> void: + # TODO play animation + player.life -= ball.base_damage + + ## Create a new instance for the given player. static func create(_player: WorldPlayer) -> ShotSetup: var instance: ShotSetup = ShotSetup.scene.instantiate() diff --git a/src/player/shot_setup/shot_setup.tscn b/src/player/shot_setup/shot_setup.tscn index cb8f37d..3c92e90 100644 --- a/src/player/shot_setup/shot_setup.tscn +++ b/src/player/shot_setup/shot_setup.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=3 uid="uid://cy7t2tc4y3b4"] +[gd_scene load_steps=19 format=3 uid="uid://cy7t2tc4y3b4"] [ext_resource type="Script" path="res://src/player/shot_setup/shot_setup.gd" id="1_r6ei4"] [ext_resource type="PackedScene" uid="uid://dfttci386ohip" path="res://src/equipment/balls/physics_ball/physics_ball.tscn" id="2_1i5j5"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://1s3gywmoi20e" path="res://src/characters/player_characters/gfolf_girl/gfolf_girl.tscn" id="3_e4aur"] [ext_resource type="PackedScene" uid="uid://fht6j87o8ecr" path="res://src/ui/3d/projectile_arc/projectile_arc.tscn" id="4_ry2ho"] [ext_resource type="PackedScene" uid="uid://dbdul15c4oblg" path="res://src/ui/3d/projected_target.tscn" id="6_mynqj"] +[ext_resource type="Script" path="res://src/player/shot_setup/hitbox.gd" id="7_uh8kn"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_lnol1"] albedo_color = Color(0, 0.537255, 1, 1) @@ -203,6 +204,9 @@ _data = { "swing_delay": SubResource("Animation_u8k07") } +[sub_resource type="SphereShape3D" id="SphereShape3D_xvvdi"] +radius = 1.5 + [node name="ShotSetup" type="Node3D"] script = ExtResource("1_r6ei4") @@ -360,7 +364,16 @@ libraries = { unique_name_in_owner = true one_shot = true +[node name="Hitbox" type="Area3D" parent="." node_paths=PackedStringArray("ignored_balls")] +script = ExtResource("7_uh8kn") +ignored_balls = [NodePath("../BallPoint/PhysicsBall")] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"] +shape = SubResource("SphereShape3D_xvvdi") + [connection signal="body_entered" from="BallPoint/PhysicsBall" to="." method="_on_physics_ball_body_entered"] [connection signal="entered_water" from="BallPoint/PhysicsBall" to="." method="_on_ball_entered_water"] [connection signal="sleeping_state_changed" from="BallPoint/PhysicsBall" to="." method="_on_physics_ball_sleeping_state_changed"] [connection signal="timeout" from="BallReturnTimer" to="." method="_on_ball_return_timer_timeout"] +[connection signal="ball_collision" from="Hitbox" to="." method="_on_hitbox_ball_collision"] +[connection signal="body_entered" from="Hitbox" to="Hitbox" method="_on_body_entered"] diff --git a/src/ui/shot_hud/club_selector/club_selector.gd b/src/ui/shot_hud/club_selector/club_selector.gd index 5e70ee6..f948c55 100644 --- a/src/ui/shot_hud/club_selector/club_selector.gd +++ b/src/ui/shot_hud/club_selector/club_selector.gd @@ -34,6 +34,8 @@ func set_state_for_player(player: WorldPlayer) -> void: wedge_label.set_enabled(player.wedge != null) special_label.set_enabled(player.special != null) putter_label.set_enabled(player.putter != null) + if player.shot_setup: + value = player.shot_setup.club func _get_club_label(club: Club.Type) -> Label: diff --git a/src/world/world.tscn b/src/world/world.tscn index 4c94106..9a6708b 100644 --- a/src/world/world.tscn +++ b/src/world/world.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://cwnwcd8kushl3"] +[gd_scene load_steps=14 format=3 uid="uid://cwnwcd8kushl3"] [ext_resource type="Script" path="res://src/world/world.gd" id="1_ybjyx"] [ext_resource type="PackedScene" uid="uid://bm2o3mex10v11" path="res://levels/debug_level/debug_level.tscn" id="2_0xu5a"] @@ -7,10 +7,24 @@ [ext_resource type="Script" path="res://src/ui/world_ui.gd" id="2_imewa"] [ext_resource type="Resource" uid="uid://crock3revdn73" path="res://src/player/debug_player.tres" id="3_pyw81"] [ext_resource type="Script" path="res://src/world/play_manager/round_robin_manager.gd" id="5_h6mje"] +[ext_resource type="Resource" uid="uid://c1pnqsddvey3m" path="res://src/equipment/clubs/drivers/debug_driver.tres" id="5_vde2u"] +[ext_resource type="Resource" uid="uid://ck17u5yn6k0bi" path="res://src/equipment/clubs/irons/debug_iron.tres" id="6_86dlu"] +[ext_resource type="Resource" uid="uid://dagld0q5krapu" path="res://src/equipment/clubs/putters/debug_putter.tres" id="7_1nw4u"] +[ext_resource type="Resource" uid="uid://dthtc1no2c4wy" path="res://src/equipment/clubs/wedges/debug_wedge.tres" id="8_of7mw"] + +[sub_resource type="Resource" id="Resource_7tkuj"] +script = ExtResource("2_e743i") +life = 100.0 +name = "Gfolfer 2" +color = Color(0.44, 0.645333, 1, 1) +driver = ExtResource("5_vde2u") +iron = ExtResource("6_86dlu") +wedge = ExtResource("8_of7mw") +putter = ExtResource("7_1nw4u") [sub_resource type="Resource" id="Resource_rdjhi"] script = ExtResource("5_h6mje") -players = Array[ExtResource("2_e743i")]([ExtResource("3_pyw81")]) +players = Array[ExtResource("2_e743i")]([ExtResource("3_pyw81"), SubResource("Resource_7tkuj")]) [node name="World" type="Node" groups=["WorldGroup"]] script = ExtResource("1_ybjyx")