"splat-launch" move :3
This commit is contained in:
parent
20f35ab240
commit
7779e241f6
6 changed files with 97 additions and 11 deletions
|
@ -13,8 +13,8 @@ func _process(delta: float) -> void:
|
|||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
body.ices_touched += 1
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
body.ices_touched -= 1
|
||||
pass
|
||||
|
|
|
@ -11,6 +11,8 @@ extends CharacterBody2D
|
|||
@export_group("Air Movement")
|
||||
@export var gravity: float
|
||||
@export var jump_power: float
|
||||
@export var splat_launch_power: float
|
||||
@export var splat_offset: float
|
||||
|
||||
@export_group("Internal References")
|
||||
@export var state_chart: StateChart
|
||||
|
@ -26,8 +28,12 @@ var input_dir: Vector2 = Vector2.ZERO:
|
|||
input_dir = value.sign()
|
||||
state_chart.set_expression_property(&"input_dir", input_dir)
|
||||
|
||||
var _last_velocity: Vector2 = Vector2.ZERO
|
||||
var _splat_normal: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_last_velocity = velocity
|
||||
move_and_slide()
|
||||
state_chart.set_expression_property(&"velocity", velocity)
|
||||
if velocity.x != 0.0:
|
||||
|
@ -88,11 +94,35 @@ func _start_jump() -> void:
|
|||
|
||||
|
||||
#region Missile
|
||||
func _restore_graphics_rotation() -> void:
|
||||
graphics.rotation = 0.0
|
||||
|
||||
|
||||
func _face_towards_velocity(_delta: float) -> void:
|
||||
graphics.rotation = Vector2(graphics.scale.x, 0.0).angle_to(velocity)
|
||||
|
||||
func _restore_graphics_rotation() -> void:
|
||||
graphics.rotation = 0.0
|
||||
func _check_for_splat(delta: float) -> void:
|
||||
var col = move_and_collide(_last_velocity * delta, true)
|
||||
if col:
|
||||
velocity = Vector2.ZERO
|
||||
global_position += col.get_travel()
|
||||
_splat_normal = col.get_normal()
|
||||
var angle = col.get_normal().angle()
|
||||
if graphics.scale.x > 0.0:
|
||||
angle += PI
|
||||
graphics.set_deferred(&"rotation", angle)
|
||||
state_chart.send_event(&"splatted")
|
||||
#endregion
|
||||
|
||||
|
||||
#region Splatting
|
||||
func _do_splat_launch() -> void:
|
||||
var dir = input_dir.project(_splat_normal.orthogonal()).normalized()
|
||||
if dir == Vector2.ZERO:
|
||||
dir = _splat_normal
|
||||
dir = dir.rotated(dir.angle_to(_splat_normal) * 0.5)
|
||||
|
||||
launch(dir * splat_launch_power)
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
|
@ -79,23 +79,24 @@ turn_acceleration = 300.0
|
|||
stopping_force = 200.0
|
||||
gravity = 450.0
|
||||
jump_power = 180.0
|
||||
splat_launch_power = 240.0
|
||||
splat_offset = 6.0
|
||||
state_chart = NodePath("StateChart")
|
||||
graphics = NodePath("Graphics")
|
||||
run_animation = NodePath("Graphics/Sprite/Run")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -6)
|
||||
shape = SubResource("CircleShape2D_tvyy1")
|
||||
debug_color = Color(3.32102e-06, 0.648976, 0.161954, 0.42)
|
||||
|
||||
[node name="Graphics" type="Node2D" parent="."]
|
||||
position = Vector2(0, -6)
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="Graphics"]
|
||||
texture = ExtResource("3_trcll")
|
||||
offset = Vector2(0, -2)
|
||||
hframes = 4
|
||||
vframes = 4
|
||||
frame = 10
|
||||
region_rect = Rect2(0, 0, 64, 64)
|
||||
|
||||
[node name="Idle" type="Node" parent="Graphics/Sprite"]
|
||||
|
@ -128,6 +129,18 @@ first_frame = Vector2i(1, 2)
|
|||
script = ExtResource("4_bsdw5")
|
||||
first_frame = Vector2i(2, 2)
|
||||
|
||||
[node name="Splat" type="Node" parent="Graphics/Sprite"]
|
||||
script = ExtResource("4_bsdw5")
|
||||
first_frame = Vector2i(0, 3)
|
||||
frames = 2
|
||||
fps = 8.0
|
||||
|
||||
[node name="UnSplat" type="Node" parent="Graphics/Sprite"]
|
||||
script = ExtResource("4_bsdw5")
|
||||
first_frame = Vector2i(2, 3)
|
||||
frames = 2
|
||||
fps = 8.0
|
||||
|
||||
[node name="Sounds" type="Node" parent="."]
|
||||
|
||||
[node name="Voice" type="AudioStreamPlayer" parent="Sounds"]
|
||||
|
@ -140,7 +153,6 @@ bus = &"Capri"
|
|||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("5_bcjtl")
|
||||
track_in_editor = true
|
||||
initial_expression_properties = {
|
||||
&"input_dir": Vector2(0, 0),
|
||||
&"on_floor": false,
|
||||
|
@ -285,6 +297,41 @@ delay_in_seconds = "0.0"
|
|||
editor_description = "Player is hurtling through the air and ricocheting off of surfaces."
|
||||
script = ExtResource("10_mvu25")
|
||||
|
||||
[node name="on Splatted" type="Node" parent="StateChart/Root/Airborne/Missile"]
|
||||
editor_description = "Transition to splat state when the player hits a wall"
|
||||
script = ExtResource("7_rgjdc")
|
||||
to = NodePath("../../../Floating/Splat")
|
||||
event = &"splatted"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Floating" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("6_jnxnd")
|
||||
initial_state = NodePath("UnSplat")
|
||||
|
||||
[node name="Splat" type="Node" parent="StateChart/Root/Floating"]
|
||||
editor_description = "Player has slammed into a surface (and has a moment to perform an action?)"
|
||||
script = ExtResource("10_mvu25")
|
||||
|
||||
[node name="on JumpPressed" type="Node" parent="StateChart/Root/Floating/Splat"]
|
||||
script = ExtResource("7_rgjdc")
|
||||
to = NodePath("..")
|
||||
event = &"jump_pressed"
|
||||
delay_in_seconds = ""
|
||||
|
||||
[node name="on TimeOut" type="Node" parent="StateChart/Root/Floating/Splat"]
|
||||
script = ExtResource("7_rgjdc")
|
||||
to = NodePath("../../UnSplat")
|
||||
delay_in_seconds = "0.75"
|
||||
|
||||
[node name="UnSplat" type="Node" parent="StateChart/Root/Floating"]
|
||||
editor_description = "Player is unsticking from a surface."
|
||||
script = ExtResource("10_mvu25")
|
||||
|
||||
[node name="on TimeOut" type="Node" parent="StateChart/Root/Floating/UnSplat"]
|
||||
script = ExtResource("7_rgjdc")
|
||||
to = NodePath("../../../Airborne/Falling")
|
||||
delay_in_seconds = ".25"
|
||||
|
||||
[connection signal="taken" from="StateChart/Root/on Killed" to="." method="_reset_position"]
|
||||
[connection signal="taken" from="StateChart/Root/on Killed" to="Sounds/Death" method="play"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Grounded/Standing/Idle" to="Graphics/Sprite/Idle" method="play"]
|
||||
|
@ -304,3 +351,8 @@ script = ExtResource("10_mvu25")
|
|||
[connection signal="state_entered" from="StateChart/Root/Airborne/Missile" to="Graphics/Sprite/Missile" method="play"]
|
||||
[connection signal="state_exited" from="StateChart/Root/Airborne/Missile" to="." method="_restore_graphics_rotation"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/Missile" to="." method="_face_towards_velocity"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/Missile" to="." method="_check_for_splat"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Floating/Splat" to="Graphics/Sprite/Splat" method="play"]
|
||||
[connection signal="taken" from="StateChart/Root/Floating/Splat/on JumpPressed" to="." method="_do_splat_launch"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Floating/UnSplat" to="Graphics/Sprite/UnSplat" method="play"]
|
||||
[connection signal="state_exited" from="StateChart/Root/Floating/UnSplat" to="." method="_restore_graphics_rotation"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue