Cow_Life_Sim_RPG/NPCs/JuiceCafeToucan/juice_cafe_toucan.gd

67 lines
1.2 KiB
GDScript

extends NPC
var rng = RandomNumberGenerator.new()
var hopSpeed = -200
var minX = 0
var maxX = 0
var waitTimer = 0
var hopping = false
func _ready():
characterName = "Julie"
pronouns = "she/her"
minX = position.x - 100
maxX = position.x + 50
func _process(delta):
waitTimer -= delta
if waitTimer <= 0:
if $Sprite.animation != "default":
wait_between_actions()
else:
pick_next_action()
if hopping:
if $Sprite.frame >= 2 and $Sprite.frame <= 3:
position.x += hopSpeed*delta
elif position.x <= minX and hopSpeed < 0:
hopSpeed = hopSpeed*-1
$Sprite.flip_h = true
elif position.x >= maxX and hopSpeed > 0:
hopSpeed = hopSpeed*-1
$Sprite.flip_h = false
func wait_between_actions():
hopping = false
waitTimer = rng.randf_range(0.5, 3)
$Sprite.play("default")
func pick_next_action():
hopping = false
var nextActionResult = rng.randi_range(0, 4)
if nextActionResult <= 1:
hop()
elif nextActionResult <= 2:
flap()
elif nextActionResult <= 3:
bounce()
elif nextActionResult <= 4:
wait_between_actions()
func hop():
$Sprite.play("Hop")
waitTimer = 1.5
hopping = true
func flap():
$Sprite.play("Flap")
waitTimer = 1.7
func bounce():
$Sprite.play("Bounce")
waitTimer = rng.randf_range(2, 5)