prefix private variables with _
This commit is contained in:
parent
2e1878b1fe
commit
13ddbc8bd3
@ -3,12 +3,12 @@ extends AudioStreamPlayer
|
||||
const ZOOMED_IN_CUTOFF = 10000
|
||||
const ZOOMED_OUT_CUTOFF = 0
|
||||
|
||||
var audio_1 := preload("res://assets/audio/ambient/ambient_1.ogg")
|
||||
var audio_2 := preload("res://assets/audio/ambient/ambient_2.ogg")
|
||||
var audio_3 := preload("res://assets/audio/ambient/ambient_3.ogg")
|
||||
var _audio_1 := preload("res://assets/audio/ambient/ambient_1.ogg")
|
||||
var _audio_2 := preload("res://assets/audio/ambient/ambient_2.ogg")
|
||||
var _audio_3 := preload("res://assets/audio/ambient/ambient_3.ogg")
|
||||
|
||||
var streams: Array[AudioStream] = [audio_1, audio_2, audio_3]
|
||||
var filter: AudioEffectHighPassFilter
|
||||
var _streams: Array[AudioStream] = [_audio_1, _audio_2, _audio_3]
|
||||
var _filter: AudioEffectHighPassFilter
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -16,15 +16,15 @@ func _ready() -> void:
|
||||
for effect_idx in AudioServer.get_bus_effect_count(bus_idx):
|
||||
var effect := AudioServer.get_bus_effect(bus_idx, effect_idx)
|
||||
if effect is AudioEffectHighPassFilter:
|
||||
filter = effect
|
||||
assert(filter != null, "filter missing!")
|
||||
_filter = effect
|
||||
assert(_filter != null, "_filter missing!")
|
||||
|
||||
stream = streams.pick_random()
|
||||
stream = _streams.pick_random()
|
||||
play()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
filter.cutoff_hz = lerpf(
|
||||
_filter.cutoff_hz = lerpf(
|
||||
ZOOMED_IN_CUTOFF,
|
||||
ZOOMED_OUT_CUTOFF,
|
||||
StaticNodesManager.main_camera.zoom_value,
|
||||
|
||||
@ -7,8 +7,8 @@ const DEFAULT_MAX_HONEYDEW: int = 120
|
||||
var honeydew: int = 0
|
||||
var max_honeydew: int = DEFAULT_MAX_HONEYDEW
|
||||
|
||||
var ant_nitwit := preload("res://scenes/units/ant_nitwit.tscn")
|
||||
var ant_gatherer := preload("res://scenes/units/ant_gatherer.tscn")
|
||||
var _nitwit_scene := preload("res://scenes/units/ant_nitwit.tscn")
|
||||
var _gatherer_scene := preload("res://scenes/units/ant_gatherer.tscn")
|
||||
|
||||
@onready var ui_origin: Node3D = $UiOrigin
|
||||
@onready var audio_player: SoundEffectsPlayer = (
|
||||
@ -42,7 +42,7 @@ func deposit_honeydew(amount: int) -> int:
|
||||
|
||||
func spawn_nitwit(ding: bool = true) -> void:
|
||||
print('spawn!')
|
||||
var new_unit := _create_unit(ant_nitwit, AntNitwit.get_cost(), ding)
|
||||
var new_unit := _create_unit(_nitwit_scene, AntNitwit.get_cost(), ding)
|
||||
if new_unit == null:
|
||||
return
|
||||
print('add!')
|
||||
@ -50,7 +50,7 @@ func spawn_nitwit(ding: bool = true) -> void:
|
||||
|
||||
|
||||
func spawn_gatherer() -> void:
|
||||
var new_unit := _create_unit(ant_gatherer, AntGatherer.get_cost())
|
||||
var new_unit := _create_unit(_gatherer_scene, AntGatherer.get_cost())
|
||||
if new_unit == null:
|
||||
return
|
||||
StaticNodesManager.gatherers_holder.add_child(new_unit)
|
||||
|
||||
@ -7,14 +7,14 @@ enum WhatToSpawn {
|
||||
HONEYDEW,
|
||||
}
|
||||
|
||||
@export var what: WhatToSpawn = WhatToSpawn.APHID
|
||||
@export var amount: int = 5
|
||||
@export var _what: WhatToSpawn = WhatToSpawn.APHID
|
||||
@export var _amount: int = 5
|
||||
|
||||
var aphid := preload("res://scenes/units/aphid.tscn")
|
||||
var honeydew := preload("res://scenes/items/honeydew.tscn")
|
||||
var _aphid_scene := preload("res://scenes/units/aphid.tscn")
|
||||
var _honeydew_scene := preload("res://scenes/items/honeydew.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
for i in amount:
|
||||
for i in _amount:
|
||||
var pos_offset := Vector3(
|
||||
randf_range(-gizmo_extents, gizmo_extents),
|
||||
0,
|
||||
@ -23,12 +23,12 @@ func _ready() -> void:
|
||||
|
||||
var scene: PackedScene
|
||||
var holder: Node
|
||||
match what:
|
||||
match _what:
|
||||
WhatToSpawn.APHID:
|
||||
scene = aphid
|
||||
scene = _aphid_scene
|
||||
holder = StaticNodesManager.aphids_holder
|
||||
WhatToSpawn.HONEYDEW:
|
||||
scene = honeydew
|
||||
scene = _honeydew_scene
|
||||
holder = StaticNodesManager.honeydew_holder
|
||||
|
||||
_spawn(
|
||||
|
||||
@ -3,11 +3,12 @@ extends Node
|
||||
|
||||
const CURSOR_HOTSPOT = Vector2(32, 32)
|
||||
|
||||
var cursor_normal := load("res://assets/textures/gui/cursor.png")
|
||||
var cursor_click := load("res://assets/textures/gui/cursor_click.png")
|
||||
|
||||
var disable_confinement: bool = false
|
||||
|
||||
var _cursor_normal := load("res://assets/textures/gui/cursor.png")
|
||||
var _cursor_click := load("res://assets/textures/gui/cursor_click.png")
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
|
||||
@ -24,9 +25,9 @@ func _input(event: InputEvent) -> void:
|
||||
or button_event.button_index == MOUSE_BUTTON_RIGHT
|
||||
):
|
||||
if button_event.pressed:
|
||||
_set_cursor(cursor_click)
|
||||
_set_cursor(_cursor_click)
|
||||
else:
|
||||
_set_cursor(cursor_normal)
|
||||
_set_cursor(_cursor_normal)
|
||||
|
||||
if event.is_action_pressed("toggle_confinement"):
|
||||
disable_confinement = not disable_confinement
|
||||
@ -35,7 +36,7 @@ func _input(event: InputEvent) -> void:
|
||||
Input.set_custom_mouse_cursor(null)
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
|
||||
_set_cursor(cursor_normal)
|
||||
_set_cursor(_cursor_normal)
|
||||
|
||||
|
||||
func _set_cursor(image: Resource) -> void:
|
||||
|
||||
@ -8,32 +8,32 @@ const DEFAULT_COLOR: Color = Color.RED
|
||||
|
||||
var enabled: bool = false
|
||||
|
||||
var control: Control = Control.new()
|
||||
var label: RichTextLabel = RichTextLabel.new()
|
||||
var _control: Control = Control.new()
|
||||
var _label: RichTextLabel = RichTextLabel.new()
|
||||
|
||||
var vectors_to_draw: Array[Dictionary] = []
|
||||
var markers_to_draw: Array[Dictionary] = []
|
||||
var circles_to_draw: Array[Dictionary] = []
|
||||
var text_to_draw: PackedStringArray = []
|
||||
var _vectors_to_draw: Array[Dictionary] = []
|
||||
var _markers_to_draw: Array[Dictionary] = []
|
||||
var _circles_to_draw: Array[Dictionary] = []
|
||||
var _text_to_draw: PackedStringArray = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
layer = 999
|
||||
enabled = false
|
||||
control.draw.connect(_on_control_draw)
|
||||
control.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(control)
|
||||
_control.draw.connect(_on_control_draw)
|
||||
_control.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_control)
|
||||
|
||||
label.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(label)
|
||||
_label.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_label)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not enabled:
|
||||
return
|
||||
control.queue_redraw()
|
||||
_control.queue_redraw()
|
||||
|
||||
text('fps: ' + str(Performance.get_monitor(Performance.TIME_FPS)))
|
||||
text('draw calls: ' + str(Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME)))
|
||||
@ -45,21 +45,21 @@ func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("toggle_debug"):
|
||||
enabled = not enabled
|
||||
visible = enabled
|
||||
vectors_to_draw.clear()
|
||||
_vectors_to_draw.clear()
|
||||
|
||||
|
||||
func text(body: String) -> void:
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
text_to_draw.append(body)
|
||||
_text_to_draw.append(body)
|
||||
|
||||
|
||||
func vector(from: Vector3, to: Vector3, color: Color = DEFAULT_COLOR) -> void:
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
vectors_to_draw.append({"from": from, "to": to, "color": color})
|
||||
_vectors_to_draw.append({"from": from, "to": to, "color": color})
|
||||
|
||||
|
||||
func marker(
|
||||
@ -70,14 +70,14 @@ func marker(
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
markers_to_draw.append({"pos": pos, "radius": radius, "color": color})
|
||||
_markers_to_draw.append({"pos": pos, "radius": radius, "color": color})
|
||||
|
||||
|
||||
func circle(pos: Vector3, color: Color = DEFAULT_COLOR) -> void:
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
circles_to_draw.append({"pos": pos, "color": color})
|
||||
_circles_to_draw.append({"pos": pos, "color": color})
|
||||
|
||||
|
||||
func _unproject(pos: Vector3) -> Vector2:
|
||||
@ -85,13 +85,13 @@ func _unproject(pos: Vector3) -> Vector2:
|
||||
|
||||
|
||||
func _draw_text() -> void:
|
||||
label.text = '\n'.join(text_to_draw)
|
||||
_label.text = '\n'.join(_text_to_draw)
|
||||
|
||||
|
||||
func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
|
||||
var start := _unproject(from)
|
||||
var end := _unproject(to)
|
||||
control.draw_line(start, end, color, LINE_WIDTH)
|
||||
_control.draw_line(start, end, color, LINE_WIDTH)
|
||||
_draw_triangle(end, start.direction_to(end), 5, color)
|
||||
|
||||
|
||||
@ -105,51 +105,51 @@ func _draw_triangle(
|
||||
var b := pos + dir.rotated(2 * PI / 3) * size
|
||||
var c := pos + dir.rotated(4 * PI / 3) * size
|
||||
var points := PackedVector2Array([a, b, c])
|
||||
control.draw_polygon(points, PackedColorArray([color]))
|
||||
_control.draw_polygon(points, PackedColorArray([color]))
|
||||
|
||||
|
||||
func _draw_marker(pos: Vector3, radius: float, color: Color) -> void:
|
||||
var x_start := _unproject(pos + (Vector3.LEFT * radius))
|
||||
var x_end := _unproject(pos + (Vector3.RIGHT * radius))
|
||||
control.draw_line(x_start, x_end, color, LINE_WIDTH)
|
||||
_control.draw_line(x_start, x_end, color, LINE_WIDTH)
|
||||
|
||||
var y_start := _unproject(pos + (Vector3.UP * radius))
|
||||
var y_end := _unproject(pos + (Vector3.DOWN * radius))
|
||||
control.draw_line(y_start, y_end, color, LINE_WIDTH)
|
||||
_control.draw_line(y_start, y_end, color, LINE_WIDTH)
|
||||
|
||||
var z_start := _unproject(pos + (Vector3.FORWARD * radius))
|
||||
var z_end := _unproject(pos + (Vector3.BACK * radius))
|
||||
control.draw_line(z_start, z_end, color, LINE_WIDTH)
|
||||
_control.draw_line(z_start, z_end, color, LINE_WIDTH)
|
||||
|
||||
|
||||
func _draw_circle(pos: Vector3, color: Color) -> void:
|
||||
var point := _unproject(pos)
|
||||
control.draw_circle(point, CIRCLE_RADIUS, color)
|
||||
_control.draw_circle(point, CIRCLE_RADIUS, color)
|
||||
|
||||
|
||||
func _on_control_draw() -> void:
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
for v in vectors_to_draw:
|
||||
for v in _vectors_to_draw:
|
||||
_draw_vector(
|
||||
v["from"] as Vector3,
|
||||
v["to"] as Vector3,
|
||||
v["color"] as Color,
|
||||
)
|
||||
vectors_to_draw.clear()
|
||||
_vectors_to_draw.clear()
|
||||
|
||||
for v in markers_to_draw:
|
||||
for v in _markers_to_draw:
|
||||
_draw_marker(
|
||||
v["pos"] as Vector3,
|
||||
v["radius"] as float,
|
||||
v["color"] as Color,
|
||||
)
|
||||
markers_to_draw.clear()
|
||||
_markers_to_draw.clear()
|
||||
|
||||
for v in circles_to_draw:
|
||||
for v in _circles_to_draw:
|
||||
_draw_circle(v["pos"] as Vector3, v["color"] as Color)
|
||||
circles_to_draw.clear()
|
||||
_circles_to_draw.clear()
|
||||
|
||||
_draw_text()
|
||||
text_to_draw.clear()
|
||||
_text_to_draw.clear()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
## Handles fullscreen toggling
|
||||
|
||||
var is_fullscreen: bool = false
|
||||
var _is_fullscreen: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -14,8 +14,8 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
|
||||
func _toggle_fullscreen() -> void:
|
||||
is_fullscreen = not is_fullscreen
|
||||
if is_fullscreen:
|
||||
_is_fullscreen = not _is_fullscreen
|
||||
if _is_fullscreen:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||
else:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||
|
||||
@ -2,7 +2,8 @@ extends Node3D
|
||||
## Handles mouse hovering over units
|
||||
|
||||
var hovered_node: Variant
|
||||
var mouse_pos: Vector2 = Vector2.ZERO
|
||||
|
||||
var _mouse_pos: Vector2 = Vector2.ZERO
|
||||
|
||||
@onready var camera: Camera3D = StaticNodesManager.main_camera
|
||||
|
||||
@ -12,8 +13,8 @@ func _physics_process(_delta: float) -> void:
|
||||
return
|
||||
|
||||
var space_state := get_world_3d().direct_space_state
|
||||
var from := camera.project_ray_origin(mouse_pos)
|
||||
var to := from + camera.project_ray_normal(mouse_pos) * (camera.far - 1)
|
||||
var from := camera.project_ray_origin(_mouse_pos)
|
||||
var to := from + camera.project_ray_normal(_mouse_pos) * (camera.far - 1)
|
||||
var query := PhysicsRayQueryParameters3D.create(from, to)
|
||||
var result := space_state.intersect_ray(query)
|
||||
if not result:
|
||||
@ -24,4 +25,4 @@ func _physics_process(_delta: float) -> void:
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_pos = (event as InputEventMouseMotion).position
|
||||
_mouse_pos = (event as InputEventMouseMotion).position
|
||||
|
||||
@ -8,8 +8,11 @@ const ANIM_MAX_STEP = 30
|
||||
const MIN_VISIBLE_UNITS = 25
|
||||
const MAX_VISIBLE_UNITS = 120
|
||||
|
||||
var frustrum_polygon: ConvexPolygonShape3D = ConvexPolygonShape3D.new()
|
||||
var frustrum_polygon_points: PackedVector3Array = [
|
||||
var selecting: bool = false
|
||||
var advance_anim_step: int = 1
|
||||
|
||||
var _frustrum_polygon: ConvexPolygonShape3D = ConvexPolygonShape3D.new()
|
||||
var _frustrum_polygon_points: PackedVector3Array = [
|
||||
Vector3.ZERO,
|
||||
Vector3.UP,
|
||||
Vector3.RIGHT,
|
||||
@ -17,14 +20,12 @@ var frustrum_polygon_points: PackedVector3Array = [
|
||||
Vector3.ONE,
|
||||
]
|
||||
|
||||
var visible_units: Dictionary = {}
|
||||
var _visible_units: Dictionary = {}
|
||||
|
||||
var mouse_pressed: bool = false
|
||||
var selecting: bool = false
|
||||
var selection_rect: Rect2 = Rect2()
|
||||
var advance_anim_step: int = 1
|
||||
var _mouse_pressed: bool = false
|
||||
var _selection_rect: Rect2 = Rect2()
|
||||
|
||||
var rect_style := preload("res://resources/styles/selection_rect.tres")
|
||||
var _rect_style := preload("res://resources/styles/selection_rect.tres")
|
||||
|
||||
@onready var camera: Camera3D = StaticNodesManager.main_camera
|
||||
@onready var frustrum_area: Area3D = Area3D.new()
|
||||
@ -33,8 +34,8 @@ var rect_style := preload("res://resources/styles/selection_rect.tres")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
frustrum_polygon.points = frustrum_polygon_points
|
||||
frustrum_collision_shape.shape = frustrum_polygon
|
||||
_frustrum_polygon.points = _frustrum_polygon_points
|
||||
frustrum_collision_shape.shape = _frustrum_polygon
|
||||
rect_panel.visible = false
|
||||
frustrum_area.body_entered.connect(_on_frustrum_area_body_entered)
|
||||
frustrum_area.body_exited.connect(_on_frustrum_area_body_exited)
|
||||
@ -42,7 +43,7 @@ func _ready() -> void:
|
||||
frustrum_area.set_collision_mask_value(1, false)
|
||||
frustrum_area.set_collision_mask_value(2, true)
|
||||
rect_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
rect_panel.add_theme_stylebox_override("panel", rect_style)
|
||||
rect_panel.add_theme_stylebox_override("panel", _rect_style)
|
||||
add_child(rect_panel)
|
||||
add_child(frustrum_area)
|
||||
frustrum_area.add_child(frustrum_collision_shape)
|
||||
@ -50,8 +51,8 @@ func _ready() -> void:
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
selecting = (
|
||||
mouse_pressed
|
||||
and selection_rect.size.length() >= MIN_DRAG_DISTANCE
|
||||
_mouse_pressed
|
||||
and _selection_rect.size.length() >= MIN_DRAG_DISTANCE
|
||||
)
|
||||
|
||||
_handle_frustrum_shape()
|
||||
@ -64,22 +65,22 @@ func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if button_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
mouse_pressed = button_event.pressed
|
||||
if mouse_pressed:
|
||||
selection_rect.position = button_event.position
|
||||
selection_rect.size = Vector2.ZERO
|
||||
_mouse_pressed = button_event.pressed
|
||||
if _mouse_pressed:
|
||||
_selection_rect.position = button_event.position
|
||||
_selection_rect.size = Vector2.ZERO
|
||||
elif selecting:
|
||||
_set_selection_state(false)
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
if mouse_pressed:
|
||||
if _mouse_pressed:
|
||||
var mouse_pos := (event as InputEventMouseMotion).position
|
||||
selection_rect.size = mouse_pos - selection_rect.position
|
||||
_selection_rect.size = mouse_pos - _selection_rect.position
|
||||
|
||||
|
||||
func _handle_advance_anim_step() -> void:
|
||||
var remapped_unclamped := remap(
|
||||
visible_units.size(),
|
||||
_visible_units.size(),
|
||||
MIN_VISIBLE_UNITS,
|
||||
MAX_VISIBLE_UNITS,
|
||||
0,
|
||||
@ -99,13 +100,13 @@ func _handle_frustrum_shape() -> void:
|
||||
var corner_3 := camera.project_position(Vector2(0, viewport_size.y), far)
|
||||
var corner_4 := camera.project_position(viewport_size, far)
|
||||
|
||||
frustrum_polygon_points[0] = origin
|
||||
frustrum_polygon_points[1] = corner_1
|
||||
frustrum_polygon_points[2] = corner_2
|
||||
frustrum_polygon_points[3] = corner_3
|
||||
frustrum_polygon_points[4] = corner_4
|
||||
_frustrum_polygon_points[0] = origin
|
||||
_frustrum_polygon_points[1] = corner_1
|
||||
_frustrum_polygon_points[2] = corner_2
|
||||
_frustrum_polygon_points[3] = corner_3
|
||||
_frustrum_polygon_points[4] = corner_4
|
||||
|
||||
frustrum_polygon.points = frustrum_polygon_points
|
||||
_frustrum_polygon.points = _frustrum_polygon_points
|
||||
|
||||
|
||||
func _handle_selection_box() -> void:
|
||||
@ -113,7 +114,7 @@ func _handle_selection_box() -> void:
|
||||
if not selecting:
|
||||
return
|
||||
|
||||
var rect_abs := selection_rect.abs()
|
||||
var rect_abs := _selection_rect.abs()
|
||||
|
||||
rect_panel.position = rect_abs.position
|
||||
rect_panel.size = rect_abs.size
|
||||
@ -127,9 +128,9 @@ func _handle_unit_selection() -> void:
|
||||
|
||||
|
||||
func _set_selection_state(hover: bool) -> void:
|
||||
var rect_abs := selection_rect.abs()
|
||||
var rect_abs := _selection_rect.abs()
|
||||
|
||||
for unit: Unit in visible_units.values():
|
||||
for unit: Unit in _visible_units.values():
|
||||
if unit is not ControlledUnit:
|
||||
continue
|
||||
var controlled_unit := unit as ControlledUnit
|
||||
@ -149,15 +150,15 @@ func _on_frustrum_area_body_entered(unit: Node3D) -> void:
|
||||
return
|
||||
|
||||
var unit_id := unit.get_instance_id()
|
||||
if visible_units.keys().has(unit_id):
|
||||
if _visible_units.keys().has(unit_id):
|
||||
return
|
||||
|
||||
visible_units[unit_id] = unit as Unit
|
||||
_visible_units[unit_id] = unit as Unit
|
||||
|
||||
|
||||
func _on_frustrum_area_body_exited(unit: Node3D) -> void:
|
||||
var unit_id := unit.get_instance_id()
|
||||
if not visible_units.keys().has(unit_id):
|
||||
if not _visible_units.keys().has(unit_id):
|
||||
return
|
||||
|
||||
visible_units.erase(unit_id)
|
||||
_visible_units.erase(unit_id)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
## Holds all the sound effects for quick use
|
||||
|
||||
var pop_streams: Array[AudioStream] = [
|
||||
var _pop_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/pop_1.wav"),
|
||||
preload("res://assets/audio/units/pop_2.wav"),
|
||||
preload("res://assets/audio/units/pop_3.wav"),
|
||||
@ -11,7 +11,7 @@ var pop_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/pop_7.wav"),
|
||||
]
|
||||
|
||||
var swoosh_streams: Array[AudioStream] = [
|
||||
var _swoosh_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/swoosh_1.wav"),
|
||||
preload("res://assets/audio/units/swoosh_2.wav"),
|
||||
preload("res://assets/audio/units/swoosh_3.wav"),
|
||||
@ -21,14 +21,14 @@ var swoosh_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/swoosh_7.wav"),
|
||||
]
|
||||
|
||||
var ding_streams: Array[AudioStream] = [
|
||||
var _ding_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/ding_1.wav"),
|
||||
preload("res://assets/audio/units/ding_2.wav"),
|
||||
preload("res://assets/audio/units/ding_3.wav"),
|
||||
preload("res://assets/audio/units/ding_4.wav"),
|
||||
]
|
||||
|
||||
var tok_streams: Array[AudioStream] = [
|
||||
var _tok_streams: Array[AudioStream] = [
|
||||
preload("res://assets/audio/units/tok_1.wav"),
|
||||
preload("res://assets/audio/units/tok_2.wav"),
|
||||
preload("res://assets/audio/units/tok_3.wav"),
|
||||
@ -39,16 +39,16 @@ var tok_streams: Array[AudioStream] = [
|
||||
|
||||
|
||||
func pop() -> AudioStream:
|
||||
return pop_streams.pick_random()
|
||||
return _pop_streams.pick_random()
|
||||
|
||||
|
||||
func swoosh() -> AudioStream:
|
||||
return swoosh_streams.pick_random()
|
||||
return _swoosh_streams.pick_random()
|
||||
|
||||
|
||||
func ding() -> AudioStream:
|
||||
return ding_streams.pick_random()
|
||||
return _ding_streams.pick_random()
|
||||
|
||||
|
||||
func tok() -> AudioStream:
|
||||
return tok_streams.pick_random()
|
||||
return _tok_streams.pick_random()
|
||||
|
||||
@ -4,10 +4,10 @@ class_name Interactable
|
||||
|
||||
const MIN_DRAG_DISTANCE: float = 15
|
||||
|
||||
var hovered: bool = false
|
||||
var mouse_over: bool = false
|
||||
var can_interact: bool = true
|
||||
var click_position: Vector2 = Vector2.ZERO
|
||||
var _hovered: bool = false
|
||||
var _mouse_over: bool = false
|
||||
var _can_interact: bool = true
|
||||
var _click_start_position: Vector2 = Vector2.ZERO
|
||||
|
||||
@onready var hover_indicator: VisualInstance3D = $HoverIndicator
|
||||
|
||||
@ -19,26 +19,26 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
hovered = HoveringManager.hovered_node == self and mouse_over
|
||||
if not can_interact:
|
||||
hovered = false
|
||||
_hovered = HoveringManager.hovered_node == self and _mouse_over
|
||||
if not _can_interact:
|
||||
_hovered = false
|
||||
return
|
||||
hover_indicator.visible = hovered
|
||||
hover_indicator.visible = _hovered
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not can_interact:
|
||||
if not _can_interact:
|
||||
return
|
||||
if event is InputEventMouseButton and hovered:
|
||||
if event is InputEventMouseButton and _hovered:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if button_event.button_index != MOUSE_BUTTON_LEFT:
|
||||
return
|
||||
|
||||
if button_event.pressed:
|
||||
click_position = button_event.position
|
||||
_click_start_position = button_event.position
|
||||
else:
|
||||
if (
|
||||
(button_event.position - click_position).length()
|
||||
(button_event.position - _click_start_position).length()
|
||||
< MIN_DRAG_DISTANCE
|
||||
):
|
||||
_click()
|
||||
@ -49,8 +49,8 @@ func _click() -> void:
|
||||
|
||||
|
||||
func _on_mouse_entered() -> void:
|
||||
mouse_over = true
|
||||
_mouse_over = true
|
||||
|
||||
|
||||
func _on_mouse_exited() -> void:
|
||||
mouse_over = false
|
||||
_mouse_over = false
|
||||
@ -8,11 +8,12 @@ const MOVE_SPEED: float = 8
|
||||
const MOVE_ARC_HEIGHT: float = 0.5
|
||||
|
||||
var carried: bool = false
|
||||
var move_to: Vector3
|
||||
var move_from: Vector3
|
||||
var moving_timer: float = 0
|
||||
|
||||
var from_aphid: Aphid
|
||||
var _move_to: Vector3
|
||||
var _move_from: Vector3
|
||||
var _moving_timer: float = 0
|
||||
|
||||
var _from_aphid: Aphid
|
||||
|
||||
@onready var collision_shape: CollisionShape3D = $CollisionShape3D
|
||||
|
||||
@ -25,40 +26,40 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if moving_timer <= 0:
|
||||
if move_to != Vector3.ZERO:
|
||||
move_to = Vector3.ZERO
|
||||
if _moving_timer <= 0:
|
||||
if _move_to != Vector3.ZERO:
|
||||
_move_to = Vector3.ZERO
|
||||
moved.emit()
|
||||
return
|
||||
moving_timer -= delta * MOVE_SPEED
|
||||
global_position = move_from.bezier_interpolate(
|
||||
move_from + Vector3.UP * MOVE_ARC_HEIGHT,
|
||||
move_to + Vector3.UP * MOVE_ARC_HEIGHT,
|
||||
move_to,
|
||||
(1 - moving_timer),
|
||||
_moving_timer -= delta * MOVE_SPEED
|
||||
global_position = _move_from.bezier_interpolate(
|
||||
_move_from + Vector3.UP * MOVE_ARC_HEIGHT,
|
||||
_move_to + Vector3.UP * MOVE_ARC_HEIGHT,
|
||||
_move_to,
|
||||
(1 - _moving_timer),
|
||||
)
|
||||
if carried:
|
||||
hover_indicator.visible = false
|
||||
|
||||
|
||||
func set_aphid(from: Aphid) -> void:
|
||||
from_aphid = from
|
||||
_from_aphid = from
|
||||
|
||||
|
||||
func remove_from_spawner() -> void:
|
||||
if from_aphid == null:
|
||||
if _from_aphid == null:
|
||||
return
|
||||
from_aphid.erase_honeydew(self)
|
||||
_from_aphid.erase_honeydew(self)
|
||||
|
||||
|
||||
func set_carried(on: bool) -> void:
|
||||
carried = on
|
||||
can_interact = not carried
|
||||
_can_interact = not carried
|
||||
collision_shape.disabled = carried
|
||||
|
||||
|
||||
func start_moving(to: Vector3) -> Honeydew:
|
||||
moving_timer = 1
|
||||
move_from = global_position
|
||||
move_to = to
|
||||
_moving_timer = 1
|
||||
_move_from = global_position
|
||||
_move_to = to
|
||||
return self
|
||||
|
||||
@ -17,40 +17,41 @@ const WORLD_LIMIT_DISTANCE: float = 150 / 2
|
||||
|
||||
const ANIM_MAX_STEP = 10
|
||||
|
||||
@export var zoom_in_distance: float = 5
|
||||
@export var zoom_in_fov: float = 25
|
||||
@export var zoom_in_angle: float = -0.1 * PI
|
||||
@export var zoom_in_speed: float = 5
|
||||
@export var zoom_in_dof_far_distance: float = 7
|
||||
@export var zoom_in_dof_far_transition: float = 5
|
||||
@export var zoom_in_dof_near_distance: float = 2
|
||||
@export var zoom_in_dof_near_transition: float = 1
|
||||
@export var _zoom_in_distance: float = 5
|
||||
@export var _zoom_in_fov: float = 25
|
||||
@export var _zoom_in_angle: float = -0.1 * PI
|
||||
@export var _zoom_in_speed: float = 5
|
||||
@export var _zoom_in_dof_far_distance: float = 7
|
||||
@export var _zoom_in_dof_far_transition: float = 5
|
||||
@export var _zoom_in_dof_near_distance: float = 2
|
||||
@export var _zoom_in_dof_near_transition: float = 1
|
||||
|
||||
@export var zoom_out_distance: float = 90
|
||||
@export var zoom_out_fov: float = 30
|
||||
@export var zoom_out_angle: float = -0.25 * PI
|
||||
@export var zoom_out_speed: float = 35
|
||||
@export var zoom_out_dof_far_distance: float = 100
|
||||
@export var zoom_out_dof_far_transition: float = 40
|
||||
@export var zoom_out_dof_near_distance: float = 80
|
||||
@export var zoom_out_dof_near_transition: float = 20
|
||||
@export var _zoom_out_distance: float = 90
|
||||
@export var _zoom_out_fov: float = 30
|
||||
@export var _zoom_out_angle: float = -0.25 * PI
|
||||
@export var _zoom_out_speed: float = 35
|
||||
@export var _zoom_out_dof_far_distance: float = 100
|
||||
@export var _zoom_out_dof_far_transition: float = 40
|
||||
@export var _zoom_out_dof_near_distance: float = 80
|
||||
@export var _zoom_out_dof_near_transition: float = 20
|
||||
|
||||
var target_position: Vector3 = Vector3.ZERO
|
||||
var mouse_position: Vector2 = Vector2.ZERO
|
||||
## 0 = zoomed in. 1 = zoomed out.
|
||||
var zoom_value: float = ZOOM_VALUE_DEFAULT
|
||||
var zoom_unsmoothed: float = zoom_value
|
||||
var advance_anim_step: int = 1
|
||||
|
||||
var heading_to_position: Vector3 = Vector3.ZERO
|
||||
var heading_to_zoom: float = 0
|
||||
var heading_from_position: Vector3 = Vector3.ZERO
|
||||
var heading_from_zoom: float = 0
|
||||
var heading_progress: float = 0
|
||||
var _target_position: Vector3 = Vector3.ZERO
|
||||
var _mouse_position: Vector2 = Vector2.ZERO
|
||||
var _zoom_unsmoothed: float = zoom_value
|
||||
|
||||
var state: State = State.FREE
|
||||
var _heading_to_position: Vector3 = Vector3.ZERO
|
||||
var _heading_to_zoom: float = 0
|
||||
var _heading_from_position: Vector3 = Vector3.ZERO
|
||||
var _heading_from_zoom: float = 0
|
||||
var _heading_progress: float = 0
|
||||
|
||||
var window_out_of_focus: bool = false
|
||||
var _state: State = State.FREE
|
||||
|
||||
var _window_out_of_focus: bool = false
|
||||
|
||||
@onready var attrs: CameraAttributesPractical = attributes
|
||||
@onready var listener: AudioListener3D = $AudioListener3D
|
||||
@ -59,7 +60,7 @@ var window_out_of_focus: bool = false
|
||||
func _ready() -> void:
|
||||
assert(attrs != null, "attrs missing!")
|
||||
assert(listener != null, "listener missing!")
|
||||
target_position = StaticNodesManager.player_anthill.global_position
|
||||
_target_position = StaticNodesManager.player_anthill.global_position
|
||||
listener.make_current()
|
||||
|
||||
|
||||
@ -67,40 +68,40 @@ func _process(delta: float) -> void:
|
||||
_handle_heading_to(delta)
|
||||
_handle_movement(delta)
|
||||
|
||||
zoom_value = lerpf(zoom_value, zoom_unsmoothed, delta * ZOOM_DAMP)
|
||||
zoom_value = lerpf(zoom_value, _zoom_unsmoothed, delta * ZOOM_DAMP)
|
||||
|
||||
_handle_dof()
|
||||
_handle_advance_anim_step()
|
||||
|
||||
fov = lerpf(zoom_in_fov, zoom_out_fov, zoom_value)
|
||||
global_rotation.x = lerpf(zoom_in_angle, zoom_out_angle, zoom_value)
|
||||
var distance: float = lerpf(zoom_in_distance, zoom_out_distance, zoom_value)
|
||||
fov = lerpf(_zoom_in_fov, _zoom_out_fov, zoom_value)
|
||||
global_rotation.x = lerpf(_zoom_in_angle, _zoom_out_angle, zoom_value)
|
||||
var distance: float = lerpf(_zoom_in_distance, _zoom_out_distance, zoom_value)
|
||||
|
||||
var offset_direction := Vector3.BACK.rotated(
|
||||
Vector3.RIGHT,
|
||||
global_rotation.x
|
||||
)
|
||||
var offset := offset_direction * distance
|
||||
global_position = target_position + offset
|
||||
listener.global_position = target_position + (Vector3.UP * distance)
|
||||
global_position = _target_position + offset
|
||||
listener.global_position = _target_position + (Vector3.UP * distance)
|
||||
listener.global_rotation = global_rotation
|
||||
|
||||
DebugManager.marker(target_position, 0.05)
|
||||
DebugManager.marker(_target_position, 0.05)
|
||||
DebugManager.marker(listener.global_position, 0.05, Color.GREEN)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_position = (event as InputEventMouseMotion).position
|
||||
_mouse_position = (event as InputEventMouseMotion).position
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if button_event.pressed:
|
||||
if button_event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
zoom_unsmoothed -= ZOOM_STEP
|
||||
_zoom_unsmoothed -= ZOOM_STEP
|
||||
elif button_event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
zoom_unsmoothed += ZOOM_STEP
|
||||
zoom_unsmoothed = clampf(zoom_unsmoothed, 0, 1)
|
||||
_zoom_unsmoothed += ZOOM_STEP
|
||||
_zoom_unsmoothed = clampf(_zoom_unsmoothed, 0, 1)
|
||||
|
||||
if event.is_action_pressed("reset_camera"):
|
||||
head_to(StaticNodesManager.player_anthill.global_position)
|
||||
@ -108,19 +109,19 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_WINDOW_FOCUS_IN:
|
||||
window_out_of_focus = false
|
||||
_window_out_of_focus = false
|
||||
elif what == NOTIFICATION_WM_WINDOW_FOCUS_OUT:
|
||||
window_out_of_focus = true
|
||||
_window_out_of_focus = true
|
||||
|
||||
|
||||
## Start gradually moving camera towards a position
|
||||
func head_to(to: Vector3, zoom: float = ZOOM_VALUE_DEFAULT) -> void:
|
||||
heading_to_position = to
|
||||
heading_from_position = target_position
|
||||
heading_progress = 0
|
||||
heading_from_zoom = zoom_value
|
||||
heading_to_zoom = zoom
|
||||
state = State.HEADING_TO
|
||||
_heading_to_position = to
|
||||
_heading_from_position = _target_position
|
||||
_heading_progress = 0
|
||||
_heading_from_zoom = zoom_value
|
||||
_heading_to_zoom = zoom
|
||||
_state = State.HEADING_TO
|
||||
|
||||
|
||||
func _handle_advance_anim_step() -> void:
|
||||
@ -137,31 +138,31 @@ func _handle_advance_anim_step() -> void:
|
||||
|
||||
func _handle_dof() -> void:
|
||||
attrs.dof_blur_far_distance = lerpf(
|
||||
zoom_in_dof_far_distance,
|
||||
zoom_out_dof_far_distance,
|
||||
_zoom_in_dof_far_distance,
|
||||
_zoom_out_dof_far_distance,
|
||||
zoom_value,
|
||||
)
|
||||
attrs.dof_blur_far_transition = lerpf(
|
||||
zoom_in_dof_far_transition,
|
||||
zoom_out_dof_far_transition,
|
||||
_zoom_in_dof_far_transition,
|
||||
_zoom_out_dof_far_transition,
|
||||
zoom_value,
|
||||
)
|
||||
attrs.dof_blur_near_distance = lerpf(
|
||||
zoom_in_dof_near_distance,
|
||||
zoom_out_dof_near_distance,
|
||||
_zoom_in_dof_near_distance,
|
||||
_zoom_out_dof_near_distance,
|
||||
zoom_value,
|
||||
)
|
||||
attrs.dof_blur_near_transition = lerpf(
|
||||
zoom_in_dof_near_transition,
|
||||
zoom_out_dof_near_transition,
|
||||
_zoom_in_dof_near_transition,
|
||||
_zoom_out_dof_near_transition,
|
||||
zoom_value,
|
||||
)
|
||||
|
||||
|
||||
func _handle_movement(delta: float) -> void:
|
||||
if (
|
||||
window_out_of_focus
|
||||
or state != State.FREE
|
||||
_window_out_of_focus
|
||||
or _state != State.FREE
|
||||
or CursorManager.disable_confinement
|
||||
or SelectionManager.selecting
|
||||
):
|
||||
@ -172,17 +173,17 @@ func _handle_movement(delta: float) -> void:
|
||||
var move_input := Vector2()
|
||||
|
||||
# Horizontal
|
||||
if (mouse_position.x <= SCREEN_EDGE_THRESHOLD):
|
||||
if (_mouse_position.x <= SCREEN_EDGE_THRESHOLD):
|
||||
move_input.x = -1
|
||||
elif (mouse_position.x > viewport_size.x - SCREEN_EDGE_THRESHOLD):
|
||||
elif (_mouse_position.x > viewport_size.x - SCREEN_EDGE_THRESHOLD):
|
||||
move_input.x = 1
|
||||
else:
|
||||
move_input.x = 0
|
||||
|
||||
# Vertical
|
||||
if (mouse_position.y <= SCREEN_EDGE_THRESHOLD):
|
||||
if (_mouse_position.y <= SCREEN_EDGE_THRESHOLD):
|
||||
move_input.y = -1
|
||||
elif (mouse_position.y > viewport_size.y - SCREEN_EDGE_THRESHOLD):
|
||||
elif (_mouse_position.y > viewport_size.y - SCREEN_EDGE_THRESHOLD):
|
||||
move_input.y = 1
|
||||
else:
|
||||
move_input.y = 0
|
||||
@ -192,40 +193,40 @@ func _handle_movement(delta: float) -> void:
|
||||
.rotated(Vector3.UP, global_rotation.y)
|
||||
)
|
||||
|
||||
var speed: float = lerpf(zoom_in_speed, zoom_out_speed, zoom_value)
|
||||
var speed: float = lerpf(_zoom_in_speed, _zoom_out_speed, zoom_value)
|
||||
var velocity := direction * speed
|
||||
target_position += velocity * delta
|
||||
target_position.x = clampf(
|
||||
target_position.x,
|
||||
_target_position += velocity * delta
|
||||
_target_position.x = clampf(
|
||||
_target_position.x,
|
||||
-WORLD_LIMIT_DISTANCE,
|
||||
WORLD_LIMIT_DISTANCE
|
||||
)
|
||||
target_position.z = clampf(
|
||||
target_position.z,
|
||||
_target_position.z = clampf(
|
||||
_target_position.z,
|
||||
-WORLD_LIMIT_DISTANCE,
|
||||
WORLD_LIMIT_DISTANCE
|
||||
)
|
||||
|
||||
|
||||
func _handle_heading_to(delta: float) -> void:
|
||||
if state != State.HEADING_TO:
|
||||
if _state != State.HEADING_TO:
|
||||
return
|
||||
|
||||
if heading_progress >= 1:
|
||||
target_position = heading_to_position
|
||||
state = State.FREE
|
||||
if _heading_progress >= 1:
|
||||
_target_position = _heading_to_position
|
||||
_state = State.FREE
|
||||
|
||||
heading_progress += HEADING_SPEED * delta
|
||||
var eased_progress := ease(heading_progress, -3)
|
||||
target_position = heading_from_position.lerp(
|
||||
heading_to_position,
|
||||
_heading_progress += HEADING_SPEED * delta
|
||||
var eased_progress := ease(_heading_progress, -3)
|
||||
_target_position = _heading_from_position.lerp(
|
||||
_heading_to_position,
|
||||
eased_progress
|
||||
)
|
||||
zoom_unsmoothed = bezier_interpolate(
|
||||
heading_from_zoom,
|
||||
_zoom_unsmoothed = bezier_interpolate(
|
||||
_heading_from_zoom,
|
||||
1,
|
||||
1,
|
||||
heading_to_zoom,
|
||||
_heading_to_zoom,
|
||||
eased_progress,
|
||||
)
|
||||
zoom_value = zoom_unsmoothed
|
||||
zoom_value = _zoom_unsmoothed
|
||||
|
||||
@ -2,13 +2,13 @@ extends AudioStreamPlayer3D
|
||||
class_name SoundEffectsPlayer
|
||||
## Wrapper of AudioStreamPlayer3D that has AudioStreamPlaybackPolyphonic
|
||||
|
||||
var playback: AudioStreamPlaybackPolyphonic
|
||||
var _playback: AudioStreamPlaybackPolyphonic
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
stream = AudioStreamPolyphonic.new()
|
||||
play()
|
||||
playback = get_stream_playback()
|
||||
_playback = get_stream_playback()
|
||||
|
||||
|
||||
func play_sound(
|
||||
@ -17,7 +17,7 @@ func play_sound(
|
||||
new_volume_db: float = 0,
|
||||
new_pitch_scale: float = 1.0,
|
||||
) -> void:
|
||||
playback.play_stream(
|
||||
_playback.play_stream(
|
||||
new_stream,
|
||||
from_offset,
|
||||
new_volume_db,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends FollowingUI
|
||||
class_name AnthillInfo
|
||||
|
||||
var anthill: Anthill
|
||||
var _anthill: Anthill
|
||||
|
||||
@onready var ant_buy_button: BaseButton = $AntBuyButton
|
||||
@onready var add_one_button: BaseButton = $AddOneButton
|
||||
@ -25,9 +25,9 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if anthill == null or not visible:
|
||||
if _anthill == null or not visible:
|
||||
return
|
||||
counter.update_counter(anthill.honeydew)
|
||||
counter.update_counter(_anthill.honeydew)
|
||||
add_one_button.disabled = not DebugManager.enabled
|
||||
add_one_button.visible = DebugManager.enabled
|
||||
add_five_button.disabled = not DebugManager.enabled
|
||||
@ -38,28 +38,28 @@ func _process(delta: float) -> void:
|
||||
|
||||
func open(at: Anthill) -> void:
|
||||
visible = true
|
||||
anthill = at
|
||||
set_target(anthill.ui_origin)
|
||||
counter.initialize(anthill.honeydew, anthill.max_honeydew)
|
||||
_anthill = at
|
||||
set_target(_anthill.ui_origin)
|
||||
counter.initialize(_anthill.honeydew, _anthill.max_honeydew)
|
||||
|
||||
|
||||
func close() -> void:
|
||||
super.close()
|
||||
anthill = null
|
||||
_anthill = null
|
||||
|
||||
|
||||
func _on_ant_buy_button_pressed() -> void:
|
||||
UiManager.buy_ants.open(anthill)
|
||||
UiManager.buy_ants.open(_anthill)
|
||||
close()
|
||||
|
||||
|
||||
func _on_add_one_button_pressed() -> void:
|
||||
anthill.deposit_honeydew(1)
|
||||
_anthill.deposit_honeydew(1)
|
||||
|
||||
|
||||
func _on_add_five_button_pressed() -> void:
|
||||
anthill.deposit_honeydew(5)
|
||||
_anthill.deposit_honeydew(5)
|
||||
|
||||
|
||||
func _on_add_max_button_pressed() -> void:
|
||||
anthill.deposit_honeydew(anthill.max_honeydew)
|
||||
_anthill.deposit_honeydew(_anthill.max_honeydew)
|
||||
|
||||
@ -3,7 +3,7 @@ class_name BuyAnts
|
||||
|
||||
const COUNTER_SIZE:float = 32
|
||||
|
||||
var anthill: Anthill
|
||||
var _anthill: Anthill
|
||||
|
||||
@onready var buy_nitwit_button: BaseButton = $BuyNitwitButton
|
||||
@onready var nitwit_price_counter: HoneydewCounter = $NitwitPriceCounter
|
||||
@ -33,16 +33,16 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if anthill == null or not visible:
|
||||
if _anthill == null or not visible:
|
||||
return
|
||||
counter.update_counter(anthill.honeydew)
|
||||
counter.update_counter(_anthill.honeydew)
|
||||
nitwit_info.visible = buy_nitwit_button.is_hovered()
|
||||
gatherer_info.visible = buy_gatherer_button.is_hovered()
|
||||
|
||||
|
||||
func open(at: Anthill) -> void:
|
||||
visible = true
|
||||
anthill = at
|
||||
_anthill = at
|
||||
nitwit_price_counter.initialize(
|
||||
AntNitwit.get_cost(),
|
||||
AntNitwit.get_cost(),
|
||||
@ -53,16 +53,16 @@ func open(at: Anthill) -> void:
|
||||
AntGatherer.get_cost(),
|
||||
COUNTER_SIZE,
|
||||
)
|
||||
set_target(anthill.ui_origin)
|
||||
counter.initialize(anthill.honeydew, anthill.max_honeydew)
|
||||
set_target(_anthill.ui_origin)
|
||||
counter.initialize(_anthill.honeydew, _anthill.max_honeydew)
|
||||
|
||||
|
||||
func close() -> void:
|
||||
super.close()
|
||||
anthill = null
|
||||
_anthill = null
|
||||
|
||||
func _on_buy_nitwit_button_pressed() -> void:
|
||||
anthill.spawn_nitwit()
|
||||
_anthill.spawn_nitwit()
|
||||
|
||||
func _on_buy_gatherer_button_pressed() -> void:
|
||||
anthill.spawn_gatherer()
|
||||
_anthill.spawn_gatherer()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Control
|
||||
class_name CloseableUI
|
||||
|
||||
var is_mouse_over: bool = false
|
||||
var _is_mouse_over: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -12,7 +12,7 @@ func _input(event: InputEvent) -> void:
|
||||
if not visible:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and not is_mouse_over:
|
||||
if event is InputEventMouseButton and not _is_mouse_over:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if not button_event.pressed:
|
||||
return
|
||||
@ -21,7 +21,7 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
var motion_event := event as InputEventMouseMotion
|
||||
is_mouse_over = (
|
||||
_is_mouse_over = (
|
||||
Rect2(global_position, size)
|
||||
.has_point(motion_event.position)
|
||||
)
|
||||
|
||||
@ -3,15 +3,15 @@ class_name FollowingUI
|
||||
|
||||
const EDGE_MARGIN = 10
|
||||
|
||||
var target: Node3D
|
||||
var _target: Node3D
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not visible or target == null:
|
||||
if not visible or _target == null:
|
||||
return
|
||||
|
||||
var pos := StaticNodesManager.main_camera.unproject_position(
|
||||
target.global_position
|
||||
_target.global_position
|
||||
)
|
||||
var corner_1 := Vector2.ONE * EDGE_MARGIN
|
||||
var viewport_size := get_viewport().get_visible_rect().size
|
||||
@ -23,9 +23,9 @@ func _process(_delta: float) -> void:
|
||||
|
||||
|
||||
func set_target(to: Node3D) -> void:
|
||||
target = to
|
||||
_target = to
|
||||
|
||||
|
||||
func close() -> void:
|
||||
super.close()
|
||||
target = null
|
||||
_target = null
|
||||
|
||||
@ -6,18 +6,18 @@ const RANDOM_OFFSET: float = 5
|
||||
const GAP: float = 1
|
||||
const SPRITES_PER_RECT: int = 5
|
||||
|
||||
@export var atlas: AtlasTexture
|
||||
@export var _atlas: AtlasTexture
|
||||
|
||||
var rects: Array[TextureRect] = []
|
||||
var _rects: Array[TextureRect] = []
|
||||
|
||||
var max_count: int = 0
|
||||
var count_per_row: int = 0
|
||||
var rect_size: float = RECT_SIZE
|
||||
var _max_count: int = 0
|
||||
var _count_per_row: int = 0
|
||||
var _rect_size: float = RECT_SIZE
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
assert(atlas != null, "atlas missing!")
|
||||
count_per_row = floori(size.x / (rect_size + GAP))
|
||||
assert(_atlas != null, "_atlas missing!")
|
||||
_count_per_row = floori(size.x / (_rect_size + GAP))
|
||||
|
||||
|
||||
func initialize(
|
||||
@ -25,18 +25,18 @@ func initialize(
|
||||
init_max_count: int,
|
||||
r_size: float = RECT_SIZE,
|
||||
) -> void:
|
||||
max_count = init_max_count
|
||||
rect_size = r_size
|
||||
rects.clear()
|
||||
_max_count = init_max_count
|
||||
_rect_size = r_size
|
||||
_rects.clear()
|
||||
for rect in get_children():
|
||||
remove_child(rect)
|
||||
rect.queue_free()
|
||||
|
||||
for i in (ceil(init_max_count / SPRITES_PER_RECT) as int):
|
||||
var col: int = i % count_per_row
|
||||
var row: int = floori(i / count_per_row)
|
||||
var col: int = i % _count_per_row
|
||||
var row: int = floori(i / _count_per_row)
|
||||
var rect := _create_rect(col, row)
|
||||
rects.append(rect)
|
||||
_rects.append(rect)
|
||||
|
||||
update_counter(init_count)
|
||||
|
||||
@ -45,8 +45,8 @@ func update_counter(new_count: int) -> void:
|
||||
var remainder := new_count % SPRITES_PER_RECT
|
||||
var whole := new_count - remainder
|
||||
|
||||
for i in range(rects.size()):
|
||||
var rect := rects[i]
|
||||
for i in range(_rects.size()):
|
||||
var rect := _rects[i]
|
||||
var amount := i * SPRITES_PER_RECT
|
||||
var count: int = 0
|
||||
if amount >= new_count:
|
||||
@ -56,23 +56,23 @@ func update_counter(new_count: int) -> void:
|
||||
else:
|
||||
count = remainder
|
||||
|
||||
(rect.texture as AtlasTexture).region.position.x = count * atlas.region.size.x
|
||||
(rect.texture as AtlasTexture).region.position.x = count * _atlas.region.size.x
|
||||
|
||||
|
||||
func _create_rect(col: int, row: int) -> TextureRect:
|
||||
var rect := TextureRect.new()
|
||||
add_child(rect)
|
||||
rect.texture = atlas.duplicate()
|
||||
rect.texture = _atlas.duplicate()
|
||||
rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
rect.position.x = (
|
||||
col
|
||||
* (rect_size + GAP)
|
||||
* (_rect_size + GAP)
|
||||
+ randf_range(-RANDOM_OFFSET, RANDOM_OFFSET)
|
||||
)
|
||||
rect.position.y = (
|
||||
row
|
||||
* (rect_size + GAP)
|
||||
* (_rect_size + GAP)
|
||||
+ randf_range(-RANDOM_OFFSET, RANDOM_OFFSET)
|
||||
)
|
||||
rect.size = Vector2(rect_size, rect_size)
|
||||
rect.size = Vector2(_rect_size, _rect_size)
|
||||
return rect
|
||||
|
||||
@ -15,9 +15,9 @@ enum State {
|
||||
|
||||
const ANIMATION_SPEED: float = 0.25
|
||||
|
||||
var unit: Unit
|
||||
var state: State = State.NONE
|
||||
var anim_time: float = 0
|
||||
var _unit: Unit
|
||||
var _state: State = State.NONE
|
||||
var _anim_time: float = 0
|
||||
|
||||
@onready var texture_rect: TextureRect = $TextureRect
|
||||
@onready var atlas: AtlasTexture = texture_rect.texture as AtlasTexture
|
||||
@ -30,67 +30,67 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if unit == null or not visible:
|
||||
if _unit == null or not visible:
|
||||
return
|
||||
|
||||
anim_time += delta
|
||||
_anim_time += delta
|
||||
|
||||
_get_state()
|
||||
_handle_pictogram()
|
||||
|
||||
|
||||
func open(who: Unit) -> void:
|
||||
if unit != null:
|
||||
if _unit != null:
|
||||
close()
|
||||
visible = true
|
||||
unit = who
|
||||
set_target(unit.ui_origin)
|
||||
_unit = who
|
||||
set_target(_unit.ui_origin)
|
||||
|
||||
|
||||
func close() -> void:
|
||||
unit.toggle_info(false)
|
||||
_unit.toggle_info(false)
|
||||
super.close()
|
||||
|
||||
|
||||
func _handle_pictogram() -> void:
|
||||
texture_rect.visible = state != State.NONE
|
||||
atlas.region.position.y = (state - 1) * atlas.region.size.y
|
||||
texture_rect.visible = _state != State.NONE
|
||||
atlas.region.position.y = (_state - 1) * atlas.region.size.y
|
||||
atlas.region.position.x = floorf(
|
||||
wrapf(anim_time / ANIMATION_SPEED, 0, 4)
|
||||
wrapf(_anim_time / ANIMATION_SPEED, 0, 4)
|
||||
) * atlas.region.size.x
|
||||
|
||||
func _get_state() -> void:
|
||||
if unit is Aphid:
|
||||
match (unit as Aphid).state:
|
||||
if _unit is Aphid:
|
||||
match (_unit as Aphid).state:
|
||||
Aphid.State.WANDERING:
|
||||
state = State.APHID_IDLE
|
||||
_state = State.APHID_IDLE
|
||||
|
||||
if unit is AntNitwit:
|
||||
match (unit as AntNitwit).state:
|
||||
if _unit is AntNitwit:
|
||||
match (_unit as AntNitwit).state:
|
||||
AntNitwit.State.WANDERING:
|
||||
state = State.ANT_IDLE
|
||||
_state = State.ANT_IDLE
|
||||
AntNitwit.State.MOVING:
|
||||
state = State.ANT_MOVING
|
||||
_state = State.ANT_MOVING
|
||||
AntNitwit.State.GATHERING:
|
||||
_get_gathering_state((unit as AntNitwit).gathering.state)
|
||||
|
||||
if unit is AntGatherer:
|
||||
match (unit as AntGatherer).state:
|
||||
_get_gathering_state((_unit as AntNitwit).gathering.state)
|
||||
|
||||
if _unit is AntGatherer:
|
||||
match (_unit as AntGatherer).state:
|
||||
AntGatherer.State.WANDERING:
|
||||
state = State.ANT_IDLE
|
||||
_state = State.ANT_IDLE
|
||||
AntGatherer.State.MOVING:
|
||||
state = State.ANT_MOVING
|
||||
_state = State.ANT_MOVING
|
||||
AntGatherer.State.GATHERING:
|
||||
_get_gathering_state((unit as AntGatherer).gathering.state)
|
||||
_get_gathering_state((_unit as AntGatherer).gathering.state)
|
||||
|
||||
|
||||
func _get_gathering_state(gather_state: Gathering.State) -> void:
|
||||
match gather_state:
|
||||
Gathering.State.PICKING_UP:
|
||||
state = State.ANT_PICKING_UP
|
||||
_state = State.ANT_PICKING_UP
|
||||
Gathering.State.DEPOSITING:
|
||||
state = State.ANT_DEPOSITING
|
||||
_state = State.ANT_DEPOSITING
|
||||
Gathering.State.AWAITING:
|
||||
state = State.ANT_AWAITING
|
||||
_state = State.ANT_AWAITING
|
||||
Gathering.State.STOP:
|
||||
state = State.NONE
|
||||
_state = State.NONE
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
extends ControlledUnit
|
||||
class_name ControlledAntUnit
|
||||
|
||||
@onready var skeleton: Skeleton3D = $AntModel/Armature/Skeleton3D
|
||||
@onready var _skeleton: Skeleton3D = $AntModel/Armature/Skeleton3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
assert(skeleton != null, "skeleton missing!")
|
||||
assert(_skeleton != null, "_skeleton missing!")
|
||||
super._ready()
|
||||
|
||||
@ -4,12 +4,12 @@ class_name ControlledUnit
|
||||
signal moving_started
|
||||
signal moving_ended
|
||||
|
||||
var anthill: Anthill
|
||||
var _anthill: Anthill
|
||||
|
||||
var hovered_rect: bool = false
|
||||
var selected: bool = false
|
||||
var is_relocating: bool = false
|
||||
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||
var _hovered_rect: bool = false
|
||||
var _selected: bool = false
|
||||
var _is_relocating: bool = false
|
||||
var _ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||
|
||||
@onready var selection_indicator: VisualInstance3D = $SelectionIndicator
|
||||
|
||||
@ -19,9 +19,9 @@ static func get_cost() -> int:
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
max_wander_distance = 2
|
||||
min_wander_interval = 0.5
|
||||
max_wander_interval = 10
|
||||
_max_wander_distance = 2
|
||||
_min_wander_interval = 0.5
|
||||
_max_wander_interval = 10
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -32,23 +32,23 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
selection_indicator.visible = selected
|
||||
hover_indicator.visible = hovered or hovered_rect
|
||||
selection_indicator.visible = _selected
|
||||
hover_indicator.visible = _hovered or _hovered_rect
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
if is_relocating and nav_agent.is_navigation_finished():
|
||||
is_relocating = false
|
||||
if _is_relocating and nav_agent.is_navigation_finished():
|
||||
_is_relocating = false
|
||||
moving_ended.emit()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
super._input(event)
|
||||
if not is_on_screen:
|
||||
if not _is_on_screen:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and selected:
|
||||
if event is InputEventMouseButton and _selected:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if (
|
||||
button_event.button_index == MOUSE_BUTTON_RIGHT
|
||||
@ -62,21 +62,21 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
|
||||
func initialize(from: Anthill, pos: Vector3) -> ControlledUnit:
|
||||
anthill = from
|
||||
spawn_pos = pos
|
||||
_anthill = from
|
||||
_spawn_pos = pos
|
||||
return self
|
||||
|
||||
|
||||
func set_hovered_rect(on: bool) -> void:
|
||||
hovered_rect = on
|
||||
_hovered_rect = on
|
||||
|
||||
|
||||
func set_selected(on: bool) -> void:
|
||||
selected = on
|
||||
_selected = on
|
||||
|
||||
|
||||
func navigate(to: Vector3, relocating: bool = false) -> void:
|
||||
is_relocating = relocating
|
||||
_is_relocating = relocating
|
||||
nav_agent.set_target_position(to)
|
||||
|
||||
|
||||
@ -95,8 +95,8 @@ func _set_target_click(mouse_pos: Vector2) -> void:
|
||||
func _click_raycast(mouse_pos: Vector2) -> Vector3:
|
||||
var from := StaticNodesManager.main_camera.global_position
|
||||
var to := StaticNodesManager.main_camera.project_ray_normal(mouse_pos)
|
||||
return ground_plane.intersects_ray(from, to)
|
||||
return _ground_plane.intersects_ray(from, to)
|
||||
|
||||
|
||||
func _on_nav_agent_navigation_finished() -> void:
|
||||
wandering_center = nav_agent.get_final_position()
|
||||
_wandering_center = nav_agent.get_final_position()
|
||||
|
||||
@ -4,18 +4,18 @@ class_name Unit
|
||||
const MOVE_SPEED: float = 3
|
||||
const TURN_SPEED: float = 10
|
||||
|
||||
var max_wander_distance: float = 5
|
||||
var min_wander_interval: float = 0.25
|
||||
var max_wander_interval: float = 5
|
||||
var _max_wander_distance: float = 5
|
||||
var _min_wander_interval: float = 0.25
|
||||
var _max_wander_interval: float = 5
|
||||
|
||||
var is_on_screen: bool = false
|
||||
var wandering_timer: float = 0
|
||||
var wandering_center: Vector3 = Vector3.ZERO
|
||||
var spawn_pos: Vector3
|
||||
var _is_on_screen: bool = false
|
||||
var _wandering_timer: float = 0
|
||||
var _wandering_center: Vector3 = Vector3.ZERO
|
||||
var _spawn_pos: Vector3
|
||||
|
||||
var locomotion_value: float = 0
|
||||
var showing_info: bool = false
|
||||
var advance_anim_delta_accum: float = 0
|
||||
var _locomotion_value: float = 0
|
||||
var _showing_info: bool = false
|
||||
var _advance_anim_delta_accum: float = 0
|
||||
|
||||
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
||||
@onready var ui_origin: Node3D = $UiOrigin
|
||||
@ -39,10 +39,10 @@ func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
anim_advance_indicator.visible = false
|
||||
if spawn_pos != null and spawn_pos != Vector3.ZERO:
|
||||
global_position = spawn_pos
|
||||
if _spawn_pos != null and _spawn_pos != Vector3.ZERO:
|
||||
global_position = _spawn_pos
|
||||
|
||||
wandering_center = global_position
|
||||
_wandering_center = global_position
|
||||
nav_agent.max_speed = MOVE_SPEED
|
||||
nav_agent.velocity_computed.connect(_on_nav_agent_velocity_computed)
|
||||
set_max_slides(2)
|
||||
@ -64,7 +64,7 @@ func _physics_process(_delta: float) -> void:
|
||||
|
||||
|
||||
func toggle_info(on: bool) -> void:
|
||||
showing_info = on
|
||||
_showing_info = on
|
||||
|
||||
|
||||
func _click() -> void:
|
||||
@ -85,7 +85,7 @@ func _navigate() -> void:
|
||||
|
||||
|
||||
func _animate(delta: float) -> void:
|
||||
if not is_on_screen:
|
||||
if not _is_on_screen:
|
||||
return
|
||||
|
||||
if velocity.length() > 0.01:
|
||||
@ -98,14 +98,14 @@ func _animate(delta: float) -> void:
|
||||
)
|
||||
# look_at(global_position + velocity, Vector3.UP, true)
|
||||
|
||||
locomotion_value = move_toward(
|
||||
locomotion_value,
|
||||
_locomotion_value = move_toward(
|
||||
_locomotion_value,
|
||||
velocity.length() / MOVE_SPEED,
|
||||
delta * 8
|
||||
)
|
||||
animation_tree.set("parameters/locomotion/blend_position", locomotion_value)
|
||||
animation_tree.set("parameters/locomotion/blend_position", _locomotion_value)
|
||||
|
||||
advance_anim_delta_accum += delta
|
||||
_advance_anim_delta_accum += delta
|
||||
|
||||
var advance_anim_step := maxi(
|
||||
StaticNodesManager.main_camera.advance_anim_step,
|
||||
@ -115,21 +115,21 @@ func _animate(delta: float) -> void:
|
||||
var advance := (frame + get_instance_id()) % advance_anim_step == 0
|
||||
anim_advance_indicator.visible = advance and DebugManager.enabled
|
||||
if advance:
|
||||
animation_tree.advance(advance_anim_delta_accum)
|
||||
advance_anim_delta_accum = 0
|
||||
animation_tree.advance(_advance_anim_delta_accum)
|
||||
_advance_anim_delta_accum = 0
|
||||
|
||||
|
||||
func _wander(delta: float) -> void:
|
||||
wandering_timer -= delta
|
||||
if wandering_timer <= 0:
|
||||
_wandering_timer -= delta
|
||||
if _wandering_timer <= 0:
|
||||
var new_pos_offset := Vector3(
|
||||
randf_range(-max_wander_distance, max_wander_distance),
|
||||
randf_range(-_max_wander_distance, _max_wander_distance),
|
||||
0,
|
||||
randf_range(-max_wander_distance, max_wander_distance),
|
||||
randf_range(-_max_wander_distance, _max_wander_distance),
|
||||
)
|
||||
var new_pos := wandering_center + new_pos_offset
|
||||
var new_pos := _wandering_center + new_pos_offset
|
||||
nav_agent.set_target_position(new_pos)
|
||||
wandering_timer = randf_range(-min_wander_interval, max_wander_interval)
|
||||
_wandering_timer = randf_range(-_min_wander_interval, _max_wander_interval)
|
||||
|
||||
|
||||
func _on_nav_agent_velocity_computed(safe_velocity: Vector3) -> void:
|
||||
@ -138,8 +138,8 @@ func _on_nav_agent_velocity_computed(safe_velocity: Vector3) -> void:
|
||||
|
||||
|
||||
func _on_visibility_notifier_screen_entered() -> void:
|
||||
is_on_screen = true
|
||||
_is_on_screen = true
|
||||
|
||||
|
||||
func _on_visibility_notifier_screen_exited() -> void:
|
||||
is_on_screen = false
|
||||
_is_on_screen = false
|
||||
|
||||
@ -27,14 +27,14 @@ func _ready() -> void:
|
||||
nav_agent.navigation_finished.connect(gathering.on_nav_agent_navigation_finished)
|
||||
var item_bones: Array[int] = []
|
||||
for i in MAX_CARRY:
|
||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1)
|
||||
item_bones.append(_skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(_anthill, _skeleton, item_bones, MAX_CARRY, 0.4, 1)
|
||||
gathering.navigate_to.connect(_on_gathering_navigate_to)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if is_relocating:
|
||||
if _is_relocating:
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
@ -55,7 +55,7 @@ func _handle_wandering(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_gathering() -> void:
|
||||
gathering.handle_gathering(showing_info)
|
||||
gathering.handle_gathering(_showing_info)
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
|
||||
@ -26,14 +26,14 @@ func _ready() -> void:
|
||||
nav_agent.navigation_finished.connect(gathering.on_nav_agent_navigation_finished)
|
||||
var item_bones: Array[int] = []
|
||||
for i in gathering.DEFAULT_MAX_CARRYING:
|
||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(anthill, skeleton, item_bones)
|
||||
item_bones.append(_skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(_anthill, _skeleton, item_bones)
|
||||
gathering.navigate_to.connect(_on_gathering_navigate_to)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if is_relocating:
|
||||
if _is_relocating:
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
@ -54,7 +54,7 @@ func _handle_wandering(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_gathering() -> void:
|
||||
gathering.handle_gathering(showing_info)
|
||||
gathering.handle_gathering(_showing_info)
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
|
||||
@ -18,18 +18,18 @@ enum State {
|
||||
|
||||
var state: State = State.STOP
|
||||
|
||||
var nearby_items: Dictionary = {}
|
||||
var carrying_items: Array[Honeydew] = []
|
||||
var max_carrying: int = DEFAULT_MAX_CARRYING
|
||||
var _nearby_items: Dictionary = {}
|
||||
var _carrying_items: Array[Honeydew] = []
|
||||
var _max_carrying: int = DEFAULT_MAX_CARRYING
|
||||
|
||||
var target: Honeydew
|
||||
var anthill: Anthill
|
||||
var skeleton: Skeleton3D
|
||||
var _target: Honeydew
|
||||
var _anthill: Anthill
|
||||
var _skeleton: Skeleton3D
|
||||
|
||||
var drop_interval: float = DEFAULT_DROP_INTERVAL
|
||||
var pickup_interval: float = DEFAULT_PICKUP_INTERVAL
|
||||
var item_bones: Array[int] = []
|
||||
var showing_after_set: bool = false
|
||||
var _drop_interval: float = DEFAULT_DROP_INTERVAL
|
||||
var _pickup_interval: float = DEFAULT_PICKUP_INTERVAL
|
||||
var _item_bones: Array[int] = []
|
||||
var _showing_after_set: bool = false
|
||||
|
||||
@onready var gathering_center: Vector3 = global_position
|
||||
@onready var collision_shape: CollisionShape3D = $NearbyItemsSearch
|
||||
@ -50,19 +50,19 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
for i in range(carrying_items.size()):
|
||||
var item := carrying_items[i]
|
||||
for i in range(_carrying_items.size()):
|
||||
var item := _carrying_items[i]
|
||||
item.global_position = _get_nth_pile_pos(i)
|
||||
|
||||
if target != null:
|
||||
DebugManager.circle(target.global_position)
|
||||
if _target != null:
|
||||
DebugManager.circle(_target.global_position)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not visible:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and showing_after_set:
|
||||
if event is InputEventMouseButton and _showing_after_set:
|
||||
var button_event := event as InputEventMouseButton
|
||||
if not button_event.pressed:
|
||||
return
|
||||
@ -70,7 +70,7 @@ func _input(event: InputEvent) -> void:
|
||||
button_event.button_index == MOUSE_BUTTON_LEFT
|
||||
or button_event.button_index == MOUSE_BUTTON_RIGHT
|
||||
):
|
||||
showing_after_set = false
|
||||
_showing_after_set = false
|
||||
|
||||
|
||||
func initialize(
|
||||
@ -81,12 +81,12 @@ func initialize(
|
||||
drop_interv: float = DEFAULT_DROP_INTERVAL,
|
||||
pickup_interv: float = DEFAULT_PICKUP_INTERVAL,
|
||||
) -> void:
|
||||
anthill = from
|
||||
max_carrying = max_carry
|
||||
drop_interval = drop_interv
|
||||
pickup_interval = pickup_interv
|
||||
skeleton = skeleton_3d
|
||||
item_bones = bones
|
||||
_anthill = from
|
||||
_max_carrying = max_carry
|
||||
_drop_interval = drop_interv
|
||||
_pickup_interval = pickup_interv
|
||||
_skeleton = skeleton_3d
|
||||
_item_bones = bones
|
||||
|
||||
|
||||
func handle_gathering(showing_info: bool) -> void:
|
||||
@ -95,20 +95,20 @@ func handle_gathering(showing_info: bool) -> void:
|
||||
|
||||
radius_indicator.visible = (
|
||||
(state != State.STOP and showing_info)
|
||||
or showing_after_set
|
||||
or _showing_after_set
|
||||
)
|
||||
|
||||
|
||||
func start_gathering(item: Honeydew) -> void:
|
||||
gathering_center = item.global_position
|
||||
showing_after_set = true
|
||||
_showing_after_set = true
|
||||
state = State.AWAITING
|
||||
_go_pick_up(item)
|
||||
|
||||
|
||||
func stop_gathering() -> void:
|
||||
state = State.STOP
|
||||
target = null
|
||||
_target = null
|
||||
|
||||
|
||||
func on_nav_agent_navigation_finished() -> void:
|
||||
@ -117,57 +117,57 @@ func on_nav_agent_navigation_finished() -> void:
|
||||
|
||||
if (
|
||||
state == State.DEPOSITING
|
||||
and global_position.distance_to(anthill.global_position) < 1
|
||||
and global_position.distance_to(_anthill.global_position) < 1
|
||||
):
|
||||
_deposit()
|
||||
|
||||
|
||||
func _go_pick_up(item: Honeydew) -> void:
|
||||
state = State.AWAITING
|
||||
if anthill.space_left() <= 0:
|
||||
if _anthill.space_left() <= 0:
|
||||
return
|
||||
if carrying_items.size() >= max_carrying:
|
||||
if _carrying_items.size() >= _max_carrying:
|
||||
_go_deposit()
|
||||
return
|
||||
target = item
|
||||
_target = item
|
||||
state = State.PICKING_UP
|
||||
navigate_to.emit(item.global_position)
|
||||
|
||||
|
||||
func _go_deposit() -> void:
|
||||
state = State.DEPOSITING
|
||||
var dir := anthill.global_position.direction_to(global_position)
|
||||
var dir := _anthill.global_position.direction_to(global_position)
|
||||
navigate_to.emit(
|
||||
anthill.global_position
|
||||
_anthill.global_position
|
||||
+ dir
|
||||
* ANTHILL_DEPOSIT_RADIUS
|
||||
)
|
||||
|
||||
|
||||
func _get_nth_pile_pos(n: int) -> Vector3:
|
||||
return skeleton.to_global(skeleton.get_bone_global_pose(item_bones[n]).origin)
|
||||
return _skeleton.to_global(_skeleton.get_bone_global_pose(_item_bones[n]).origin)
|
||||
|
||||
|
||||
func _pick_up() -> void:
|
||||
var nearest := _find_nearest(nearby_items.values())
|
||||
if target == null or target.carried:
|
||||
var nearest := _find_nearest(_nearby_items.values())
|
||||
if _target == null or _target.carried:
|
||||
state = State.AWAITING
|
||||
if nearest != null:
|
||||
_go_pick_up(nearest)
|
||||
elif carrying_items.size() > 0:
|
||||
elif _carrying_items.size() > 0:
|
||||
_go_deposit()
|
||||
return
|
||||
|
||||
carrying_items.append(target)
|
||||
target.set_carried(true)
|
||||
_carrying_items.append(_target)
|
||||
_target.set_carried(true)
|
||||
audio_player.play_sound(SoundManager.swoosh())
|
||||
await target.start_moving(
|
||||
_get_nth_pile_pos(carrying_items.size() - 1)
|
||||
await _target.start_moving(
|
||||
_get_nth_pile_pos(_carrying_items.size() - 1)
|
||||
).moved
|
||||
audio_player.play_sound(SoundManager.pop())
|
||||
|
||||
await get_tree().create_timer(pickup_interval).timeout
|
||||
if carrying_items.size() >= max_carrying or nearest == null:
|
||||
await get_tree().create_timer(_pickup_interval).timeout
|
||||
if _carrying_items.size() >= _max_carrying or nearest == null:
|
||||
_go_deposit()
|
||||
return
|
||||
|
||||
@ -176,26 +176,26 @@ func _pick_up() -> void:
|
||||
|
||||
func _deposit() -> void:
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
while carrying_items.size() > 0:
|
||||
while _carrying_items.size() > 0:
|
||||
if state != State.DEPOSITING:
|
||||
return
|
||||
|
||||
if anthill.space_left() <= 0:
|
||||
if _anthill.space_left() <= 0:
|
||||
state = State.AWAITING
|
||||
await _drop_everything()
|
||||
return
|
||||
|
||||
var item := carrying_items.pop_back() as Honeydew
|
||||
var item := _carrying_items.pop_back() as Honeydew
|
||||
audio_player.play_sound(SoundManager.swoosh())
|
||||
await item.start_moving(anthill.global_position).moved
|
||||
await item.start_moving(_anthill.global_position).moved
|
||||
audio_player.play_sound(SoundManager.tok())
|
||||
item.remove_from_spawner()
|
||||
_erase_honeydew(item)
|
||||
item.queue_free()
|
||||
anthill.deposit_honeydew(1)
|
||||
await get_tree().create_timer(drop_interval).timeout
|
||||
_anthill.deposit_honeydew(1)
|
||||
await get_tree().create_timer(_drop_interval).timeout
|
||||
|
||||
var nearest := _find_nearest(nearby_items.values())
|
||||
var nearest := _find_nearest(_nearby_items.values())
|
||||
if nearest != null:
|
||||
_go_pick_up(nearest)
|
||||
return
|
||||
@ -205,8 +205,8 @@ func _deposit() -> void:
|
||||
|
||||
|
||||
func _drop_everything() -> void:
|
||||
while carrying_items.size() > 0:
|
||||
var item := carrying_items.pop_back() as Honeydew
|
||||
while _carrying_items.size() > 0:
|
||||
var item := _carrying_items.pop_back() as Honeydew
|
||||
var new_pos := Vector3(
|
||||
randf_range(-DROP_SPREAD, DROP_SPREAD),
|
||||
Honeydew.HEIGHT_OFFSET,
|
||||
@ -214,7 +214,7 @@ func _drop_everything() -> void:
|
||||
)
|
||||
await item.start_moving(global_position + new_pos).moved
|
||||
item.set_carried(false)
|
||||
await get_tree().create_timer(drop_interval).timeout
|
||||
await get_tree().create_timer(_drop_interval).timeout
|
||||
|
||||
|
||||
func _find_nearest(items: Array) -> Honeydew:
|
||||
@ -232,10 +232,10 @@ func _find_nearest(items: Array) -> Honeydew:
|
||||
|
||||
func _erase_honeydew(item: Honeydew) -> void:
|
||||
var item_id := item.get_instance_id()
|
||||
if not nearby_items.keys().has(item_id):
|
||||
if not _nearby_items.keys().has(item_id):
|
||||
return
|
||||
|
||||
nearby_items.erase(item_id)
|
||||
_nearby_items.erase(item_id)
|
||||
|
||||
|
||||
func _on_body_entered(item: Node3D) -> void:
|
||||
@ -243,11 +243,11 @@ func _on_body_entered(item: Node3D) -> void:
|
||||
return
|
||||
|
||||
var item_id := item.get_instance_id()
|
||||
if nearby_items.keys().has(item_id):
|
||||
if _nearby_items.keys().has(item_id):
|
||||
return
|
||||
|
||||
nearby_items[item_id] = item as Honeydew
|
||||
if state == State.AWAITING and anthill.space_left() > 0:
|
||||
_nearby_items[item_id] = item as Honeydew
|
||||
if state == State.AWAITING and _anthill.space_left() > 0:
|
||||
_go_pick_up(item as Honeydew)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user