still working on ball possession
This commit is contained in:
parent
19b18532db
commit
90a179e6d3
@ -31,6 +31,16 @@ end_turn={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
grab_ball={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
drop_ball={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
radius = 13.0
|
||||
|
||||
[node name="Ball" type="RigidBody2D" unique_id=1681382008]
|
||||
mass = 0.65
|
||||
script = ExtResource("1_x8fbi")
|
||||
|
||||
[node name="BallSprite" type="Sprite2D" parent="." unique_id=982207895]
|
||||
|
||||
9
scenes/debug/debug_container.tscn
Normal file
9
scenes/debug/debug_container.tscn
Normal file
@ -0,0 +1,9 @@
|
||||
[gd_scene format=3 uid="uid://jbmh0ufhsbng"]
|
||||
|
||||
[node name="DebugContainer" type="VBoxContainer" unique_id=379013793]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="DebugHeader" type="Label" parent="." unique_id=1997943304]
|
||||
layout_mode = 2
|
||||
text = "DEBUG INFO"
|
||||
16
scenes/debug/debug_field.tscn
Normal file
16
scenes/debug/debug_field.tscn
Normal file
@ -0,0 +1,16 @@
|
||||
[gd_scene format=3 uid="uid://cfuxrrpf48w74"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cb35vwqypoqvd" path="res://scripts/debug/debug_field.gd" id="1_fqtbf"]
|
||||
|
||||
[node name="DebugField" type="HBoxContainer" unique_id=1030220017]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_fqtbf")
|
||||
|
||||
[node name="VariableLabel" type="Label" parent="." unique_id=1621640165]
|
||||
layout_mode = 2
|
||||
text = "VariableName: "
|
||||
|
||||
[node name="ValueLabel" type="Label" parent="." unique_id=1830807892]
|
||||
layout_mode = 2
|
||||
text = "VariableValue"
|
||||
11
scenes/debug/debug_object.tscn
Normal file
11
scenes/debug/debug_object.tscn
Normal file
@ -0,0 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://b4qlhcnyklahj"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://t1k260hy0286" path="res://scripts/debug/debug_object.gd" id="1_mv8di"]
|
||||
|
||||
[node name="DebugObject" type="VBoxContainer" unique_id=1345287721]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_mv8di")
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="." unique_id=2025252694]
|
||||
layout_mode = 2
|
||||
@ -6,6 +6,8 @@
|
||||
[ext_resource type="PackedScene" uid="uid://b7js4xq85ajf7" path="res://teams/orange_team.tscn" id="6_eow3j"]
|
||||
[ext_resource type="PackedScene" uid="uid://dndfw477wwjog" path="res://teams/blue_team.tscn" id="6_j5wjh"]
|
||||
[ext_resource type="PackedScene" uid="uid://cbqaj6trvqat0" path="res://scenes/ball.tscn" id="6_ryrav"]
|
||||
[ext_resource type="PackedScene" uid="uid://jbmh0ufhsbng" path="res://scenes/debug/debug_container.tscn" id="7_u5sy4"]
|
||||
[ext_resource type="PackedScene" uid="uid://b4qlhcnyklahj" path="res://scenes/debug/debug_object.tscn" id="8_gee14"]
|
||||
|
||||
[node name="Game" type="Node2D" unique_id=980666470 node_paths=PackedStringArray("ball", "court", "home_team", "away_team")]
|
||||
script = ExtResource("1_7jktm")
|
||||
@ -54,5 +56,14 @@ rotation = 2.8848953
|
||||
position = Vector2(760, 873)
|
||||
zoom = Vector2(1.5, 1.5)
|
||||
|
||||
[node name="GameDebug" type="CanvasLayer" parent="." unique_id=1401074573]
|
||||
|
||||
[node name="DebugContainer" parent="GameDebug" unique_id=379013793 instance=ExtResource("7_u5sy4")]
|
||||
|
||||
[node name="BallDebug" parent="GameDebug/DebugContainer" unique_id=1345287721 node_paths=PackedStringArray("target_object") instance=ExtResource("8_gee14")]
|
||||
layout_mode = 2
|
||||
target_object = NodePath("../../../Ball")
|
||||
target_variables = Array[StringName]([&"position", &"global_position"])
|
||||
|
||||
[editable path="OrangeTeam"]
|
||||
[editable path="BlueTeam"]
|
||||
|
||||
@ -46,8 +46,20 @@ editor_draw_screen = false
|
||||
avoidance_enabled = true
|
||||
radius = 25.0
|
||||
max_speed = 100000.0
|
||||
avoidance_priority = 0.5
|
||||
debug_enabled = true
|
||||
|
||||
[node name="PlayerHands" type="Node2D" parent="." unique_id=314541152]
|
||||
position = Vector2(25, 0)
|
||||
|
||||
[node name="PlayerLeftHand" type="RemoteTransform2D" parent="PlayerHands" unique_id=470792655]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(0, -10)
|
||||
|
||||
[node name="PlayerRightHand" type="RemoteTransform2D" parent="PlayerHands" unique_id=285981896]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(0, 10)
|
||||
|
||||
[node name="NavTargetSprite" type="Sprite2D" parent="." unique_id=1224616450]
|
||||
z_index = 10
|
||||
texture = SubResource("GradientTexture2D_hqtel")
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
extends Node
|
||||
|
||||
enum PlayerPosition {
|
||||
Guard,
|
||||
Wing,
|
||||
Big,
|
||||
enum PlayerHandedness {
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
|
||||
enum PlayerPosition {
|
||||
GUARD,
|
||||
WING,
|
||||
BIG,
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@ extends Resource
|
||||
@export var player_name: String
|
||||
@export_range(0.0, 99.0, 1.0, "prefer_slider") var player_number: int
|
||||
@export var player_position: Globals.PlayerPosition
|
||||
@export_range(150.0, 250.0, 1.0, "prefer_slider") var player_height: float ## Player height in centimetres; determines reach.
|
||||
@export_range(150.0, 250.0, 1.0, "prefer_slider") var player_height: float ## Player height in centimetres; determines reach.
|
||||
@export var player_handedness: Globals.PlayerHandedness
|
||||
@export_group("Abilities")
|
||||
@export var speed: float
|
||||
@export var reflexes: float
|
||||
|
||||
14
scripts/debug/debug_field.gd
Normal file
14
scripts/debug/debug_field.gd
Normal file
@ -0,0 +1,14 @@
|
||||
class_name DebugField
|
||||
extends HBoxContainer
|
||||
|
||||
var target_node: Node
|
||||
var variable_name: StringName
|
||||
|
||||
@onready var variable_label: Label = $VariableLabel
|
||||
@onready var value_label: Label = $ValueLabel
|
||||
|
||||
func _ready() -> void:
|
||||
variable_label.text = variable_name.to_pascal_case() + ": "
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
value_label.text = str(target_node.get(variable_name))
|
||||
1
scripts/debug/debug_field.gd.uid
Normal file
1
scripts/debug/debug_field.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cb35vwqypoqvd
|
||||
18
scripts/debug/debug_object.gd
Normal file
18
scripts/debug/debug_object.gd
Normal file
@ -0,0 +1,18 @@
|
||||
class_name DebugObject
|
||||
extends VBoxContainer
|
||||
|
||||
const DEBUG_FIELD = preload("uid://cfuxrrpf48w74")
|
||||
|
||||
@export var target_object: Node
|
||||
@export var target_variables: Array[StringName]
|
||||
|
||||
@onready var title_label: Label = $TitleLabel
|
||||
|
||||
func _ready() -> void:
|
||||
if target_object:
|
||||
title_label.text = "Debug info for %s" % target_object.name.to_upper()
|
||||
for variable in target_variables:
|
||||
var debug_field := DEBUG_FIELD.instantiate()
|
||||
debug_field.target_node = target_object
|
||||
debug_field.variable_name = variable
|
||||
add_child(debug_field)
|
||||
1
scripts/debug/debug_object.gd.uid
Normal file
1
scripts/debug/debug_object.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://t1k260hy0286
|
||||
@ -2,19 +2,26 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
## signals
|
||||
## Signals
|
||||
signal turn_finished
|
||||
|
||||
## export variables
|
||||
## Export variables
|
||||
@export var attributes: PlayerAttributes ## The attributes resource that defines the player's abilities, vitals etc.
|
||||
|
||||
## regular variables
|
||||
## Regular variables
|
||||
var current_ball: Ball
|
||||
var ball_within_reach: bool = false
|
||||
var has_ball: bool = false: set = set_has_ball
|
||||
var is_active: bool = false: set = set_active
|
||||
var desired_velocity: Vector2: set = set_desired_velocity
|
||||
var player_label_offset: Vector2
|
||||
|
||||
## 'onready' variables
|
||||
## child nodes
|
||||
## Onready variables
|
||||
## Child nodes
|
||||
@onready var player_camera: Camera2D = $PlayerCamera
|
||||
@onready var player_hands: Node2D = $PlayerHands
|
||||
@onready var player_left_hand: RemoteTransform2D = %PlayerLeftHand
|
||||
@onready var player_right_hand: RemoteTransform2D = %PlayerRightHand
|
||||
@onready var player_label: PlayerLabel = $PlayerLabel
|
||||
@onready var player_nav: NavigationAgent2D = $PlayerNav
|
||||
@onready var player_reach_area: Area2D = $PlayerReachArea
|
||||
@ -23,33 +30,42 @@ var player_label_offset: Vector2
|
||||
@onready var player_ui: CanvasLayer = $PlayerUI
|
||||
#@onready var end_turn_button: Button = %EndTurnButton
|
||||
|
||||
## Overrides
|
||||
## -- Overrides -- ##
|
||||
func _ready() -> void:
|
||||
_connect_signals()
|
||||
#set_player_attributes(attributes)
|
||||
|
||||
if attributes:
|
||||
_set_player_label_values(attributes)
|
||||
_set_player_sprite(attributes.player_texture)
|
||||
|
||||
_apply_attributes()
|
||||
player_label_offset = player_label.position
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
_set_player_label_position()
|
||||
player_label.global_position = global_position + player_label_offset
|
||||
if is_active:
|
||||
_set_nav_sprite_position()
|
||||
nav_target_sprite.global_position = get_global_mouse_position()
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
_set_desired_velocity()
|
||||
func _physics_process(delta: float) -> void:
|
||||
desired_velocity = global_position.direction_to(player_nav.get_next_path_position()) * attributes.speed
|
||||
if get_last_slide_collision():
|
||||
var collision = get_last_slide_collision()
|
||||
var collider = collision.get_collider()
|
||||
if collider is Ball:
|
||||
collider.apply_central_impulse(collision.get_normal() * -2.0)
|
||||
collider.apply_central_impulse(collision.get_normal() * -1.0)
|
||||
if has_ball:
|
||||
current_ball.apply_central_force(
|
||||
current_ball.global_position.direction_to(global_position) * current_ball.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("end_turn"):
|
||||
end_turn()
|
||||
|
||||
if event.is_action_pressed("drop_ball"):
|
||||
if has_ball: drop_ball(current_ball)
|
||||
else: print_debug("%s can't drop the ball" % attributes.player_name)
|
||||
|
||||
if event.is_action_pressed("grab_ball"):
|
||||
if ball_within_reach: grab_ball(current_ball)
|
||||
else: print_debug("%s can't grab the ball" % attributes.player_name)
|
||||
|
||||
if event is InputEventMouseButton and event.is_pressed() and event.button_index == 1:
|
||||
var click_position_global = get_global_mouse_position()
|
||||
print_debug("%s wants to navigate to %s" % [attributes.player_name, click_position_global])
|
||||
@ -57,7 +73,29 @@ func _input(event: InputEvent) -> void:
|
||||
var target_distance = player_nav.distance_to_target()
|
||||
print_debug("That's %s pixels/cm away" % target_distance)
|
||||
|
||||
## Setters
|
||||
|
||||
## -- ACTIONS -- ##
|
||||
func drop_ball(b: Ball) -> void:
|
||||
print_debug("%s will attempt to drop the ball" % attributes.player_name)
|
||||
#for hand in player_hands.get_children():
|
||||
#hand = hand as RemoteTransform2D
|
||||
#hand.remote_path = NodePath("")
|
||||
has_ball = false
|
||||
|
||||
func end_turn() -> void:
|
||||
print_debug("%s says: I'd like my turn to end." % attributes.player_name)
|
||||
is_active = false
|
||||
turn_finished.emit()
|
||||
|
||||
func grab_ball(b: Ball) -> void:
|
||||
print_debug("%s will attempt to grab the ball" % attributes.player_name)
|
||||
#if attributes.player_handedness == Globals.PlayerHandedness.LEFT:
|
||||
#player_left_hand.remote_path = player_left_hand.get_path_to(b)
|
||||
#else:
|
||||
#player_right_hand.remote_path = player_right_hand.get_path_to(b)
|
||||
has_ball = true
|
||||
|
||||
## -- SETTERS -- ##
|
||||
func set_active(active: bool) -> void:
|
||||
is_active = active
|
||||
if is_active:
|
||||
@ -65,55 +103,53 @@ func set_active(active: bool) -> void:
|
||||
player_camera.enabled = true
|
||||
player_camera.make_current()
|
||||
nav_target_sprite.visible = true
|
||||
player_nav.avoidance_priority = 0.0
|
||||
set_process_input(true)
|
||||
else:
|
||||
print_debug("%s says: 'It's not my turn'" % attributes.player_name)
|
||||
player_camera.enabled = false
|
||||
nav_target_sprite.visible = false
|
||||
player_nav.avoidance_priority = 0.5
|
||||
set_process_input(false)
|
||||
|
||||
## Actions
|
||||
func end_turn() -> void:
|
||||
print_debug("%s says: I'd like my turn to end." % attributes.player_name)
|
||||
is_active = false
|
||||
turn_finished.emit()
|
||||
|
||||
## Helper functions
|
||||
func set_desired_velocity(d_v: Vector2) -> void:
|
||||
desired_velocity = d_v
|
||||
player_nav.velocity = desired_velocity
|
||||
|
||||
func set_has_ball(h_b: bool) -> void:
|
||||
has_ball = h_b
|
||||
if has_ball: print_debug("%s has the ball" % attributes.player_name)
|
||||
else: print_debug("%s no longer as the ball" % attributes.player_name)
|
||||
|
||||
|
||||
## -- HELPERS -- ##
|
||||
func _apply_attributes() -> void:
|
||||
player_label.player_name = attributes.player_name
|
||||
player_label.player_number = attributes.player_number
|
||||
player_label.player_position = attributes.player_position
|
||||
player_sprite.texture = attributes.player_texture
|
||||
|
||||
func _connect_signals() -> void:
|
||||
player_nav.connect("velocity_computed", on_velocity_computed)
|
||||
player_reach_area.connect("body_entered", on_player_reach_area_body_entered)
|
||||
player_reach_area.connect("body_exited", on_player_reach_area_body_exited)
|
||||
|
||||
func _set_desired_velocity() -> void:
|
||||
var desired_velocity: Vector2 = global_position.direction_to(player_nav.get_next_path_position()) * attributes.speed
|
||||
player_nav.velocity = desired_velocity
|
||||
|
||||
func _set_player_label_position() -> void:
|
||||
player_label.global_position = global_position + player_label_offset
|
||||
|
||||
func _set_nav_sprite_position() -> void:
|
||||
nav_target_sprite.global_position = get_global_mouse_position()
|
||||
|
||||
func _set_player_label_values(attributes_resource: PlayerAttributes) -> void:
|
||||
player_label.player_name = attributes_resource.player_name
|
||||
player_label.player_number = attributes_resource.player_number
|
||||
player_label.player_position = attributes_resource.player_position
|
||||
|
||||
func _set_player_sprite(texture: Texture2D) -> void:
|
||||
player_sprite.texture = texture
|
||||
|
||||
## Signal handlers
|
||||
## -- RECEIVERS -- ##
|
||||
func on_player_reach_area_body_entered(body: PhysicsBody2D) -> void:
|
||||
if body is Player:
|
||||
print_debug((body.attributes.player_name) + " has entered %s's reach area" % attributes.player_name)
|
||||
elif body is Ball:
|
||||
print_debug("The ball has entered %s's reach area" % attributes.player_name)
|
||||
ball_within_reach = true
|
||||
current_ball = body
|
||||
|
||||
func on_player_reach_area_body_exited(body: PhysicsBody2D) -> void:
|
||||
if body is Player:
|
||||
print_debug((body.attributes.player_name) + " has exited %s's reach area" % attributes.player_name)
|
||||
elif body is Ball:
|
||||
print_debug("The ball has exited %s's reach area" % attributes.player_name)
|
||||
ball_within_reach = false
|
||||
|
||||
func on_velocity_computed(safe_velocity: Vector2) -> void:
|
||||
look_at(player_nav.get_next_path_position())
|
||||
|
||||
@ -3,7 +3,7 @@ extends Control
|
||||
|
||||
@export var player_name: String: set = set_player_name
|
||||
@export var player_number: int: set = set_player_number
|
||||
@export var player_position: Globals.PlayerPosition = Globals.PlayerPosition.Guard: set = set_player_position
|
||||
@export var player_position: Globals.PlayerPosition: set = set_player_position
|
||||
|
||||
@onready var name_label: Label = %NameLabel
|
||||
@onready var number_label: Label = %NumberLabel
|
||||
@ -16,4 +16,4 @@ func set_player_number(number: int) -> void:
|
||||
number_label.text = "#%s" % str(number)
|
||||
|
||||
func set_player_position(p_position: Globals.PlayerPosition) -> void:
|
||||
position_label.text = Globals.PlayerPosition.keys()[p_position]
|
||||
position_label.text = str(Globals.PlayerPosition.keys()[p_position]).to_pascal_case()
|
||||
|
||||
@ -19,6 +19,7 @@ script = ExtResource("5_bwj7y")
|
||||
player_texture = ExtResource("4_21h5f")
|
||||
player_name = "Stevie"
|
||||
player_number = 14
|
||||
player_handedness = 1
|
||||
speed = 250.0
|
||||
reflexes = 5.0
|
||||
metadata/_custom_type_script = "uid://bbey5ttwv5utd"
|
||||
@ -29,6 +30,7 @@ player_texture = ExtResource("6_21h5f")
|
||||
player_name = "Brendan"
|
||||
player_number = 9
|
||||
player_position = 1
|
||||
player_handedness = 1
|
||||
speed = 170.0
|
||||
reflexes = 3.0
|
||||
metadata/_custom_type_script = "uid://bbey5ttwv5utd"
|
||||
|
||||
@ -19,6 +19,7 @@ script = ExtResource("5_ssmnd")
|
||||
player_texture = ExtResource("4_dbbjc")
|
||||
player_name = "Dave"
|
||||
player_number = 11
|
||||
player_handedness = 1
|
||||
speed = 400.0
|
||||
reflexes = 5.0
|
||||
metadata/_custom_type_script = "uid://bbey5ttwv5utd"
|
||||
@ -29,6 +30,7 @@ player_texture = ExtResource("6_dbbjc")
|
||||
player_name = "Matt"
|
||||
player_number = 13
|
||||
player_position = 1
|
||||
player_handedness = 1
|
||||
speed = 150.0
|
||||
reflexes = 3.0
|
||||
metadata/_custom_type_script = "uid://bbey5ttwv5utd"
|
||||
@ -39,6 +41,7 @@ player_texture = ExtResource("7_ssmnd")
|
||||
player_name = "Orville"
|
||||
player_number = 33
|
||||
player_position = 2
|
||||
player_handedness = 1
|
||||
speed = 175.0
|
||||
reflexes = 4.0
|
||||
metadata/_custom_type_script = "uid://bbey5ttwv5utd"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user