Bingus follows muh man

This commit is contained in:
Rakarake 2023-04-11 22:40:16 +02:00
parent 9c2db1e801
commit c21cdca2f3
5 changed files with 60 additions and 28 deletions

12
state_machine/Follow.gd Normal file
View file

@ -0,0 +1,12 @@
extends StateRun
var following
func enter(actor_to_follow):
following = actor_to_follow
super.enter(actor_to_follow)
func update(delta):
var diff = following.global_position - actor.global_position
direction = diff.normalized().x
super.update(delta)

View file

@ -1,10 +1,12 @@
extends CharacterBody2D extends CharacterBody2D
@onready var stm := $StateMachine @onready var stm := $StateMachine
@onready var detect_box := $DetectBox
@onready var run := $StateMachine/Run @onready var run := $StateMachine/Run
@onready var air := $StateMachine/Air @onready var air := $StateMachine/Air
@onready var idle := $StateMachine/Idle @onready var idle := $StateMachine/Idle
@onready var detect_box := $DetectBox @onready var follow := $StateMachine/Follow
@export var wait_low: float @export var wait_low: float
@export var wait_high: float @export var wait_high: float
@ -54,7 +56,11 @@ func _physics_process(delta):
wait_tmp -= delta wait_tmp -= delta
if current_state() in [run, idle]: if current_state() in [run, idle]:
if detect_box.tracked != null: if detect_box.tracked != null:
pass stm.transition(follow, detect_box.tracked)
if current_state() in [follow] && !is_on_floor():
stm.transition(air)
if current_state() in [follow] && detect_box.tracked == null:
stm.transition(air)
current_state().update(delta) current_state().update(delta)
func _on_hurt_box_hurt(_data): func _on_hurt_box_hurt(_data):

View file

@ -1,40 +1,20 @@
[gd_scene load_steps=26 format=3 uid="uid://sxcxj2sua5ho"] [gd_scene load_steps=24 format=3 uid="uid://sxcxj2sua5ho"]
[ext_resource type="Script" path="res://test_levels/Bingus/Bingus.gd" id="1_rrndo"] [ext_resource type="Script" path="res://test_levels/Bingus/Bingus.gd" id="1_rrndo"]
[ext_resource type="Script" path="res://state_machine/StateMachine.gd" id="1_thnff"] [ext_resource type="Script" path="res://state_machine/StateMachine.gd" id="1_thnff"]
[ext_resource type="Texture2D" uid="uid://bgw5itdndav4s" path="res://icon.svg" id="1_xwbic"] [ext_resource type="Texture2D" uid="uid://bgw5itdndav4s" path="res://icon.svg" id="1_xwbic"]
[ext_resource type="Script" path="res://state_machine/Run.gd" id="2_07v8r"] [ext_resource type="Script" path="res://state_machine/Run.gd" id="2_07v8r"]
[ext_resource type="Script" path="res://state_machine/misc/RunStats.gd" id="4_3hl8o"] [ext_resource type="Script" path="res://state_machine/misc/RunStats.gd" id="4_3hl8o"]
[ext_resource type="Resource" uid="uid://cdynh4jxcd7nf" path="res://test_levels/Bingus/run-stats.tres" id="4_cmuis"]
[ext_resource type="Script" path="res://state_machine/Air.gd" id="5_glf41"] [ext_resource type="Script" path="res://state_machine/Air.gd" id="5_glf41"]
[ext_resource type="Script" path="res://state_machine/Idle.gd" id="6_wth30"] [ext_resource type="Script" path="res://state_machine/Idle.gd" id="6_wth30"]
[ext_resource type="Script" path="res://test_levels/Bingus/ToolWalkingRange.gd" id="7_32jv7"] [ext_resource type="Script" path="res://test_levels/Bingus/ToolWalkingRange.gd" id="7_32jv7"]
[ext_resource type="Script" path="res://state_machine/Follow.gd" id="7_hcxdp"]
[ext_resource type="Shape2D" uid="uid://dtwp5o51vl44k" path="res://test_levels/Bingus/shape.tres" id="8_ch2rf"] [ext_resource type="Shape2D" uid="uid://dtwp5o51vl44k" path="res://test_levels/Bingus/shape.tres" id="8_ch2rf"]
[ext_resource type="Script" path="res://state_machine/misc/HurtBox.gd" id="10_8ns80"] [ext_resource type="Script" path="res://state_machine/misc/HurtBox.gd" id="10_8ns80"]
[ext_resource type="Script" path="res://state_machine/misc/HitBox.gd" id="11_t4cwu"] [ext_resource type="Script" path="res://state_machine/misc/HitBox.gd" id="11_t4cwu"]
[ext_resource type="Script" path="res://state_machine/misc/DetectBox.gd" id="12_gga00"] [ext_resource type="Script" path="res://state_machine/misc/DetectBox.gd" id="12_gga00"]
[sub_resource type="Curve" id="Curve_q4yvk"]
max_value = 300.0
_data = [Vector2(0, 245.455), 0.0, 0.0, 0, 0, Vector2(0.232628, 240), 0.0, 0.0, 0, 0, Vector2(0.407855, 0), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="Curve" id="Curve_i3mgk"]
max_value = 200.0
_data = [Vector2(0.473354, 200), 0.0, 0.0, 0, 0]
point_count = 1
[sub_resource type="Curve" id="Curve_06xsq"]
max_value = 200.0
_data = [Vector2(0.435045, 200), 0.0, 0.0, 0, 0]
point_count = 1
[sub_resource type="Resource" id="Resource_8hs8i"]
script = ExtResource("4_3hl8o")
accel_curve = SubResource("Curve_q4yvk")
turn_curve = SubResource("Curve_06xsq")
stop_curve = SubResource("Curve_i3mgk")
time = 200.0
[sub_resource type="Curve" id="Curve_msnum"] [sub_resource type="Curve" id="Curve_msnum"]
min_value = -200.0 min_value = -200.0
max_value = 0.0 max_value = 0.0
@ -84,7 +64,7 @@ initial_state = NodePath("Run")
[node name="Run" type="Node" parent="StateMachine"] [node name="Run" type="Node" parent="StateMachine"]
script = ExtResource("2_07v8r") script = ExtResource("2_07v8r")
run_stats = SubResource("Resource_8hs8i") run_stats = ExtResource("4_cmuis")
[node name="Air" type="Node" parent="StateMachine"] [node name="Air" type="Node" parent="StateMachine"]
script = ExtResource("5_glf41") script = ExtResource("5_glf41")
@ -95,6 +75,10 @@ air_run_stats = SubResource("Resource_hmkwm")
script = ExtResource("6_wth30") script = ExtResource("6_wth30")
stop_curve = SubResource("Curve_0konv") stop_curve = SubResource("Curve_0konv")
[node name="Follow" type="Node" parent="StateMachine"]
script = ExtResource("7_hcxdp")
run_stats = ExtResource("4_cmuis")
[node name="Icon" type="Sprite2D" parent="."] [node name="Icon" type="Sprite2D" parent="."]
texture = ExtResource("1_xwbic") texture = ExtResource("1_xwbic")
@ -125,19 +109,23 @@ script = ExtResource("12_gga00")
[node name="Detect" type="Area2D" parent="DetectBox"] [node name="Detect" type="Area2D" parent="DetectBox"]
collision_layer = 0 collision_layer = 0
collision_mask = 2 collision_mask = 4
[node name="Shape" type="CollisionShape2D" parent="DetectBox/Detect"] [node name="Shape" type="CollisionShape2D" parent="DetectBox/Detect"]
shape = SubResource("CircleShape2D_i74o8") shape = SubResource("CircleShape2D_i74o8")
debug_color = Color(0.580392, 0.529412, 0.423529, 0.192157) debug_color = Color(0.580392, 0.529412, 0.423529, 0.192157)
[node name="Undetect" type="Area2D" parent="DetectBox"] [node name="Undetect" type="Area2D" parent="DetectBox"]
collision_layer = 0
collision_mask = 4
[node name="Shape" type="CollisionShape2D" parent="DetectBox/Undetect"] [node name="Shape" type="CollisionShape2D" parent="DetectBox/Undetect"]
shape = SubResource("CircleShape2D_pv3id") shape = SubResource("CircleShape2D_pv3id")
debug_color = Color(0.556863, 0.545098, 0.364706, 0.0901961) debug_color = Color(0.556863, 0.545098, 0.364706, 0.0901961)
[node name="AttackRange" type="Area2D" parent="."] [node name="AttackRange" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 4
[node name="Shape" type="CollisionShape2D" parent="AttackRange"] [node name="Shape" type="CollisionShape2D" parent="AttackRange"]
rotation = 1.5708 rotation = 1.5708

View file

@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="RunStats" load_steps=5 format=3 uid="uid://cdynh4jxcd7nf"]
[ext_resource type="Script" path="res://state_machine/misc/RunStats.gd" id="1_cje7e"]
[sub_resource type="Curve" id="Curve_q4yvk"]
min_value = -100.0
max_value = 300.0
_data = [Vector2(0, 67.2727), 0.0, 0.0, 0, 0, Vector2(0.325581, 60), 0.0, 0.0, 0, 0, Vector2(0.391473, -100), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="Curve" id="Curve_i3mgk"]
max_value = 200.0
_data = [Vector2(0.473354, 200), 0.0, 0.0, 0, 0]
point_count = 1
[sub_resource type="Curve" id="Curve_06xsq"]
max_value = 200.0
_data = [Vector2(0.435045, 200), 0.0, 0.0, 0, 0]
point_count = 1
[resource]
script = ExtResource("1_cje7e")
accel_curve = SubResource("Curve_q4yvk")
turn_curve = SubResource("Curve_06xsq")
stop_curve = SubResource("Curve_i3mgk")
time = 200.0

View file

@ -31,7 +31,7 @@ texture = ExtResource("2_vgtwj")
script = ExtResource("2_rd8co") script = ExtResource("2_rd8co")
[node name="Player" parent="." instance=ExtResource("1_abwpk")] [node name="Player" parent="." instance=ExtResource("1_abwpk")]
position = Vector2(356, 274) position = Vector2(665, 303)
[node name="Platforms" type="Node2D" parent="."] [node name="Platforms" type="Node2D" parent="."]