generated from krampus/template-godot4
	Compare commits
	
		
			2 Commits
		
	
	
		
			7c9403273f
			...
			1c5222fecf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 1c5222fecf | |||
| 3a4326ca50 | 
							
								
								
									
										
											BIN
										
									
								
								asset_dev/balls/ball_icons.xcf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								asset_dev/balls/ball_icons.xcf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								assets/ui/ball_icons/basic_icon.png
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/ui/ball_icons/basic_icon.png
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										34
									
								
								assets/ui/ball_icons/basic_icon.png.import
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								assets/ui/ball_icons/basic_icon.png.import
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| [remap] | ||||
| 
 | ||||
| importer="texture" | ||||
| type="CompressedTexture2D" | ||||
| uid="uid://tancoet1lih5" | ||||
| path="res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.ctex" | ||||
| metadata={ | ||||
| "vram_texture": false | ||||
| } | ||||
| 
 | ||||
| [deps] | ||||
| 
 | ||||
| source_file="res://assets/ui/ball_icons/basic_icon.png" | ||||
| dest_files=["res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.ctex"] | ||||
| 
 | ||||
| [params] | ||||
| 
 | ||||
| compress/mode=0 | ||||
| compress/high_quality=false | ||||
| compress/lossy_quality=0.7 | ||||
| compress/hdr_compression=1 | ||||
| compress/normal_map=0 | ||||
| compress/channel_pack=0 | ||||
| mipmaps/generate=false | ||||
| mipmaps/limit=-1 | ||||
| roughness/mode=0 | ||||
| roughness/src_normal="" | ||||
| process/fix_alpha_border=true | ||||
| process/premult_alpha=false | ||||
| process/normal_map_invert_y=false | ||||
| process/hdr_as_srgb=false | ||||
| process/hdr_clamp_exposure=false | ||||
| process/size_limit=0 | ||||
| detect_3d/compress_to=1 | ||||
| @ -182,6 +182,16 @@ pause={ | ||||
| "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":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| ball_next={ | ||||
| "deadzone": 0.5, | ||||
| "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":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| ball_previous={ | ||||
| "deadzone": 0.5, | ||||
| "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| 
 | ||||
| [layer_names] | ||||
| 
 | ||||
|  | ||||
| @ -1,8 +1,16 @@ | ||||
| class_name GameBall extends RigidBody3D | ||||
| ## Base class for all gfolf balls | ||||
| 
 | ||||
| ## Fired as soon as this ball enters a water hazard | ||||
| signal entered_water | ||||
| 
 | ||||
| ## Types of game balls | ||||
| enum Type { | ||||
| 	NONE, | ||||
| 	BASIC, | ||||
| 	PLASMA, | ||||
| } | ||||
| 
 | ||||
| const TERRAIN_DAMPING_EPSILON := 1e-6 | ||||
| const IRON_DAMPING := 9999.0 | ||||
| 
 | ||||
| @ -89,6 +97,7 @@ func get_reoriented_basis() -> Basis: | ||||
| 
 | ||||
| 
 | ||||
| func _on_sleeping_state_changed() -> void: | ||||
| 	print("SLEEPING STATE: ", sleeping) | ||||
| 	if sleeping: | ||||
| 		# Trigger to reassign on wake | ||||
| 		_awake = false | ||||
|  | ||||
| @ -8,9 +8,9 @@ func _on_body_entered(_body: Node) -> void: | ||||
| 	print_debug("Plasma ball stuck to ", _body) | ||||
| 	# Freeze physics as soon as we hit something | ||||
| 	freeze = true | ||||
| 	sleeping = true | ||||
| 	manual_sleep_timer.start() | ||||
| 
 | ||||
| 
 | ||||
| func _fire_sleep_signal() -> void: | ||||
| 	sleeping = true | ||||
| 	sleeping_state_changed.emit() | ||||
|  | ||||
| @ -8,9 +8,14 @@ | ||||
| 
 | ||||
| [resource] | ||||
| script = ExtResource("4_8ybyj") | ||||
| name = "DEBUG Gfolfer" | ||||
| life = 100.0 | ||||
| name = "DEBUG Gfolfer" | ||||
| color = Color(1, 0.439216, 0.439216, 1) | ||||
| driver = ExtResource("1_sn8fd") | ||||
| iron = ExtResource("2_piku2") | ||||
| wedge = ExtResource("5_wm4ae") | ||||
| putter = ExtResource("3_tytwr") | ||||
| _balls = { | ||||
| 1: -1, | ||||
| 2: 5 | ||||
| } | ||||
|  | ||||
							
								
								
									
										42
									
								
								src/player/shot_setup/ball_point.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/player/shot_setup/ball_point.gd
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| class_name BallPoint extends Node3D | ||||
| ## Ball spawn point & origin. I.E. the "tee". | ||||
| 
 | ||||
| ## Emitted when a new ball is placed. | ||||
| signal ball_changed(ball: GameBall) | ||||
| 
 | ||||
| ## Scenes for each type of ball. | ||||
| const SCENE_MAP: Dictionary = { | ||||
| 	GameBall.Type.BASIC: preload("res://src/equipment/balls/physics_ball/physics_ball.tscn"), | ||||
| 	GameBall.Type.PLASMA: preload("res://src/equipment/balls/plasma_ball/plasma_ball.tscn"), | ||||
| } | ||||
| 
 | ||||
| @export var ball: GameBall: | ||||
| 	set(value): | ||||
| 		ball = value | ||||
| 		ball_changed.emit(ball) | ||||
| 
 | ||||
| 
 | ||||
| ## Get a new instance of a ball of the given type. | ||||
| ## Returns null if the type can't be instantiated (e.g. NONE type) | ||||
| func get_instance(type: GameBall.Type) -> GameBall: | ||||
| 	if type in SCENE_MAP: | ||||
| 		var scene: PackedScene = SCENE_MAP.get(type) | ||||
| 		return scene.instantiate() as GameBall | ||||
| 	return null | ||||
| 
 | ||||
| 
 | ||||
| ## Clear any existing ball, instantiate a new one of the given type, and place it at the ball point. | ||||
| func spawn_ball(type: GameBall.Type) -> void: | ||||
| 	# Clear existing ball | ||||
| 	if is_instance_valid(ball): | ||||
| 		ball.queue_free() | ||||
| 
 | ||||
| 	ball = get_instance(type) | ||||
| 	if is_instance_valid(ball): | ||||
| 		add_child(ball) | ||||
| 		snap() | ||||
| 
 | ||||
| 
 | ||||
| ## Snap the ball back to the ball point. | ||||
| func snap() -> void: | ||||
| 	ball.global_transform = global_transform | ||||
| @ -3,13 +3,12 @@ extends Area3D | ||||
| 
 | ||||
| signal ball_collision(ball: GameBall) | ||||
| 
 | ||||
| @export var ignored_balls: Array[GameBall] = [] | ||||
| 
 | ||||
| @onready var shot_setup: ShotSetup = $".." | ||||
| 
 | ||||
| 
 | ||||
| func _on_ball_entered(ball: GameBall) -> void: | ||||
| 	if not ball in ignored_balls: | ||||
| 	# TODO generalize this in the future if we have multiple players on teams | ||||
| 	if ball != shot_setup.game_ball: | ||||
| 		ball_collision.emit(ball) | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -41,6 +41,9 @@ const WATER_DAMAGE := 10.0 | ||||
| ## Initially-selected club | ||||
| @export var initial_club: Club.Type = Club.Type.DRIVER | ||||
| 
 | ||||
| ## Initially-selected ball type | ||||
| @export var initial_ball: GameBall.Type = GameBall.Type.BASIC | ||||
| 
 | ||||
| @export_category("Shot Parameters") | ||||
| @export var base_power := 2.5 | ||||
| @export var base_curve := 0.0 | ||||
| @ -86,6 +89,13 @@ var club: Club.Type: | ||||
| 			_on_club_change(value) | ||||
| 		club = value | ||||
| 
 | ||||
| var ball_type: GameBall.Type: | ||||
| 	set(value): | ||||
| 		if value != ball_type: | ||||
| 			hud.ball_selector.value = value | ||||
| 			ball_point.spawn_ball(value) | ||||
| 		ball_type = value | ||||
| 
 | ||||
| var shot_ref: Node3D | ||||
| 
 | ||||
| var shot_power: float: | ||||
| @ -100,6 +110,10 @@ var shot_curve: float: | ||||
| 	get: | ||||
| 		return hud.power_bar.value | ||||
| 
 | ||||
| var game_ball: GameBall: | ||||
| 	get: | ||||
| 		return ball_point.ball | ||||
| 
 | ||||
| var _free_camera: FreeCamera | ||||
| var _returning_free_camera := false | ||||
| var _restart_queued := false | ||||
| @ -123,9 +137,7 @@ var _tracking_camera: OrbitalCamera | ||||
| @onready var arrow_animation: AnimationPlayer = %ArrowAnimation | ||||
| @onready var shot_projection: ProjectileArc = %ShotProjection | ||||
| 
 | ||||
| @onready var ball_point: Node3D = %BallPoint | ||||
| # @onready var game_ball: GameBall = %PhysicsBall | ||||
| @onready var game_ball: GameBall = %PlasmaBall | ||||
| @onready var ball_point: BallPoint = %BallPoint | ||||
| 
 | ||||
| @onready var drive_ref: RayCast3D = %DriveRef | ||||
| @onready var drive_arrow: Node3D = %DriveArrow | ||||
| @ -138,8 +150,6 @@ var _tracking_camera: OrbitalCamera | ||||
| 
 | ||||
| @onready var ball_return_timer: Timer = %BallReturnTimer | ||||
| 
 | ||||
| @onready var ball_impulse_debug: Node3D = %BallImpulseDebug | ||||
| 
 | ||||
| @onready var camera_distance := zoom.position.z: | ||||
| 	set = _set_camera_distance | ||||
| 
 | ||||
| @ -155,6 +165,7 @@ func _ready() -> void: | ||||
| 	# Create & set up HUD | ||||
| 	hud = ShotHUD.create(player) | ||||
| 	world.ui.add_player_hud(hud) | ||||
| 	ball_type = initial_ball | ||||
| 	club = initial_club | ||||
| 
 | ||||
| 
 | ||||
| @ -223,16 +234,20 @@ func take_shot() -> void: | ||||
| 	var impulse := get_shot_impulse(shot_power) | ||||
| 	print_debug("Shot impulse: ", impulse, "; ", impulse.length(), " N*s") | ||||
| 
 | ||||
| 	ball_impulse_debug.transform = ( | ||||
| 		Transform3D.IDENTITY.scaled(Vector3.ONE * impulse.length()).looking_at(impulse) | ||||
| 	) | ||||
| 
 | ||||
| 	if game_ball: | ||||
| 		game_ball.freeze = false | ||||
| 		game_ball.apply_central_impulse(impulse) | ||||
| 
 | ||||
| 	# Use a ball if a limited type is selected | ||||
| 	if player.get_balls(ball_type) > 0: | ||||
| 		player.mutate_balls(ball_type, -1) | ||||
| 
 | ||||
| 
 | ||||
| ## Make the shot projection widget visible, with animated transition | ||||
| func _show_shot_projection() -> void: | ||||
| 	if not game_ball: | ||||
| 		return | ||||
| 
 | ||||
| 	shot_projection.initial_speed = 1 | ||||
| 	shot_projection.basis = shot_ref.basis.orthonormalized() | ||||
| 	var shot_speed := get_shot_impulse(1.0).length() / game_ball.mass | ||||
| @ -272,6 +287,9 @@ func return_free_cam() -> void: | ||||
| 
 | ||||
| 
 | ||||
| func return_ball() -> void: | ||||
| 	if not game_ball: | ||||
| 		return | ||||
| 
 | ||||
| 	game_ball.freeze = true | ||||
| 	var tween := get_tree().create_tween() | ||||
| 	( | ||||
| @ -288,6 +306,9 @@ func return_ball() -> void: | ||||
| 
 | ||||
| 
 | ||||
| func travel_to_ball() -> void: | ||||
| 	if not game_ball: | ||||
| 		return | ||||
| 
 | ||||
| 	game_ball.freeze = true | ||||
| 	global_position = game_ball.global_position | ||||
| 
 | ||||
| @ -296,12 +317,14 @@ func travel_to_ball() -> void: | ||||
| 	direction.rotation.y = 0 | ||||
| 	_target_rotation.y = 0 | ||||
| 	global_basis = game_ball.get_reoriented_basis() | ||||
| 	print_debug("REORIENTED BASIS: ", global_basis) | ||||
| 
 | ||||
| 	game_ball.global_transform = ball_point.global_transform | ||||
| 	ball_point.snap() | ||||
| 
 | ||||
| 
 | ||||
| func start_shot_track() -> void: | ||||
| 	if not game_ball: | ||||
| 		return | ||||
| 
 | ||||
| 	if phase == Phase.SHOT: | ||||
| 		_tracking_camera = OrbitalCamera.create(game_ball) | ||||
| 		_tracking_camera.rotation.y = randf_range(0.0, TAU) | ||||
| @ -331,6 +354,7 @@ func _on_club_change(new_club_type: Club.Type) -> void: | ||||
| 	wedge_arrow.hide() | ||||
| 	iron_arrow.hide() | ||||
| 	putt_arrow.hide() | ||||
| 	if game_ball: | ||||
| 		game_ball.iron_ball = false | ||||
| 	hud.club_selector.value = new_club_type | ||||
| 	# TODO club change animation | ||||
| @ -348,6 +372,7 @@ func _on_club_change(new_club_type: Club.Type) -> void: | ||||
| 		Club.Type.IRON: | ||||
| 			shot_ref = iron_ref | ||||
| 			iron_arrow.show() | ||||
| 			if game_ball: | ||||
| 				game_ball.iron_ball = true | ||||
| 		Club.Type.SPECIAL: | ||||
| 			# TODO figure this out | ||||
| @ -358,7 +383,6 @@ func _on_club_change(new_club_type: Club.Type) -> void: | ||||
| 
 | ||||
| ## Called immediately before `phase` is mutated. | ||||
| func _on_phase_change(new_phase: Phase) -> void: | ||||
| 	print_debug("Player ", player.name, ": change to ", Phase.keys()[new_phase]) | ||||
| 	match new_phase: | ||||
| 		Phase.AIM: | ||||
| 			hud.show_hud() | ||||
| @ -400,7 +424,18 @@ func _on_phase_change(new_phase: Phase) -> void: | ||||
| 			finished.emit(self) | ||||
| 
 | ||||
| 
 | ||||
| func _on_game_ball_changed(ball: GameBall) -> void: | ||||
| 	if ball: | ||||
| 		ball.iron_ball = (club == Club.Type.IRON) | ||||
| 		ball.entered_water.connect(_on_ball_entered_water) | ||||
| 		ball.sleeping_state_changed.connect(_on_ball_sleeping_state_changed) | ||||
| 
 | ||||
| 
 | ||||
| func _process(delta: float) -> void: | ||||
| 	# REMOVEME | ||||
| 	if Input.is_action_just_pressed("ui_menu"): | ||||
| 		print("Debugging...") | ||||
| 
 | ||||
| 	## Visual updates | ||||
| 	# Rotation | ||||
| 	direction.rotation.y = lerp_angle( | ||||
| @ -456,6 +491,12 @@ func _process(delta: float) -> void: | ||||
| 			if Input.is_action_just_pressed("select_putter"): | ||||
| 				club = Club.Type.PUTTER | ||||
| 
 | ||||
| 			# Ball select | ||||
| 			if Input.is_action_just_pressed("ball_next"): | ||||
| 				ball_type = player.next_ball(ball_type) | ||||
| 			if Input.is_action_just_pressed("ball_previous"): | ||||
| 				ball_type = player.prev_ball(ball_type) | ||||
| 
 | ||||
| 			# Switch to free cam | ||||
| 			if ( | ||||
| 				Input.is_action_just_pressed("camera_back") | ||||
| @ -467,7 +508,10 @@ func _process(delta: float) -> void: | ||||
| 
 | ||||
| 			# Advance to next phase | ||||
| 			if Input.is_action_just_pressed("shot_accept"): | ||||
| 				if player.get_balls(ball_type) != 0: | ||||
| 					# Check that player has enough of the selected ball (<0 means unlimited) | ||||
| 					phase = Phase.POWER_ADJUST | ||||
| 				# TODO play UI bonk if player doesn't have balls (lmao) | ||||
| 		Phase.POWER_ADJUST: | ||||
| 			if Input.is_action_just_pressed("shot_accept"): | ||||
| 				# TODO set power gauge parameters if needed | ||||
|  | ||||
| @ -1,22 +1,13 @@ | ||||
| [gd_scene load_steps=19 format=3 uid="uid://cy7t2tc4y3b4"] | ||||
| [gd_scene load_steps=17 format=3 uid="uid://cy7t2tc4y3b4"] | ||||
| 
 | ||||
| [ext_resource type="Script" path="res://src/player/shot_setup/shot_setup.gd" id="1_r6ei4"] | ||||
| [ext_resource type="Script" path="res://src/player/shot_setup/ball_point.gd" id="2_e6i3g"] | ||||
| [ext_resource type="PackedScene" uid="uid://c2k88ns0h5ie1" path="res://src/ui/3d/arrow/arrow.tscn" id="2_s70wl"] | ||||
| [ext_resource type="PackedScene" uid="uid://dcqxlbsrubapk" path="res://src/equipment/balls/plasma_ball/plasma_ball.tscn" id="3_8dte7"] | ||||
| [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) | ||||
| 
 | ||||
| [sub_resource type="CylinderMesh" id="CylinderMesh_ql2ui"] | ||||
| material = SubResource("StandardMaterial3D_lnol1") | ||||
| top_radius = 0.02 | ||||
| bottom_radius = 0.02 | ||||
| height = 1.0 | ||||
| 
 | ||||
| [sub_resource type="Animation" id="Animation_ug2a7"] | ||||
| length = 0.001 | ||||
| tracks/0/type = "value" | ||||
| @ -213,18 +204,7 @@ script = ExtResource("1_r6ei4") | ||||
| [node name="BallPoint" type="Node3D" parent="."] | ||||
| unique_name_in_owner = true | ||||
| transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.08, 0) | ||||
| 
 | ||||
| [node name="PlasmaBall" parent="BallPoint" instance=ExtResource("3_8dte7")] | ||||
| unique_name_in_owner = true | ||||
| 
 | ||||
| [node name="BallImpulseDebug" type="Node3D" parent="BallPoint"] | ||||
| unique_name_in_owner = true | ||||
| visible = false | ||||
| 
 | ||||
| [node name="MeshInstance3D" type="MeshInstance3D" parent="BallPoint/BallImpulseDebug"] | ||||
| transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, -0.5) | ||||
| mesh = SubResource("CylinderMesh_ql2ui") | ||||
| skeleton = NodePath("../..") | ||||
| script = ExtResource("2_e6i3g") | ||||
| 
 | ||||
| [node name="PlayerPivot" type="Node3D" parent="."] | ||||
| unique_name_in_owner = true | ||||
| @ -343,14 +323,13 @@ visible = false | ||||
| transform = Transform3D(0.2, 0, 0, 0, -1.74846e-08, 0.2, 0, -0.4, -8.74228e-09, 0, 0, -1) | ||||
| loop_animation = 1 | ||||
| 
 | ||||
| [node name="ShotProjection" parent="ArrowPivot" node_paths=PackedStringArray("excluded_bodies") instance=ExtResource("4_ry2ho")] | ||||
| [node name="ShotProjection" parent="ArrowPivot" instance=ExtResource("4_ry2ho")] | ||||
| unique_name_in_owner = true | ||||
| transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, -0.02, 0) | ||||
| visible = false | ||||
| initial_speed = 50.0 | ||||
| time_step = 0.01 | ||||
| max_steps = 800 | ||||
| excluded_bodies = [NodePath("../../BallPoint/PlasmaBall")] | ||||
| 
 | ||||
| [node name="ProjectedTarget" parent="ArrowPivot/ShotProjection" instance=ExtResource("6_mynqj")] | ||||
| 
 | ||||
| @ -365,15 +344,13 @@ libraries = { | ||||
| unique_name_in_owner = true | ||||
| one_shot = true | ||||
| 
 | ||||
| [node name="Hitbox" type="Area3D" parent="." node_paths=PackedStringArray("ignored_balls")] | ||||
| [node name="Hitbox" type="Area3D" parent="."] | ||||
| script = ExtResource("7_uh8kn") | ||||
| ignored_balls = [NodePath("../BallPoint/PlasmaBall")] | ||||
| 
 | ||||
| [node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"] | ||||
| shape = SubResource("SphereShape3D_xvvdi") | ||||
| 
 | ||||
| [connection signal="entered_water" from="BallPoint/PlasmaBall" to="." method="_on_ball_entered_water"] | ||||
| [connection signal="sleeping_state_changed" from="BallPoint/PlasmaBall" to="." method="_on_ball_sleeping_state_changed"] | ||||
| [connection signal="ball_changed" from="BallPoint" to="." method="_on_game_ball_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"] | ||||
|  | ||||
| @ -2,6 +2,7 @@ class_name WorldPlayer extends Resource | ||||
| ## Container for the state of the player within the world. | ||||
| 
 | ||||
| signal on_life_changed(new_value: float) | ||||
| signal on_balls_changed(type: GameBall.Type, new_value: int) | ||||
| 
 | ||||
| @export_range(0, 100) var life: float = 100.0: | ||||
| 	set(value): | ||||
| @ -21,6 +22,13 @@ signal on_life_changed(new_value: float) | ||||
| @export var putter: Club | ||||
| @export var special: Club | ||||
| 
 | ||||
| ## Count of each type of ball the player possesses. | ||||
| ## A count of less than zero indicates unlimited quantity. | ||||
| @export var _balls := { | ||||
| 	GameBall.Type.BASIC: -1, | ||||
| 	GameBall.Type.PLASMA: -1, | ||||
| } | ||||
| 
 | ||||
| # TODO balls, pickups, etc | ||||
| 
 | ||||
| var shot_setup: ShotSetup: | ||||
| @ -48,6 +56,39 @@ func get_club(type: Club.Type) -> Club: | ||||
| 	return null | ||||
| 
 | ||||
| 
 | ||||
| ## Get the quantity of a ball type | ||||
| func get_balls(type: GameBall.Type) -> int: | ||||
| 	return _balls.get(type, 0) | ||||
| 
 | ||||
| 
 | ||||
| ## Set the quantity of a ball type | ||||
| func set_balls(type: GameBall.Type, value: int) -> void: | ||||
| 	_balls[type] = value | ||||
| 	on_balls_changed.emit(type, value) | ||||
| 
 | ||||
| 
 | ||||
| ## Change the quantity of a ball type | ||||
| func mutate_balls(type: GameBall.Type, delta: int) -> void: | ||||
| 	_balls[type] = _balls.get(type, 0) + delta | ||||
| 	on_balls_changed.emit(type, _balls[type]) | ||||
| 
 | ||||
| 
 | ||||
| ## Get next slotted ball type | ||||
| func next_ball(type: GameBall.Type) -> GameBall.Type: | ||||
| 	var keys := _balls.keys() | ||||
| 	var i := keys.find(type) | ||||
| 	var j := (i + 1) % len(keys) if i >= 0 else 0 | ||||
| 	return keys[j] | ||||
| 
 | ||||
| 
 | ||||
| ## Get previous slotted ball type | ||||
| func prev_ball(type: GameBall.Type) -> GameBall.Type: | ||||
| 	var keys := _balls.keys() | ||||
| 	var i := keys.find(type) | ||||
| 	var j := (i - 1) % len(keys) if i >= 0 else 0 | ||||
| 	return keys[j] | ||||
| 
 | ||||
| 
 | ||||
| ## Create a debug player instance | ||||
| static func create_debug() -> WorldPlayer: | ||||
| 	var instance := WorldPlayer.new() | ||||
|  | ||||
| @ -28,6 +28,11 @@ PauseMenuButton/colors/font_outline_color = Color(0, 0, 0, 1) | ||||
| PauseMenuButton/constants/outline_size = 6 | ||||
| PauseMenuButton/font_sizes/font_size = 32 | ||||
| PauseMenuButton/fonts/font = ExtResource("2_5ty6u") | ||||
| QuantityLabel/base_type = &"Label" | ||||
| QuantityLabel/colors/font_color = Color(0.819608, 0.196078, 0.196078, 1) | ||||
| QuantityLabel/colors/font_outline_color = Color(1, 0.901961, 0.509804, 1) | ||||
| QuantityLabel/constants/outline_size = 6 | ||||
| QuantityLabel/font_sizes/font_size = 22 | ||||
| ShotFeedback/base_type = &"RichTextLabel" | ||||
| ShotFeedback/colors/font_shadow_color = Color(0, 0, 0, 1) | ||||
| ShotFeedback/constants/shadow_offset_x = 6 | ||||
|  | ||||
							
								
								
									
										51
									
								
								src/ui/shot_hud/ball_selector/ball_icon.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/ui/shot_hud/ball_selector/ball_icon.gd
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | ||||
| @tool | ||||
| class_name BallIcon extends Control | ||||
| ## HUD icon for a ball type | ||||
| 
 | ||||
| const BASE_MODULATE := Color.WHITE | ||||
| const EMPTY_MODULATE := Color.DIM_GRAY | ||||
| 
 | ||||
| @export var text: String: | ||||
| 	set(value): | ||||
| 		text = value | ||||
| 		if ball_label: | ||||
| 			ball_label.text = value | ||||
| 
 | ||||
| @export var quantity: int: | ||||
| 	set = _set_quantity | ||||
| @export var empty: bool: | ||||
| 	set(value): | ||||
| 		if value: | ||||
| 			quantity = 0 | ||||
| 		elif not quantity: | ||||
| 			quantity = 1 | ||||
| 	get: | ||||
| 		return quantity == 0 | ||||
| @export var unlimited: bool: | ||||
| 	set(value): | ||||
| 		quantity = -1 if value else 0 | ||||
| 	get: | ||||
| 		return quantity < 0 | ||||
| 
 | ||||
| @onready var ball_label: Label = %BallLabel | ||||
| @onready var quantity_container: HBoxContainer = %QuantityContainer | ||||
| @onready var quantity_label: Label = %QuantityLabel | ||||
| 
 | ||||
| 
 | ||||
| func _ready() -> void: | ||||
| 	text = text | ||||
| 	quantity = quantity | ||||
| 
 | ||||
| 
 | ||||
| func _set_quantity(value: int) -> void: | ||||
| 	# TODO play effect on gain/loss | ||||
| 	quantity = value | ||||
| 	if not quantity_label: | ||||
| 		return | ||||
| 	quantity_label.text = str(quantity) | ||||
| 
 | ||||
| 	# Quantity is not visible if we're empty or unlimited | ||||
| 	quantity_container.visible = quantity > 0 | ||||
| 
 | ||||
| 	# Grey out when empty | ||||
| 	ball_label.modulate = EMPTY_MODULATE if quantity == 0 else BASE_MODULATE | ||||
							
								
								
									
										68
									
								
								src/ui/shot_hud/ball_selector/ball_icon.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/ui/shot_hud/ball_selector/ball_icon.tscn
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,68 @@ | ||||
| [gd_scene load_steps=3 format=3 uid="uid://cc8a55ly7ybhy"] | ||||
| 
 | ||||
| [ext_resource type="Script" path="res://src/ui/shot_hud/ball_selector/ball_icon.gd" id="1_p0p8j"] | ||||
| [ext_resource type="FontFile" uid="uid://b6gxwgomstkgu" path="res://assets/fonts/Geo/Geo-Italic.ttf" id="2_bu42i"] | ||||
| 
 | ||||
| [node name="BallIcon" type="Control"] | ||||
| custom_minimum_size = Vector2(0, 27) | ||||
| layout_mode = 3 | ||||
| anchors_preset = 8 | ||||
| anchor_left = 0.5 | ||||
| anchor_top = 0.5 | ||||
| anchor_right = 0.5 | ||||
| anchor_bottom = 0.5 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| size_flags_horizontal = 4 | ||||
| script = ExtResource("1_p0p8j") | ||||
| quantity = -1 | ||||
| unlimited = true | ||||
| 
 | ||||
| [node name="BallLabel" type="Label" parent="."] | ||||
| unique_name_in_owner = true | ||||
| layout_mode = 1 | ||||
| anchors_preset = 8 | ||||
| anchor_left = 0.5 | ||||
| anchor_top = 0.5 | ||||
| anchor_right = 0.5 | ||||
| anchor_bottom = 0.5 | ||||
| offset_left = -46.5 | ||||
| offset_top = -13.5 | ||||
| offset_right = 46.5 | ||||
| offset_bottom = 13.5 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| theme_override_constants/outline_size = 10 | ||||
| theme_override_fonts/font = ExtResource("2_bu42i") | ||||
| theme_override_font_sizes/font_size = 25 | ||||
| horizontal_alignment = 2 | ||||
| 
 | ||||
| [node name="QuantityContainer" type="HBoxContainer" parent="BallLabel"] | ||||
| unique_name_in_owner = true | ||||
| visible = false | ||||
| layout_mode = 1 | ||||
| anchors_preset = -1 | ||||
| anchor_left = 1.0 | ||||
| anchor_top = 0.8 | ||||
| anchor_right = 1.0 | ||||
| anchor_bottom = 0.8 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| theme_override_constants/separation = 0 | ||||
| 
 | ||||
| [node name="Label" type="Label" parent="BallLabel/QuantityContainer"] | ||||
| layout_mode = 2 | ||||
| size_flags_horizontal = 8 | ||||
| size_flags_vertical = 8 | ||||
| theme_type_variation = &"QuantityLabel" | ||||
| theme_override_font_sizes/font_size = 22 | ||||
| text = "×" | ||||
| 
 | ||||
| [node name="QuantityLabel" type="Label" parent="BallLabel/QuantityContainer"] | ||||
| unique_name_in_owner = true | ||||
| layout_mode = 2 | ||||
| size_flags_horizontal = 8 | ||||
| size_flags_vertical = 8 | ||||
| theme_type_variation = &"QuantityLabel" | ||||
| theme_override_font_sizes/font_size = 22 | ||||
| text = "-1" | ||||
							
								
								
									
										54
									
								
								src/ui/shot_hud/ball_selector/ball_selector.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/ui/shot_hud/ball_selector/ball_selector.gd
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| @tool | ||||
| class_name BallSelector extends Control | ||||
| 
 | ||||
| const TWEEN_TIME := 0.2 | ||||
| 
 | ||||
| const Y_OFFSET := { | ||||
| 	GameBall.Type.NONE: 50, | ||||
| 	GameBall.Type.BASIC: 18, | ||||
| 	GameBall.Type.PLASMA: -14, | ||||
| } | ||||
| 
 | ||||
| @export var value: GameBall.Type: | ||||
| 	set = _set_value | ||||
| 
 | ||||
| @onready var ball_list: VBoxContainer = %BallList | ||||
| @onready var basic_icon: BallIcon = %BasicIcon | ||||
| @onready var plasma_icon: BallIcon = %PlasmaIcon | ||||
| 
 | ||||
| 
 | ||||
| func _ready() -> void: | ||||
| 	value = value | ||||
| 
 | ||||
| 
 | ||||
| ## Set ball quantities based on player's state | ||||
| func set_state_for_player(player: WorldPlayer) -> void: | ||||
| 	basic_icon.quantity = player.get_balls(GameBall.Type.BASIC) | ||||
| 	plasma_icon.quantity = player.get_balls(GameBall.Type.PLASMA) | ||||
| 	if player.shot_setup: | ||||
| 		value = player.shot_setup.ball_type | ||||
| 	player.on_balls_changed.connect(_set_quantity) | ||||
| 
 | ||||
| 
 | ||||
| func _get_icon(type: GameBall.Type) -> BallIcon: | ||||
| 	match type: | ||||
| 		GameBall.Type.BASIC: | ||||
| 			return basic_icon | ||||
| 		GameBall.Type.PLASMA: | ||||
| 			return plasma_icon | ||||
| 	return null | ||||
| 
 | ||||
| 
 | ||||
| func _set_value(new_value: GameBall.Type) -> void: | ||||
| 	if not ball_list: | ||||
| 		return | ||||
| 
 | ||||
| 	var tween := get_tree().create_tween() | ||||
| 	tween.tween_property(ball_list, "position:y", Y_OFFSET[new_value], TWEEN_TIME).set_trans( | ||||
| 		Tween.TRANS_EXPO | ||||
| 	) | ||||
| 	value = new_value | ||||
| 
 | ||||
| 
 | ||||
| func _set_quantity(type: GameBall.Type, new_value: int) -> void: | ||||
| 	_get_icon(type).quantity = new_value | ||||
							
								
								
									
										66
									
								
								src/ui/shot_hud/ball_selector/ball_selector.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/ui/shot_hud/ball_selector/ball_selector.tscn
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,66 @@ | ||||
| [gd_scene load_steps=5 format=3 uid="uid://b0yr0w0xv8cm5"] | ||||
| 
 | ||||
| [ext_resource type="PackedScene" uid="uid://cc8a55ly7ybhy" path="res://src/ui/shot_hud/ball_selector/ball_icon.tscn" id="1_1v8xg"] | ||||
| [ext_resource type="Script" path="res://src/ui/shot_hud/ball_selector/ball_selector.gd" id="1_b7gkp"] | ||||
| 
 | ||||
| [sub_resource type="Gradient" id="Gradient_3vqut"] | ||||
| interpolation_mode = 2 | ||||
| offsets = PackedFloat32Array(0, 0.382, 0.618, 1) | ||||
| colors = PackedColorArray(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0) | ||||
| 
 | ||||
| [sub_resource type="GradientTexture2D" id="GradientTexture2D_tm61r"] | ||||
| gradient = SubResource("Gradient_3vqut") | ||||
| fill_to = Vector2(0, 1) | ||||
| metadata/_snap_enabled = true | ||||
| 
 | ||||
| [node name="BallSelector" type="Control"] | ||||
| custom_minimum_size = Vector2(120, 27) | ||||
| layout_mode = 3 | ||||
| anchors_preset = 8 | ||||
| anchor_left = 0.5 | ||||
| anchor_top = 0.5 | ||||
| anchor_right = 0.5 | ||||
| anchor_bottom = 0.5 | ||||
| offset_left = -60.0 | ||||
| offset_top = -13.5 | ||||
| offset_right = 60.0 | ||||
| offset_bottom = 13.5 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| script = ExtResource("1_b7gkp") | ||||
| 
 | ||||
| [node name="GradientMask" type="TextureRect" parent="."] | ||||
| clip_children = 1 | ||||
| custom_minimum_size = Vector2(120, 32) | ||||
| layout_mode = 1 | ||||
| anchors_preset = 15 | ||||
| anchor_right = 1.0 | ||||
| anchor_bottom = 1.0 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| texture = SubResource("GradientTexture2D_tm61r") | ||||
| 
 | ||||
| [node name="BallList" type="VBoxContainer" parent="GradientMask"] | ||||
| unique_name_in_owner = true | ||||
| custom_minimum_size = Vector2(120, 0) | ||||
| layout_mode = 1 | ||||
| anchors_preset = 15 | ||||
| anchor_right = 1.0 | ||||
| anchor_bottom = 1.0 | ||||
| offset_top = 50.0 | ||||
| offset_bottom = 50.0 | ||||
| grow_horizontal = 2 | ||||
| grow_vertical = 2 | ||||
| theme_override_constants/separation = 5 | ||||
| 
 | ||||
| [node name="BasicIcon" parent="GradientMask/BallList" instance=ExtResource("1_1v8xg")] | ||||
| unique_name_in_owner = true | ||||
| custom_minimum_size = Vector2(120, 27) | ||||
| layout_mode = 2 | ||||
| text = "BASIC" | ||||
| 
 | ||||
| [node name="PlasmaIcon" parent="GradientMask/BallList" instance=ExtResource("1_1v8xg")] | ||||
| unique_name_in_owner = true | ||||
| custom_minimum_size = Vector2(120, 27) | ||||
| layout_mode = 2 | ||||
| text = "PLASMA" | ||||
| @ -13,6 +13,7 @@ var player: WorldPlayer | ||||
| @onready var life_bar: TextureProgressBar = %LifeBar | ||||
| 
 | ||||
| @onready var club_selector: ClubSelector = %ClubSelector | ||||
| @onready var ball_selector: BallSelector = %BallSelector | ||||
| 
 | ||||
| @onready var _curve_animation: AnimationPlayer = %CurveAnimation | ||||
| @onready var _power_animation: AnimationPlayer = %PowerAnimation | ||||
| @ -32,6 +33,7 @@ static var scene: PackedScene = preload("res://src/ui/shot_hud/shot_hud.tscn") | ||||
| 
 | ||||
| func _ready() -> void: | ||||
| 	club_selector.set_state_for_player(player) | ||||
| 	ball_selector.set_state_for_player(player) | ||||
| 	_player_name.text = player.name | ||||
| 	life_bar.value = player.life | ||||
| 	life_bar.tint_progress = player.color | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| [gd_scene load_steps=32 format=3 uid="uid://c4ifdiohng830"] | ||||
| [gd_scene load_steps=34 format=3 uid="uid://c4ifdiohng830"] | ||||
| 
 | ||||
| [ext_resource type="Script" path="res://src/ui/shot_hud/shot_hud.gd" id="1_x5b4c"] | ||||
| [ext_resource type="Shader" path="res://src/shaders/canvas_retro.gdshader" id="1_ybxxp"] | ||||
| @ -7,7 +7,9 @@ | ||||
| [ext_resource type="Texture2D" uid="uid://b5812y3pmmgg5" path="res://assets/ui/gauge_patch.png" id="4_5kcpe"] | ||||
| [ext_resource type="Texture2D" uid="uid://76fjx2ukavqe" path="res://assets/ui/power_gauge_fill.png" id="5_3i1yq"] | ||||
| [ext_resource type="Texture2D" uid="uid://4a8tvjgwegv3" path="res://assets/ui/power_gauge_tab.png" id="6_sw48q"] | ||||
| [ext_resource type="PackedScene" uid="uid://b0yr0w0xv8cm5" path="res://src/ui/shot_hud/ball_selector/ball_selector.tscn" id="8_b2302"] | ||||
| [ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="8_bejx4"] | ||||
| [ext_resource type="Texture2D" uid="uid://tancoet1lih5" path="res://assets/ui/ball_icons/basic_icon.png" id="8_tt8i3"] | ||||
| [ext_resource type="PackedScene" uid="uid://dmciuk3pbjsae" path="res://src/ui/shot_hud/life_bar/life_bar.tscn" id="9_w1fiw"] | ||||
| 
 | ||||
| [sub_resource type="Animation" id="Animation_3xds6"] | ||||
| @ -490,35 +492,6 @@ tracks/1/keys = { | ||||
| "values": [false] | ||||
| } | ||||
| 
 | ||||
| [sub_resource type="Animation" id="Animation_nicro"] | ||||
| resource_name = "show_life_bar" | ||||
| length = 0.4 | ||||
| step = 0.02 | ||||
| tracks/0/type = "value" | ||||
| tracks/0/imported = false | ||||
| tracks/0/enabled = true | ||||
| tracks/0/path = NodePath("SouthWest:position") | ||||
| tracks/0/interp = 2 | ||||
| tracks/0/loop_wrap = true | ||||
| tracks/0/keys = { | ||||
| "times": PackedFloat32Array(0, 0.34, 0.4), | ||||
| "transitions": PackedFloat32Array(1.618, 1.618, 1), | ||||
| "update": 0, | ||||
| "values": [Vector2(0, 1100), Vector2(0, 960), Vector2(0, 982)] | ||||
| } | ||||
| tracks/1/type = "value" | ||||
| tracks/1/imported = false | ||||
| tracks/1/enabled = true | ||||
| tracks/1/path = NodePath("SouthWest:visible") | ||||
| tracks/1/interp = 1 | ||||
| tracks/1/loop_wrap = true | ||||
| tracks/1/keys = { | ||||
| "times": PackedFloat32Array(0), | ||||
| "transitions": PackedFloat32Array(1), | ||||
| "update": 1, | ||||
| "values": [true] | ||||
| } | ||||
| 
 | ||||
| [sub_resource type="Animation" id="Animation_jugqx"] | ||||
| resource_name = "peek" | ||||
| length = 2.4 | ||||
| @ -548,6 +521,35 @@ tracks/1/keys = { | ||||
| "values": [true, false] | ||||
| } | ||||
| 
 | ||||
| [sub_resource type="Animation" id="Animation_nicro"] | ||||
| resource_name = "show_life_bar" | ||||
| length = 0.4 | ||||
| step = 0.02 | ||||
| tracks/0/type = "value" | ||||
| tracks/0/imported = false | ||||
| tracks/0/enabled = true | ||||
| tracks/0/path = NodePath("SouthWest:position") | ||||
| tracks/0/interp = 2 | ||||
| tracks/0/loop_wrap = true | ||||
| tracks/0/keys = { | ||||
| "times": PackedFloat32Array(0, 0.34, 0.4), | ||||
| "transitions": PackedFloat32Array(1.618, 1.618, 1), | ||||
| "update": 0, | ||||
| "values": [Vector2(0, 1100), Vector2(0, 960), Vector2(0, 982)] | ||||
| } | ||||
| tracks/1/type = "value" | ||||
| tracks/1/imported = false | ||||
| tracks/1/enabled = true | ||||
| tracks/1/path = NodePath("SouthWest:visible") | ||||
| tracks/1/interp = 1 | ||||
| tracks/1/loop_wrap = true | ||||
| tracks/1/keys = { | ||||
| "times": PackedFloat32Array(0), | ||||
| "transitions": PackedFloat32Array(1), | ||||
| "update": 1, | ||||
| "values": [true] | ||||
| } | ||||
| 
 | ||||
| [sub_resource type="AnimationLibrary" id="AnimationLibrary_c3i4w"] | ||||
| _data = { | ||||
| "RESET": SubResource("Animation_3cn2c"), | ||||
| @ -756,15 +758,30 @@ libraries = { | ||||
| "": SubResource("AnimationLibrary_5nauw") | ||||
| } | ||||
| 
 | ||||
| [node name="TextureRect" type="TextureRect" parent="ClubSelector"] | ||||
| texture_filter = 1 | ||||
| layout_mode = 0 | ||||
| offset_right = 128.0 | ||||
| offset_bottom = 128.0 | ||||
| texture = ExtResource("8_tt8i3") | ||||
| 
 | ||||
| [node name="BallSelector" parent="ClubSelector/TextureRect" instance=ExtResource("8_b2302")] | ||||
| unique_name_in_owner = true | ||||
| layout_mode = 1 | ||||
| anchors_preset = -1 | ||||
| anchor_left = 0.7 | ||||
| anchor_right = 0.7 | ||||
| offset_right = 108.0 | ||||
| grow_horizontal = 1 | ||||
| 
 | ||||
| [node name="SouthWest" type="MarginContainer" parent="."] | ||||
| layout_mode = 1 | ||||
| anchors_preset = -1 | ||||
| anchor_top = 1.0 | ||||
| anchor_right = 0.333 | ||||
| anchor_bottom = 1.0 | ||||
| offset_top = 20.0 | ||||
| offset_top = -98.0 | ||||
| offset_right = 40.0 | ||||
| offset_bottom = 118.0 | ||||
| grow_vertical = 0 | ||||
| theme_override_constants/margin_left = 16 | ||||
| theme_override_constants/margin_bottom = 16 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user