change dictionaries to inner classes in main_camera and cursor

This commit is contained in:
Teatov 2025-03-03 14:06:41 +10:00
parent a782d1e820
commit 0835f66ac4
6 changed files with 40 additions and 25 deletions

View File

@ -9,6 +9,8 @@ process_priority = 1000
process_physics_priority = 1000
layer = 128
script = ExtResource("1_tkygf")
side_change_speed = null
screen_inset = null
[node name="CursorBase" type="Control" parent="."]
layout_mode = 3

View File

@ -1,5 +1,4 @@
class_name DebugCollisionShapes
extends RefCounted
const MARGIN = 0.01

View File

@ -33,12 +33,11 @@ func _handle_cursors(delta: float) -> void:
func _init_player_cursor(id: int) -> void:
var cursor_node: Control = _cursor_scene.instantiate() as Control
add_child(cursor_node)
_cursors[id] = {
"base": cursor_node,
"bat": cursor_node.get_node("CursorBat"),
"arrow": cursor_node.get_node("CursorArrow"),
"side": 0
}
_cursors[id] = PlayerCursor.new(
cursor_node,
cursor_node.get_node("CursorBat") as Control,
cursor_node.get_node("CursorArrow") as Control
)
func _handle_cursor(player_index: int, delta: float) -> void:
@ -58,15 +57,15 @@ func _handle_cursor(player_index: int, delta: float) -> void:
clamp_corner_min += Vector2(screen_inset, screen_inset)
clamp_corner_max -= Vector2(screen_inset, screen_inset)
var cursor: Dictionary = _cursors[id]
var cursor: PlayerCursor = _cursors[id]
cursor["base"].position = (
cursor.base.position = (
cursor_pos_screen.clamp(clamp_corner_min, clamp_corner_max)
- cursor["base"].size / 2
- cursor.base.size / 2
)
cursor["side"] = lerpf(
cursor["side"] as float,
cursor.side = lerpf(
cursor.side as float,
(PI / 2.0) * (1.0 if player.attack.side == PlayerAttack.Side.LEFT else -1.0),
side_change_speed * delta
)
@ -75,14 +74,26 @@ func _handle_cursor(player_index: int, delta: float) -> void:
var bat_rotation_point_screen := Referencer.main_camera.unproject_position(
(
cursor_pos_world
+ aim_offset_normalized.rotated(Vector3.UP, cursor["side"] as float)
+ aim_offset_normalized.rotated(Vector3.UP, cursor.side as float)
)
)
var arrow_rotation_point_screen := Referencer.main_camera.unproject_position(
cursor_pos_world + aim_offset_normalized
)
cursor["bat"].rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
cursor["arrow"].rotation = cursor_pos_screen.angle_to_point(
cursor.bat.rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
cursor.arrow.rotation = cursor_pos_screen.angle_to_point(
arrow_rotation_point_screen
)
class PlayerCursor:
var base: Control
var bat: Control
var arrow: Control
var side: float = 0
func _init(_base: Control, _bat: Control, _arrow: Control) -> void:
base = _base
bat = _bat
arrow = _arrow

View File

@ -30,33 +30,33 @@ func _process(delta: float) -> void:
func _follow(player: Player, delta: float) -> Vector3:
var id := player.get_instance_id()
if not _player_offsets.has(id):
_player_offsets[id] = {"floor_height": 0, "aim_offset": Vector3.ZERO}
_player_offsets[id] = PlayerOffset.new()
var player_offset: Dictionary = _player_offsets[id]
var player_offset: PlayerOffset = _player_offsets[id]
var player_position := player.global_position
if player.is_on_floor():
player_offset["floor_height"] = player_position.y
player_position.y = player_offset["floor_height"] + Projectile.HEIGHT
player_offset.floor_height = player_position.y
player_position.y = player_offset.floor_height + Projectile.HEIGHT
if Referencer.players_count > 1:
player_offset["aim_offset"] = Vector3.ZERO
player_offset.aim_offset = Vector3.ZERO
elif player.input_mode_is(Inputer.Mode.KB_MOUSE):
player_offset["aim_offset"] = player.aiming.aim_offset
player_offset.aim_offset = player.aiming.aim_offset
elif player.input_mode_is(Inputer.Mode.CONTROLLER):
var new_aim_offset := (
Vector3.ZERO
if player.aiming.aim_input.length() == 0
else player.aiming.aim_offset
)
player_offset["aim_offset"] = player_offset["aim_offset"].lerp(
player_offset.aim_offset = player_offset.aim_offset.lerp(
new_aim_offset, _aim_damping * delta
)
var follow_position := (
player_position
+ (
player_offset["aim_offset"] as Vector3
player_offset.aim_offset as Vector3
* (
_aim_offset_factor_mouse
if player.input_mode_is(Inputer.Mode.KB_MOUSE)
@ -68,3 +68,8 @@ func _follow(player: Player, delta: float) -> Vector3:
Debugger.circle("follow_position" + str(player.name), follow_position)
return follow_position
class PlayerOffset:
var floor_height: float = 0
var aim_offset: Vector3 = Vector3.ZERO

View File

@ -1,5 +1,4 @@
class_name PlayerAiming
extends RefCounted
@export var _controller_aim_offset: float = 6
@export var _vertical_aim_aspect: float = 1.5

View File

@ -1,5 +1,4 @@
class_name PlayerMovement
extends RefCounted
@export var _move_speed: float = 8
@export var _move_acceleration: float = 100