Players can damage one another

This commit is contained in:
Rob Kelly 2024-11-18 12:57:11 -07:00
parent 7c7458be65
commit 40a1b3548a
7 changed files with 61 additions and 4 deletions

View File

@ -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(

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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"]

View File

@ -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:

View File

@ -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")