fix: platforms are tweens, enemies hurting fix

Enemies now make the player die
(would be better with event)
This resolves blobby detecting being killed
whilst stomping
This commit is contained in:
Jakob Feldmann 2023-08-04 20:56:17 +02:00
parent 328abd6b54
commit 8021aa1bf5
20 changed files with 293 additions and 427 deletions

View File

@ -231,7 +231,7 @@ func is_touching_wall_completely() -> bool:
# Attached to wall state is in the PlayerStateMachine
func is_correct_walljump_input(direction: Vector2) -> bool:
return (
Input.is_action_pressed("jump")
Input.is_action_just_pressed("jump")
&& abs(direction.x + wall_touch_direction) < 1
&& abs(direction.x + wall_touch_direction) >= 0
)
@ -429,6 +429,7 @@ func receive_power_up(kind: String) -> void:
# TODO Maybe this should be a state in itself?
func die(animation_number: int = 0) -> void:
if levelState.is_dead: return
if shielded:
shielded = false
$BubbleShieldViewport/IridescenceBall.visible = false
@ -458,16 +459,11 @@ func respawn() -> void:
# When the Enemy stomp AREA enters the enemy collision area -> stomp
func _on_BlobbySkin_area_entered(area: Area2D) -> void:
if area.is_in_group("harmful") && !levelState.is_dead:
if area.is_in_group("harmful"):
die()
if area.is_in_group("pit"):
$PitfallTimer.start()
# When the Enemy collision BODY enters the enemy collision area -> die
func _on_BlobbySkin_body_entered(body: Node) -> void:
if body.is_in_group("harmful") && !levelState.is_dead:
die()
# This problem stems from trying to decelerate a walk
# that was caused by the moving environment and not by input
# It is particularly usefull for moving floor physics

View File

@ -4396,6 +4396,8 @@ one_shot = true
wait_time = 0.809
one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
[connection signal="area_entered" from="BlobbySkin" to="." method="_on_BlobbySkin_area_entered"]
[connection signal="body_entered" from="BlobbySkin" to="." method="_on_BlobbySkin_body_entered"]
[connection signal="got_grounded" from="BlobbyStateMachine" to="." method="_on_Blobby_got_grounded"]

View File

@ -4,19 +4,20 @@
[ext_resource path="res://src/Actors/Enemies/Beings/Caterpillar.gd" type="Script" id=2]
[ext_resource path="res://src/StateMachines/CaterpillarStateMachine.gd" type="Script" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 14.7108, 7.85442 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 15, 6 )
extents = Vector2( 13.3735, 3.49085 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 15, 12 )
extents = Vector2( 15, 8.61814 )
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 14.7108, 7.85442 )
[node name="Caterpillar" type="KinematicBody2D" groups=["harmful"]]
scale = Vector2( 0.747749, 0.572926 )
collision_layer = 2
collision_mask = 9
collision/safe_margin = 0.001
script = ExtResource( 2 )
[node name="enemy" type="Sprite" parent="."]
@ -31,10 +32,6 @@ rect = Rect2( -89, -10, 2, 20 )
process_parent = true
physics_process_parent = true
[node name="EnemyBody" type="CollisionShape2D" parent="."]
position = Vector2( -6.37697e-07, 4.36357 )
shape = SubResource( 1 )
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
position = Vector2( -7.5, 12 )
enabled = true
@ -66,21 +63,29 @@ position = Vector2( 0, -6.44095 )
collision_layer = 2
input_pickable = false
monitorable = false
priority = 1.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"]
position = Vector2( 0, 0.440949 )
position = Vector2( 0, -2.28618 )
shape = SubResource( 2 )
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
process_priority = -1
collision_layer = 2
collision_mask = 126
collision_mask = 127
input_pickable = false
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
position = Vector2( 0, 3.49085 )
shape = SubResource( 3 )
[node name="EnemyBody" type="CollisionShape2D" parent="."]
position = Vector2( -6.37697e-07, 4.36357 )
shape = SubResource( 1 )
[node name="StateMachine" type="Node2D" parent="."]
script = ExtResource( 3 )
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
[connection signal="body_entered" from="EnemySkin" to="." method="_on_EnemySkin_body_entered"]

View File

@ -6,7 +6,6 @@ export var speed := 80
export var acceleration := 80
func _ready() -> void:
set_physics_process(false)
$StompDetector.monitoring = !invincible

View File

@ -4,13 +4,13 @@
[ext_resource path="res://src/Actors/Enemies/Beings/DartingEnemy.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 15, 7.5 )
extents = Vector2( 15, 9 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 15, 4.51505 )
extents = Vector2( 14, 1.5 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 15.534, 10.0962 )
extents = Vector2( 15.534, 9.5 )
[node name="DartingEnemy" type="KinematicBody2D" groups=["harmful"]]
collision_layer = 2
@ -18,7 +18,6 @@ collision_mask = 9
script = ExtResource( 2 )
[node name="enemy" type="Sprite" parent="."]
position = Vector2( 0, -1.90735e-06 )
scale = Vector2( 0.286789, 0.276348 )
texture = ExtResource( 1 )
@ -29,8 +28,8 @@ rect = Rect2( -89, -10, 2, 20 )
process_parent = true
physics_process_parent = true
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
position = Vector2( -4.76837e-07, 4.5 )
[node name="EnemyBody" type="CollisionShape2D" parent="."]
position = Vector2( -4.76837e-07, 4 )
shape = SubResource( 1 )
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
@ -40,7 +39,7 @@ collision_layer = 2
input_pickable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"]
position = Vector2( 0, -1.044 )
position = Vector2( 0, -3.55905 )
shape = SubResource( 2 )
[node name="LedgeDetectorRays" type="Node2D" parent="."]
@ -63,12 +62,13 @@ collision_mask = 121
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
process_priority = -1
visible = false
collision_mask = 126
collision_layer = 2
collision_mask = 127
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
position = Vector2( -8.07794e-28, 1.5 )
position = Vector2( 0, 2.5 )
shape = SubResource( 3 )
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
[connection signal="body_entered" from="EnemySkin" to="." method="_on_EnemySkin_body_entered"]

View File

@ -1,13 +1,18 @@
extends Actor
class_name Enemy
var player_entered_stomp = false
func _on_StompDetector_body_entered(body: Node) -> void:
if !body.is_in_group("player"):
return
player_entered_stomp = true
var incoming_vel_vector: Vector2 = body.velocity.normalized()
print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(90):
print("too shallow entry")
body.die()
player_entered_stomp = false
return
signalManager.emit_signal("got_stomped")
remove_from_group("harmful")
@ -24,3 +29,7 @@ func _on_EnemySkin_area_entered(area:Area2D) -> void:
if area.is_in_group("harmful"):
get_node("EnemyBody").disabled = true
die()
func _on_EnemySkin_body_entered(body: Node) -> void:
if body.is_in_group("player") && !player_entered_stomp:
body.die()

View File

@ -187,10 +187,10 @@ graph_offset = Vector2( -333, -104 )
extents = Vector2( 10, 7.5 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 15, 5.12039 )
extents = Vector2( 11.4286, 5.12039 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 18.2143, 14.3338 )
[sub_resource type="RectangleShape2D" id=52]
extents = Vector2( 15.7143, 12.1429 )
[node name="Flyer" type="KinematicBody2D" groups=["frogfood", "harmful"]]
collision_layer = 258
@ -225,7 +225,6 @@ unique_name_in_owner = true
scale = Vector2( -1, 1 )
texture = ExtResource( 4 )
hframes = 2
frame = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="FlyerSprite"]
anims/RESET = SubResource( 33 )
@ -277,7 +276,6 @@ bias = 0.108
softness = 0.1
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
visible = false
modulate = Color( 0, 0.0392157, 1, 1 )
position = Vector2( 0, -1.90735e-06 )
scale = Vector2( 0.7, 0.7 )
@ -285,18 +283,19 @@ collision_layer = 2
input_pickable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"]
position = Vector2( -4.76837e-07, 1.56134 )
position = Vector2( 6.81196e-07, 1.56134 )
shape = SubResource( 2 )
[node name="EnemySkin" type="Area2D" parent="."]
process_priority = -1
visible = false
[node name="DangerousBlockArea" type="Node2D" parent="."]
scale = Vector2( 0.7, 0.7 )
collision_layer = 2
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
shape = SubResource( 3 )
[node name="Area2D" type="Area2D" parent="DangerousBlockArea" groups=["harmful"]]
collision_layer = 8
collision_mask = 3
[node name="CollisionShape2D" type="CollisionShape2D" parent="DangerousBlockArea/Area2D"]
position = Vector2( 5.10897e-07, -0.714285 )
shape = SubResource( 52 )
[node name="PatrolPath" type="Node2D" parent="."]

View File

@ -42,10 +42,10 @@ unique_name_in_owner = true
process_mode = 1
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 2
frame = 11
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 1
frame = 10
[node name="Blobby" parent="." instance=ExtResource( 7 )]
unique_name_in_owner = true

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=20 format=2]
[ext_resource path="res://assets/environment/decor/platform-plants.png" type="Texture" id=1]
[ext_resource path="res://src/Contraptions/Triggers/ElevatorButton.tscn" type="PackedScene" id=2]
@ -15,6 +15,7 @@
[ext_resource path="res://src/Environment/DropThroughPlatforms.tres" type="TileSet" id=13]
[ext_resource path="res://src/Platforms/FlyingPlatform.tscn" type="PackedScene" id=14]
[ext_resource path="res://src/Actors/Enemies/Beings/Caterpillar.tscn" type="PackedScene" id=15]
[ext_resource path="res://src/BenefitialObjects/Coin.tscn" type="PackedScene" id=16]
[sub_resource type="AnimationNodeStateMachinePlayback" id=4]
@ -80,10 +81,10 @@ wait_time = 20.0
unique_name_in_owner = true
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 2
frame = 3
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 1
frame = 2
[node name="Blobby" parent="." instance=ExtResource( 10 )]
unique_name_in_owner = true
@ -179,6 +180,12 @@ scale = Vector2( 0.75, 1 )
autoplay = "Path"
anims/Path = SubResource( 6 )
[node name="Coin" parent="." instance=ExtResource( 16 )]
position = Vector2( 383, -31 )
[node name="Coin2" parent="." instance=ExtResource( 16 )]
position = Vector2( 496, -337 )
[connection signal="body_exited" from="Blobby/BlobbySkin" to="Blobby" method="_on_BlobbySkin_body_exited"]
[editable path="SignalManager"]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -44,10 +44,10 @@ wait_time = 20.0
unique_name_in_owner = true
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 2
frame = 6
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 6
frame = 10
[node name="Blobby" parent="." instance=ExtResource( 15 )]
unique_name_in_owner = true

View File

@ -89,10 +89,10 @@ wait_time = 20.0
[node name="BlobbyCam" parent="." instance=ExtResource( 6 )]
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 7
frame = 1
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 12
frame = 6
[node name="Blobby" parent="." instance=ExtResource( 12 )]
unique_name_in_owner = true

View File

@ -1,6 +1,14 @@
extends Node2D
extends Node
onready var slide_friction = 2
onready var tween_values = []
export var x_target = 0
export var y_target = 0
export var speed = 32
var time
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
@ -8,9 +16,20 @@ onready var slide_friction = 2
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$anim.play("Horizontal")
var start = Vector2(0,0)
var end = Vector2(x_target, y_target)
tween_values.append(start)
tween_values.append(end)
time = start.distance_to(end)/speed
_start_tween()
func _start_tween():
$FlyTween.interpolate_property($PlatformBody, "position",
tween_values[0], tween_values[1], time,
Tween.TRANS_QUAD, Tween.EASE_IN_OUT)
$FlyTween.start()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
func _on_FlyTween_tween_completed(object: Object, key: NodePath) -> void:
tween_values.invert()
_start_tween()

View File

@ -1,59 +1,27 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/Platforms/FlyingPlatform.gd" type="Script" id=1]
[ext_resource path="res://assets/contraption/floating_platform_test.png" type="Texture" id=2]
[sub_resource type="Animation" id=3]
resource_name = "Path"
length = 6.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("KinematicBody2D:position")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 3 ),
"transitions": PoolRealArray( 1, 0.965936 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( -48, -40 ) ]
}
[sub_resource type="Animation" id=4]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("KinematicBody2D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ) ]
}
[node name="FlyingPlatform" type="Node2D"]
script = ExtResource( 1 )
[node name="anim" type="AnimationPlayer" parent="."]
playback_process_mode = 0
anims/Path = SubResource( 3 )
anims/RESET = SubResource( 4 )
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
collision_layer = 8
[node name="PlatformBody" type="KinematicBody2D" parent="."]
collision_layer = 16
collision_mask = 0
motion/sync_to_physics = true
[node name="Sprite" type="Sprite" parent="KinematicBody2D"]
[node name="Sprite" type="Sprite" parent="PlatformBody"]
position = Vector2( 0, 8 )
texture = ExtResource( 2 )
vframes = 8
frame = 1
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="KinematicBody2D"]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="PlatformBody"]
position = Vector2( 0, 4 )
scale = Vector2( 4, 0.4 )
polygon = PoolVector2Array( -10, -10, 10, -10, 9.5, 0, 9.25, 5, -9.25, 5, -9.5, 0 )
[node name="FlyTween" type="Tween" parent="."]
[connection signal="tween_completed" from="FlyTween" to="." method="_on_FlyTween_tween_completed"]