change dictionaries to inner classes in main_camera and cursor
This commit is contained in:
parent
a782d1e820
commit
0835f66ac4
@ -9,6 +9,8 @@ process_priority = 1000
|
|||||||
process_physics_priority = 1000
|
process_physics_priority = 1000
|
||||||
layer = 128
|
layer = 128
|
||||||
script = ExtResource("1_tkygf")
|
script = ExtResource("1_tkygf")
|
||||||
|
side_change_speed = null
|
||||||
|
screen_inset = null
|
||||||
|
|
||||||
[node name="CursorBase" type="Control" parent="."]
|
[node name="CursorBase" type="Control" parent="."]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
class_name DebugCollisionShapes
|
class_name DebugCollisionShapes
|
||||||
extends RefCounted
|
|
||||||
|
|
||||||
const MARGIN = 0.01
|
const MARGIN = 0.01
|
||||||
|
|
||||||
|
|||||||
@ -33,12 +33,11 @@ func _handle_cursors(delta: float) -> void:
|
|||||||
func _init_player_cursor(id: int) -> void:
|
func _init_player_cursor(id: int) -> void:
|
||||||
var cursor_node: Control = _cursor_scene.instantiate() as Control
|
var cursor_node: Control = _cursor_scene.instantiate() as Control
|
||||||
add_child(cursor_node)
|
add_child(cursor_node)
|
||||||
_cursors[id] = {
|
_cursors[id] = PlayerCursor.new(
|
||||||
"base": cursor_node,
|
cursor_node,
|
||||||
"bat": cursor_node.get_node("CursorBat"),
|
cursor_node.get_node("CursorBat") as Control,
|
||||||
"arrow": cursor_node.get_node("CursorArrow"),
|
cursor_node.get_node("CursorArrow") as Control
|
||||||
"side": 0
|
)
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func _handle_cursor(player_index: int, delta: float) -> void:
|
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_min += Vector2(screen_inset, screen_inset)
|
||||||
clamp_corner_max -= 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_pos_screen.clamp(clamp_corner_min, clamp_corner_max)
|
||||||
- cursor["base"].size / 2
|
- cursor.base.size / 2
|
||||||
)
|
)
|
||||||
|
|
||||||
cursor["side"] = lerpf(
|
cursor.side = lerpf(
|
||||||
cursor["side"] as float,
|
cursor.side as float,
|
||||||
(PI / 2.0) * (1.0 if player.attack.side == PlayerAttack.Side.LEFT else -1.0),
|
(PI / 2.0) * (1.0 if player.attack.side == PlayerAttack.Side.LEFT else -1.0),
|
||||||
side_change_speed * delta
|
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(
|
var bat_rotation_point_screen := Referencer.main_camera.unproject_position(
|
||||||
(
|
(
|
||||||
cursor_pos_world
|
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(
|
var arrow_rotation_point_screen := Referencer.main_camera.unproject_position(
|
||||||
cursor_pos_world + aim_offset_normalized
|
cursor_pos_world + aim_offset_normalized
|
||||||
)
|
)
|
||||||
|
|
||||||
cursor["bat"].rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
|
cursor.bat.rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
|
||||||
cursor["arrow"].rotation = cursor_pos_screen.angle_to_point(
|
cursor.arrow.rotation = cursor_pos_screen.angle_to_point(
|
||||||
arrow_rotation_point_screen
|
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
|
||||||
|
|||||||
@ -30,33 +30,33 @@ func _process(delta: float) -> void:
|
|||||||
func _follow(player: Player, delta: float) -> Vector3:
|
func _follow(player: Player, delta: float) -> Vector3:
|
||||||
var id := player.get_instance_id()
|
var id := player.get_instance_id()
|
||||||
if not _player_offsets.has(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
|
var player_position := player.global_position
|
||||||
if player.is_on_floor():
|
if player.is_on_floor():
|
||||||
player_offset["floor_height"] = player_position.y
|
player_offset.floor_height = player_position.y
|
||||||
player_position.y = player_offset["floor_height"] + Projectile.HEIGHT
|
player_position.y = player_offset.floor_height + Projectile.HEIGHT
|
||||||
|
|
||||||
if Referencer.players_count > 1:
|
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):
|
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):
|
elif player.input_mode_is(Inputer.Mode.CONTROLLER):
|
||||||
var new_aim_offset := (
|
var new_aim_offset := (
|
||||||
Vector3.ZERO
|
Vector3.ZERO
|
||||||
if player.aiming.aim_input.length() == 0
|
if player.aiming.aim_input.length() == 0
|
||||||
else player.aiming.aim_offset
|
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
|
new_aim_offset, _aim_damping * delta
|
||||||
)
|
)
|
||||||
|
|
||||||
var follow_position := (
|
var follow_position := (
|
||||||
player_position
|
player_position
|
||||||
+ (
|
+ (
|
||||||
player_offset["aim_offset"] as Vector3
|
player_offset.aim_offset as Vector3
|
||||||
* (
|
* (
|
||||||
_aim_offset_factor_mouse
|
_aim_offset_factor_mouse
|
||||||
if player.input_mode_is(Inputer.Mode.KB_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)
|
Debugger.circle("follow_position" + str(player.name), follow_position)
|
||||||
|
|
||||||
return follow_position
|
return follow_position
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerOffset:
|
||||||
|
var floor_height: float = 0
|
||||||
|
var aim_offset: Vector3 = Vector3.ZERO
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
class_name PlayerAiming
|
class_name PlayerAiming
|
||||||
extends RefCounted
|
|
||||||
|
|
||||||
@export var _controller_aim_offset: float = 6
|
@export var _controller_aim_offset: float = 6
|
||||||
@export var _vertical_aim_aspect: float = 1.5
|
@export var _vertical_aim_aspect: float = 1.5
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
class_name PlayerMovement
|
class_name PlayerMovement
|
||||||
extends RefCounted
|
|
||||||
|
|
||||||
@export var _move_speed: float = 8
|
@export var _move_speed: float = 8
|
||||||
@export var _move_acceleration: float = 100
|
@export var _move_acceleration: float = 100
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user