diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/game.gd | 36 | ||||
-rw-r--r-- | client/map/map.gd | 2 | ||||
-rw-r--r-- | client/player/follow_camera.gd | 2 |
3 files changed, 35 insertions, 5 deletions
diff --git a/client/game.gd b/client/game.gd index 06e3a934..8f23fbed 100644 --- a/client/game.gd +++ b/client/game.gd @@ -23,6 +23,11 @@ signal data_updated() signal joined() signal left() +enum SpectatingMode { + CENTER, + FREE, +} + var player_id: int = -1 var item_names: Array = [] var item_index_by_name: Dictionary = {} @@ -39,6 +44,8 @@ var last_position := Vector2(0, 0) var players := {} +var spectating_mode: SpectatingMode = SpectatingMode.CENTER + @onready var camera: FollowCamera = $FollowCamera @onready var mp: Multiplayer = $Multiplayer @onready var map: Map = $Map @@ -106,7 +113,7 @@ func _ready(): if player == player_id: last_position = pos ) - + mp.movement_sync.connect(func(): if not players.has(player_id): return @@ -228,7 +235,7 @@ func _ready(): map.gi_bake() await get_parent()._menu_open() map.autobake = true - + if in_lobby_: popup_message.lobby() else: @@ -253,7 +260,7 @@ func _ready(): if lobby_state and not join_sent: join() ) - + mp.environment.connect($Environment.update) func join(): @@ -287,6 +294,17 @@ func set_tile(tile: Vector2i, kind = null, neighbors = null): func update_center(): if is_joined: return + if Input.get_vector("left", "right", "forward", "backwards").normalized().length() > .1: + spectating_mode = SpectatingMode.FREE + elif spectating_mode == SpectatingMode.FREE and Input.is_action_just_pressed("reset"): + spectating_mode = SpectatingMode.CENTER + match spectating_mode: + SpectatingMode.CENTER: + spectate_center() + SpectatingMode.FREE: + spectate_free() + +func spectate_center(): var sum: int = 0 var player_sum: int = 0 var center: Vector3 = Vector3(0., 0., 0.) @@ -309,3 +327,15 @@ func update_center(): var map_center = ((extents[0] + extents[1]) / 2) + Vector2(.5, .5) new_center = Vector3(map_center.x, 0., map_center.y) $Center.position = new_center + +func spectate_free(): + var direction := Input.get_vector("left", "right", "forward", "backwards") + direction = direction.rotated(-camera.angle_target) + $Center.position += Vector3( + direction.x, + $Center.position.y, + direction.y + ) * get_process_delta_time() * 10. + var extents = map.extents() + $Center.position.x = clamp($Center.position.x, extents[0].x, extents[1].x) + $Center.position.z = clamp($Center.position.z, extents[0].y, extents[1].y) diff --git a/client/map/map.gd b/client/map/map.gd index 112ddbcc..7be1a102 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -81,7 +81,7 @@ func gi_bake_blocking(): voxelgi.visible = true print("Bake done. elapsed=", Time.get_ticks_msec() - start) -func extents() -> Array: +func extents() -> Array[Vector2]: var extent_min = Vector2(0,0) var extent_max = Vector2(0,0) for e in tile_by_pos.values(): diff --git a/client/player/follow_camera.gd b/client/player/follow_camera.gd index fd4c9d16..4df4b1eb 100644 --- a/client/player/follow_camera.gd +++ b/client/player/follow_camera.gd @@ -24,7 +24,7 @@ const ROTATE_WEIGHT: float = 8.0 const ROTATE_UP_SPEED: float = 0.7 const ROTATE_UP_WEIGHT: float = 4.0 const ANGLE_UP_MIN: float = 0.5 -const ANGLE_UP_MAX: float = 1.2 +const ANGLE_UP_MAX: float = 0.4999 * PI const LOOK_WEIGHT: float = 8.0 const MOVE_WEIGHT: float = 2.0 const ZOOM_SPEED: float = 1.0 |