summaryrefslogtreecommitdiff
path: root/player/opponent.gd
diff options
context:
space:
mode:
Diffstat (limited to 'player/opponent.gd')
-rw-r--r--player/opponent.gd57
1 files changed, 57 insertions, 0 deletions
diff --git a/player/opponent.gd b/player/opponent.gd
new file mode 100644
index 0000000..ec20cd1
--- /dev/null
+++ b/player/opponent.gd
@@ -0,0 +1,57 @@
+extends Character
+
+
+var current_direction := Direction.Left
+
+@export var random_start_type := false
+
+
+func _ready() -> void:
+ super._ready()
+
+ var rng = RandomNumberGenerator.new()
+ rng.seed = ((get_tree().current_scene as Stage).scene_file_path as String).md5_buffer().decode_u64(0) + Time.get_ticks_msec()
+
+ $AnimatedSprite2D.modulate = Color(max(0.1, rng.randf()), max(0.1, rng.randf()), max(0.1, rng.randf()))
+
+ speed_modifier = 0.5
+
+ if random_start_type:
+ current_type = Type.values().pick_random()
+
+ idle()
+
+
+func _process(_delta: float) -> void:
+ if current_state == State.Idle or current_state == State.Walk:
+ walk(current_direction)
+
+ if is_on_wall(current_direction):
+ change_direction()
+
+ if not is_on_floor():
+ fall()
+
+
+func is_below_ledge() -> bool:
+ return $RayUpLeft2.is_colliding() or $RayUpRight2.is_colliding()
+
+
+func change_direction():
+ if current_direction == Direction.Left:
+ current_direction = Direction.Right
+ else:
+ current_direction = Direction.Left
+
+
+func _on_vertical_timer_timeout() -> void:
+ if current_state == State.Idle or current_state == State.Walk:
+ if randi_range(0, 100) > 75:
+ change_direction()
+
+ if randi_range(0, 100) > 75 and is_below_ledge():
+ await jump()
+ elif randi_range(0, 100) > 75 and not is_on_bottom_floor():
+ await fall()
+
+ $VerticalTimer.start()