diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-07-22 14:31:20 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-07-22 14:31:20 -0400 |
commit | 2a5aa7dc898b57d58e941d24b03a1d83ff9ddd81 (patch) | |
tree | 1b60b1f7fea4f43c7d759d3adc6c9dae28e52087 /Chicken.gd | |
parent | 914aa9e08061db55db4d445e8e43f71603dca634 (diff) | |
download | chicken-chaser-gd-2a5aa7dc898b57d58e941d24b03a1d83ff9ddd81.tar.gz chicken-chaser-gd-2a5aa7dc898b57d58e941d24b03a1d83ff9ddd81.zip |
chiken
Diffstat (limited to 'Chicken.gd')
-rw-r--r-- | Chicken.gd | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Chicken.gd b/Chicken.gd new file mode 100644 index 0000000..996c2eb --- /dev/null +++ b/Chicken.gd @@ -0,0 +1,64 @@ +extends KinematicBody + +export var rot_chance = 5.0 +export var rot_range = PI / 4.0 +export var mov_chance = 5.0 +export var mov_speed = 1.0 +export var mov_length_min = 1.0 +export var mov_length_max = 5.0 +export var flap_chance = 5.0 +export var squak_chance = 5.0 +export var peck_chance = 5.0 + +onready var anim = $AnimationTree + +func roll_die(chance): + return (randf() * 100) <= chance + +func _physics_process(delta): + match anim.wings.get_current_node(): + "IDLE": + if roll_die(flap_chance): + anim.wings.travel("FLAP") + "FLAP": + pass + match anim.state.get_current_node(): + "IDLE": + state_idle(delta) + "MOVING": + state_moving(delta) + "SQUACK": + pass + "PECK": + pass + +func state_idle(delta): + if roll_die(rot_chance): + var ang = randf() * rot_range + rotate(Vector3.UP, ang) + if roll_die(mov_chance): + anim.state.travel("MOVING") + var dist = lerp(mov_length_min, mov_length_max, randf()) + mov_lerp_pos = 0.0 + mov_lerp_step = (mov_speed * delta) / dist + var rotation = Transform(self.rotation, Vector3.ZERO) + var forward = rotation * Vector3.FORWARD + mov_lerp_start = translation + mov_lerp_target = translation + (forward * dist) + elif roll_die(squak_chance): + anim.state.travel("SQUACK") + elif roll_die(peck_chance): + anim.state.travel("PECK") + +var mov_lerp_start = Vector3.ZERO +var mov_lerp_target = Vector3.ZERO +var mov_lerp_step = 0.0 +var mov_lerp_pos = 0.0 +func state_moving(_delta): + if mov_lerp_pos >= 1.0: + anim.state.travel("IDLE") + return + mov_lerp_pos += mov_lerp_step + mov_lerp_pos = min(mov_lerp_pos, 1.0) + var pos = lerp(mov_lerp_start, mov_lerp_target, mov_lerp_pos) + pos = move_and_slide(pos - translation, Vector3.UP) |