Group based area/body detection, walljump fix

This commit is contained in:
Jakob Feldmann 2022-06-02 19:18:10 +02:00
parent 6605221398
commit 1a45a0ca84
19 changed files with 92 additions and 45 deletions

View File

@ -116,7 +116,7 @@ quality/intended_usage/framebuffer_allocation.mobile=0
quality/filters/use_nearest_mipmap_filter=true
quality/filters/msaa=1
environment/default_environment="res://default_env.tres"
quality/2d/use_pixel_snap=true
quality/2d/use_pixel_snap=false
environment/2d/use_nvidia_rect_flicker_workaround=true
environment/stretch/aspect="ignore"
environment/intended_usage/framebuffer_allocation.mobile=0

View File

@ -20,13 +20,15 @@ onready var camera = $Camera2D
# TODO This is the worst thing since... you know
# When the Enemy stomp AREA enters the enemy collision area -> stomp
func _on_BlobbySkin_area_entered(area: Area2D) -> void:
if area.name == "StompDetector":
if area.is_in_group("weakpoint"):
velocity = calculate_stomp_velocity(velocity, stomp_feedback)
if area.is_in_group("harmful"):
die()
# When the Enemy collision BODY enters the enemy collision area -> die
func _on_BlobbySkin_body_entered(body: Node) -> void:
if body.name == "EnemyBody":
if body.is_in_group("harmful"):
die()
@ -245,19 +247,13 @@ func calculate_fall_velocity(
func calculate_wallslide_velocity(
linear_velocity: Vector2, delta: float, direction: Vector2
) -> Vector2:
# Walljump mechanics
# Walljump mechanicsdd
if is_correct_walljump_input(direction):
linear_velocity.x = PhysicsFunc.two_step_euler(
linear_velocity.x,
acceleration_force["walljump"].x * direction.x,
mass,
delta
0, acceleration_force["walljump"].x * direction.x, mass, delta
)
linear_velocity.y += PhysicsFunc.two_step_euler(
linear_velocity.y,
acceleration_force["walljump"].y * -1,
mass,
delta
linear_velocity.y = PhysicsFunc.two_step_euler(
0, acceleration_force["walljump"].y * -1, mass, delta
)
elif is_correct_airstrafe_input():
linear_velocity.x = PhysicsFunc.two_step_euler(

View File

@ -17,7 +17,7 @@ texture = ExtResource( 1 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="Player"]
[node name="BlobbyBody" type="CollisionPolygon2D" parent="."]
[node name="BlobbyBody" type="CollisionPolygon2D" parent="." groups=["player"]]
polygon = PoolVector2Array( -6.7, -3.273, -2.676, -7.3, 3.939, -7.3, 8, -1.768, 8, 4.912, 4.944, 8.5, -1.03623, 8.5, -4.213, 8.5, -6.7, 6.089 )
[node name="Camera2D" type="Camera2D" parent="."]
@ -39,7 +39,7 @@ script = ExtResource( 2 )
[node name="ShiftTween" type="Tween" parent="Camera2D"]
[node name="BlobbySkin" type="Area2D" parent="."]
[node name="BlobbySkin" type="Area2D" parent="." groups=["player"]]
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BlobbySkin"]

View File

@ -12,7 +12,7 @@ func _ready() -> void:
func _on_StompDetector_body_entered(body: Node) -> void:
if body.global_position.y > get_node("StompDetector").global_position.y:
return
get_node("EnemyShape").disabled = true
get_node("EnemyBody").disabled = true
die()

View File

@ -9,7 +9,7 @@ extents = Vector2( 2.72463, 1.17848 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 15.4794, 6.68174 )
[node name="Enemy" type="KinematicBody2D"]
[node name="Enemy" type="KinematicBody2D" groups=["harmful"]]
collision_layer = 2
collision_mask = 9
script = ExtResource( 2 )
@ -26,12 +26,12 @@ rect = Rect2( -89, -10, 2, 20 )
process_parent = true
physics_process_parent = true
[node name="EnemyBody" type="CollisionShape2D" parent="."]
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
position = Vector2( 0, 6.48802 )
scale = Vector2( 5.68128, 5.29182 )
shape = SubResource( 1 )
[node name="StompDetector" type="Area2D" parent="."]
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
modulate = Color( 0, 0.0392157, 1, 1 )
position = Vector2( 0, -6.44095 )
collision_layer = 2

View File

@ -23,7 +23,7 @@ var acceleration_force := {
"walk": Vector2(2000, 68000),
"idle": Vector2(2000, 68000),
"run": Vector2(2000, 68000),
"walljump": Vector2(30000, 58000),
"walljump": Vector2(50000, 58000),
"air_strafe": Vector2(20000, 0)
}
# Gravity as m/s^2

View File

@ -117,8 +117,6 @@ func _get_transition(_delta):
parent.is_touching_wall_completely()
&& parent.velocity.y <= parent.wallslide_threshold
):
# TODO Wallslide might be too long
# TODO Player is stuck to the wall
new_state = states.wallslide
# Begins coyote time only if walking from ledge
elif [states.walk, states.run].has(self.state) && !coyote_hanging:
@ -144,8 +142,6 @@ func _get_transition(_delta):
coyote_hanging = false
else:
# TODO How does this apply to enviornment induced movement?
# TODO Can get from platform by jumping often while platform has same direction
new_state = states.idle
coyote_hanging = false
if new_state != self.state:

View File

@ -1,11 +1,11 @@
tool
extends Area2D
onready var anim_player: AnimationPlayer = $AnimationPlayer
export var next_scene: PackedScene
func _get_configuration_warning() -> String:
return "The next scene property can't be empty" if not next_scene else ""
@ -16,5 +16,5 @@ func teleport() -> void:
get_tree().change_scene_to(next_scene)
func _on_body_entered(body: Node) -> void:
func _on_body_entered(_body: Node) -> void:
teleport()

View File

@ -0,0 +1,18 @@
extends Area2D
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func _physics_process(delta: float) -> void:
position.x += 30 * delta
func _on_Bullet_body_entered(_body: Node) -> void:
queue_free()

View File

@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/environment/blocks/approx build block.png" type="Texture" id=1]
[ext_resource path="res://src/HarmfulObjects/Bullet.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 1.51498, 5.05697 )
[node name="Bullet" type="Area2D" groups=["harmful"]]
rotation = 1.5708
collision_layer = 64
collision_mask = 59
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( -0.00644289, 0.0188824 )
scale = Vector2( 0.0919913, 0.313283 )
texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_Bullet_body_entered"]

View File

@ -4,7 +4,7 @@
[ext_resource path="res://assets/meta/tileset.png" type="Texture" id=2]
[ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4]
[ext_resource path="res://src/Neutral Objects/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/NeutralObjects/Coin.tscn" type="PackedScene" id=5]
[sub_resource type="ConvexPolygonShape2D" id=1]
points = PoolVector2Array( 0, 0, 80, 0, 80, 80, 0, 80 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://assets/meta/tileset.tres" type="TileSet" id=2]
[ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4]
[ext_resource path="res://src/Neutral Objects/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/NeutralObjects/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/UserInterface/Buttons/UserInterface.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UserInterface/Portal.tscn" type="PackedScene" id=8]

View File

@ -4,7 +4,7 @@
[ext_resource path="res://assets/meta/tileset.png" type="Texture" id=2]
[ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4]
[ext_resource path="res://src/Neutral Objects/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/NeutralObjects/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/UserInterface/Buttons/UserInterface.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UserInterface/Portal.tscn" type="PackedScene" id=7]
[ext_resource path="res://src/UserInterface/Screens/LevelEndScreen.tscn" type="PackedScene" id=8]

View File

@ -1,10 +1,12 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2]
[ext_resource path="res://src/Contraptions/Platform/Spring.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/Environment/Background.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/HarmfulObjects/Bullet.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UserInterface/Buttons/UI.tscn" type="PackedScene" id=7]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )
@ -47,6 +49,8 @@ __meta__ = {
"_edit_vertical_guides_": [ 2880.0 ]
}
[node name="UserInterface" parent="." instance=ExtResource( 7 )]
[node name="Simple Background" parent="." instance=ExtResource( 4 )]
layer = -1
@ -67,9 +71,6 @@ position = Vector2( 50.7867, 604.063 )
position = Vector2( 331.785, 601.665 )
scale = Vector2( 1.88002, 1 )
[node name="Spring" parent="Spring4" instance=ExtResource( 3 )]
position = Vector2( 206.918, 601.665 )
[node name="Track" parent="." instance=ExtResource( 5 )]
position = Vector2( 422.501, 601.665 )
scale = Vector2( 2.83999, 0.56 )
@ -77,6 +78,8 @@ scale = Vector2( 2.83999, 0.56 )
[node name="KinematicBody2D" parent="Track" index="0"]
position = Vector2( 8, 0 )
[node name="Bullet" parent="." instance=ExtResource( 6 )]
position = Vector2( 237.856, 601.801 )
[editable path="Spring4"]
[editable path="Spring4/Spring"]
[editable path="Track"]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://assets/neutral object/coin.png" type="Texture" id=1]
[ext_resource path="res://src/Neutral Objects/Coin.gd" type="Script" id=2]
[ext_resource path="res://src/NeutralObjects/Coin.gd" type="Script" id=2]
[sub_resource type="CircleShape2D" id=1]
radius = 34.0147

View File

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UserInterface/Buttons/UserInterface.tscn" type="PackedScene" id=1]
[node name="UserInterface" type="CanvasLayer"]
[node name="UserInterface" parent="." instance=ExtResource( 1 )]

View File

@ -1,22 +1,26 @@
extends Control
# Smart ist es die notwendigen Resourcen vor dem Skriptstart zu laden
onready var scene_tree: = get_tree()
onready var scene_tree := get_tree()
onready var pause_overlay: ColorRect = get_node("PauseOverlay")
onready var score: Label = get_node("Label")
onready var pause_title: Label = get_node("PauseOverlay/Title")
var paused: = false setget set_paused
var paused := false setget set_paused
func _ready():
PlayerData.connect("score_updated", self, "update_interface")
PlayerData.connect("player_died", self, "_on_PlayerData_player_died")
update_interface()
# TODO Main Menu doesnt work when opened from here
func _on_PlayerData_player_died() -> void:
self.paused = true
pause_title.text = "You lost"
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("pause") and pause_title.text != "You lost":
#not oder ! schaltet einen boolean um
@ -24,9 +28,11 @@ func _unhandled_input(event: InputEvent) -> void:
self.paused = not paused
scene_tree.set_input_as_handled()
func update_interface() -> void:
score.text = "Score: %s" % PlayerData.score
func set_paused(value: bool) -> void:
paused = value
scene_tree.paused = value

View File

@ -49,7 +49,7 @@ margin_top = 84.0
margin_right = 222.0
margin_bottom = 164.0
text = "Main Menu"
next_scene_path = "res://src/Screens/MainScreen.tscn"
next_scene_path = "res://src/UserInterface/Screens/MainScreen.tscn"
[node name="QuitButton" parent="PauseOverlay/VBoxContainer" instance=ExtResource( 2 )]
anchor_left = 0.0
@ -76,11 +76,9 @@ __meta__ = {
[node name="Label" type="Label" parent="."]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -180.0
margin_bottom = 45.0
margin_left = -84.0
margin_right = -5.0
margin_bottom = 24.0
rect_scale = Vector2( 0.590909, 0.627907 )
text = "Score: %s"
align = 2
__meta__ = {
"_edit_use_anchors_": false
}