scrubby
DevlogsIncubator3 / 5

scrubby

Just a regular day at the nursery

The first game mechanic I tackled was the mouse back and forth scrubbing action that removes the moss that spawns on the incubator.

func _input_event(_viewport, event, _shape_idx):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
is_mouse_held = event.pressed
last_mouse_position = get_global_mouse_position()
last_direction = Vector2.ZERO
if event.pressed:
scrub_sound.play() #start on click
else:
scrub_sound.stop() # stop on release
func _process(_delta: float) -> void:
if is_mouse_held and not is_cleaned:
var current_mouse_pos = get_global_mouse_position()
var movement_vector = current_mouse_pos - last_mouse_position
if movement_vector.length() > movement_threshold:
var current_direction = movement_vector.normalized()
# check if direction reversed (scrubbing motion)
if last_direction != Vector2.ZERO:
var dot = current_direction.dot(last_direction)
if dot < -0.3:
scrub_amount += 1
last_direction = current_direction
last_mouse_position = current_mouse_pos
if scrub_amount >= scrub_required:
_on_cleaned()
DevlogsIncubator3 / 5
License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.