Initial commit
This commit is contained in:
commit
7becdd23b6
989 changed files with 28526 additions and 0 deletions
64
scenes/logic/net.gd
Normal file
64
scenes/logic/net.gd
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
extends Sprite2D
|
||||
|
||||
signal net_dropped(dropped_position: Vector2)
|
||||
|
||||
var sprite_rest = preload("res://images/sprites/fishing_net/ground.png")
|
||||
var sprite_grabbed = preload("res://images/sprites/fishing_net/grabbed.png")
|
||||
|
||||
var can_move = false
|
||||
var dragging = false
|
||||
var using_mouse = false
|
||||
var offs = Vector2.ZERO
|
||||
var starting_position = Vector2.ZERO
|
||||
|
||||
func _ready():
|
||||
starting_position = position
|
||||
|
||||
func _process(delta):
|
||||
if not visible:
|
||||
return
|
||||
if can_move and Input.is_action_just_pressed("ui_accept"):
|
||||
dragging = true
|
||||
using_mouse = false
|
||||
begin_dragging()
|
||||
elif dragging and not using_mouse and Input.is_action_just_released("ui_accept"):
|
||||
stop_dragging()
|
||||
if dragging:
|
||||
if using_mouse:
|
||||
position = get_global_mouse_position() - offs
|
||||
else:
|
||||
position += Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") * delta * 400
|
||||
|
||||
func begin_dragging():
|
||||
texture = sprite_grabbed
|
||||
$Shadow.visible = true
|
||||
$"..".play_sfx("net_picked_up")
|
||||
if using_mouse:
|
||||
offs = get_global_mouse_position() - global_position
|
||||
else:
|
||||
offs = Vector2.ZERO
|
||||
|
||||
func stop_dragging():
|
||||
dragging = false
|
||||
visible = false
|
||||
$Shadow.visible = false
|
||||
texture = sprite_rest
|
||||
$Button.disabled = true
|
||||
$ResetTimer.start()
|
||||
net_dropped.emit(position)
|
||||
position = starting_position
|
||||
|
||||
func _on_button_down():
|
||||
dragging = true
|
||||
using_mouse = true
|
||||
begin_dragging()
|
||||
|
||||
func _on_button_up():
|
||||
stop_dragging()
|
||||
|
||||
func _on_reset_timer_timeout():
|
||||
texture = sprite_rest
|
||||
$Button.disabled = false
|
||||
visible = true
|
||||
if can_move:
|
||||
$"..".play_sfx("net_returns")
|
||||
Loading…
Add table
Add a link
Reference in a new issue