diff --git a/entities/flag/flag.gd b/entities/flag/flag.gd index b6767f6..e8521a7 100644 --- a/entities/flag/flag.gd +++ b/entities/flag/flag.gd @@ -5,7 +5,7 @@ enum FlagState { FLAG_STATE_ON_STAND, FLAG_STATE_DROPPED, FLAG_STATE_TAKEN } @export var flag_state : FlagState = FlagState.FLAG_STATE_ON_STAND signal grabbed(grabber : Player) -signal regrabbed +signal regrabbed(grabber : Player) signal dropped(dropper : Player) var last_carrier : Player = null @@ -22,7 +22,7 @@ func grab(grabber : Player) -> void: grabbed.emit(grabber) last_carrier = grabber else: - regrabbed.emit() + regrabbed.emit(grabber) func drop(dropper : Player) -> void: if flag_state == FlagState.FLAG_STATE_TAKEN: diff --git a/entities/player/player.gd b/entities/player/player.gd index 79068bd..31b5c90 100644 --- a/entities/player/player.gd +++ b/entities/player/player.gd @@ -60,6 +60,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD } signal died(player : Player, killer_id : int) signal energy_changed(energy : float) +static var pawn_player : Player var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m/s² var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector") var _jumping : bool = false @@ -85,6 +86,7 @@ func _ready() -> void: if _is_pawn(): camera.current = true camera.fov = _game_settings.fov + pawn_player = self # set the spring arm translation to be about head height level $Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9) diff --git a/interfaces/hud/iffs/iff.gd b/interfaces/hud/iffs/iff.gd index 0c30415..8b31bb5 100644 --- a/interfaces/hud/iffs/iff.gd +++ b/interfaces/hud/iffs/iff.gd @@ -37,10 +37,19 @@ func _process(_delta : float) -> void: # if the player is NOT infront of the camera or camera does NOT have LOS to player if camera.is_position_behind(attach_point.global_position) or !is_within_los: - _iff_container.hide() # hide the IFF and exit function - return + _iff_container.hide() else: - _iff_container.show() # display the IFF + _iff_container.show() + + # Show the correct IFF based on whether the player we're looking at belongs is a friend or a foe + # in other words if their team_ids are the same as the "pawn" player + if player.pawn_player != null: + if player.pawn_player.team_id == player.team_id: + %FoeChevron.hide() + %FriendChevron.show() + else: + %FoeChevron.show() + %FriendChevron.hide() func _physics_process(_delta : float) -> void: # https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html @@ -48,9 +57,12 @@ func _physics_process(_delta : float) -> void: is_within_los = false # always initialise trace_success as false var space_state : PhysicsDirectSpaceState3D = camera.get_world_3d().direct_space_state # do a trace check from camera to towards the player - var query : PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(camera.global_position, attach_point.global_position) + var query : PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(camera.global_position, player.global_position) + # only collide with Layer 1 (objects) and Layer 32 (terrain/structures) + query.collision_mask = 0b10000000_00000000_00000000_00000001 # exclude the camera owner nodes from intersecting with the trace check - query.exclude = [camera.owner] + if player.pawn_player: + query.exclude = [player.pawn_player] # do trace check and store result var result : Dictionary = space_state.intersect_ray(query) # if a result was returned and the hit result is the player @@ -74,7 +86,6 @@ func _physics_process(_delta : float) -> void: new_iff_position.y -= _iff_container.size.y # move the IFF up so the bottom of it is at the players head new_iff_position.x -= _iff_container.size.x / 2 # move the IFF left so it's centered horizontally above players head - position = new_iff_position # set the position of the IFF func _update_health_bar(health : float) -> void: diff --git a/interfaces/hud/iffs/iff.tscn b/interfaces/hud/iffs/iff.tscn index eeb48a6..e26d442 100644 --- a/interfaces/hud/iffs/iff.tscn +++ b/interfaces/hud/iffs/iff.tscn @@ -40,7 +40,9 @@ theme_override_styles/fill = ExtResource("2_e3xla") value = 60.0 show_percentage = false -[node name="Chevron" type="Label" parent="IFFContainer"] +[node name="FoeChevron" type="Label" parent="IFFContainer"] +unique_name_in_owner = true +visible = false layout_direction = 2 layout_mode = 2 size_flags_vertical = 1 @@ -52,3 +54,18 @@ theme_override_font_sizes/font_size = 14 text = "▼" horizontal_alignment = 1 vertical_alignment = 2 + +[node name="FriendChevron" type="Label" parent="IFFContainer"] +unique_name_in_owner = true +visible = false +layout_direction = 2 +layout_mode = 2 +size_flags_vertical = 1 +theme_override_colors/font_color = Color(0, 1, 0, 0.2) +theme_override_colors/font_outline_color = Color(0, 0, 0, 0.2) +theme_override_constants/outline_size = 3 +theme_override_constants/line_spacing = -20 +theme_override_font_sizes/font_size = 14 +text = "▼" +horizontal_alignment = 1 +vertical_alignment = 2 diff --git a/modes/multiplayer.gd b/modes/multiplayer.gd index 9350cde..0741b61 100644 --- a/modes/multiplayer.gd +++ b/modes/multiplayer.gd @@ -120,6 +120,7 @@ func _load_map(scene : PackedScene, nickname : String) -> void: func _add_flag() -> void: _flag = FLAG.instantiate() _flag.grabbed.connect(_on_flag_grabbed) + _flag.regrabbed.connect(_on_flag_regrabbed) _flag.dropped.connect(_on_flag_dropped) _flag.global_position = _map_manager.get_flagstand().global_position objectives.add_child(_flag) @@ -134,6 +135,9 @@ func _on_flag_grabbed(grabber : Player) -> void: scoreboard.add_score_to_player(grabber, 10) _flag_carrier_scoring_timer.start() +func _on_flag_regrabbed(grabber : Player) -> void: + grabber.team_id = team_rabbit.team_id + func _on_flag_dropped(dropper : Player) -> void: dropper.team_id = team_chasers.team_id _flag_carrier_scoring_timer.stop()