Initial commit
This commit is contained in:
commit
7becdd23b6
989 changed files with 28526 additions and 0 deletions
47
scenes/logic/fishing_target.gd
Normal file
47
scenes/logic/fishing_target.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
extends RigidBody2D
|
||||
|
||||
var index = -1
|
||||
var difficulty = 0.0
|
||||
var catched_by = null
|
||||
var current_direction = Vector2.ZERO
|
||||
var minimum_speed = 0.0
|
||||
|
||||
func init_target(target_index, target_sprite, fishing_difficulty):
|
||||
index = target_index
|
||||
difficulty = fishing_difficulty
|
||||
global_position = Vector2(randf_range(100, 700), randf_range(100, 340))
|
||||
$Sprite2D.texture = target_sprite
|
||||
minimum_speed = lerp(5.0, 150.0, difficulty)
|
||||
linear_velocity = Vector2(0.5 - randf(), 0.5 - randf()).normalized() * 2 * minimum_speed
|
||||
change_direction(true)
|
||||
|
||||
func _process(delta):
|
||||
if catched_by:
|
||||
global_position = catched_by.global_position
|
||||
else:
|
||||
if linear_velocity.length() < minimum_speed:
|
||||
linear_velocity *= 1.25
|
||||
if constant_force.length() > 5 * minimum_speed:
|
||||
constant_force *= 0.5
|
||||
else:
|
||||
add_constant_central_force(current_direction * delta)
|
||||
|
||||
func change_direction(init: bool = false):
|
||||
current_direction = (Vector2(400, 220) - global_position) \
|
||||
.rotated(deg_to_rad(randf_range(-30, 30))) \
|
||||
.normalized() * lerp(0.0, 40.0, difficulty)
|
||||
apply_torque_impulse(randf_range(-1.0, 1.0) * difficulty)
|
||||
# This conditional only exists because Godot is weird with Timers
|
||||
if init:
|
||||
$MovementTimer.wait_time = randf_range(2.0, 4.0)
|
||||
$MovementTimer.autostart = true
|
||||
else:
|
||||
$MovementTimer.start(randf_range(2.0, 4.0))
|
||||
|
||||
func _on_movement_timer_timeout():
|
||||
change_direction()
|
||||
|
||||
func grab_with(net_sprite_2d: AnimatedSprite2D):
|
||||
catched_by = net_sprite_2d
|
||||
$MovementTimer.paused = true
|
||||
global_position = catched_by.global_position
|
||||
Loading…
Add table
Add a link
Reference in a new issue