summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-12-30 11:41:09 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-12-30 11:41:14 +0100
commit24a8f1b156ea92e7b0ad60052521e1430a77e13f (patch)
treee2e21d5015e8003e6ba40dc85a19bc9d523e249f
parent474ef692613f298ab05bbb65ad85625f178b63cc (diff)
fix drop through wall bugHEADmain
-rw-r--r--character/character.gd31
-rw-r--r--character/character.tscn4
-rw-r--r--player/opponent.gd2
-rw-r--r--player/player.gd2
-rw-r--r--player/player.tscn6
-rw-r--r--stage/tile_map_layer.gd15
-rw-r--r--stage/tile_map_layer.tscn4
-rw-r--r--ui/start_screen.gd2
8 files changed, 48 insertions, 18 deletions
diff --git a/character/character.gd b/character/character.gd
index ef18bbc..764c02e 100644
--- a/character/character.gd
+++ b/character/character.gd
@@ -150,21 +150,28 @@ func is_on_floor() -> bool:
return $RayDownLeft.is_colliding() or $RayDownRight.is_colliding()
-func is_on_ledge() -> bool:
- return true
- pass
- # TODO: add two more down Rays
- # and up rays for is_below wall and is_below_ledge
- # to fix falling through wall
- # funktion im base-game aber auch gar nicht vorhanden:)
+func _is_on_ledge() -> bool:
+ var is_on := false
+
+ if $RayDownLeft.is_colliding():
+ is_on = is_on or $RayDownLeft.get_collider().is_ledge($RayDownLeft.get_collision_point())
+
+ if $RayDownRight.is_colliding():
+ is_on = is_on or $RayDownRight.get_collider().is_ledge($RayDownRight.get_collision_point())
+
+ return is_on
-func is_on_bottom_floor() -> bool:
- var stage: Stage = get_tree().current_scene
- var map: TileMapLayer = get_tree().get_first_node_in_group("tilemap")
- var bottom = position.y + (get_sprite_size().y / 2) + map.tile_set.tile_size.y
+func is_on_solid_floor() -> bool:
+ var is_on := false
+
+ if $RayDownLeft.is_colliding():
+ is_on = is_on or $RayDownLeft.get_collider().is_wall($RayDownLeft.get_collision_point())
+
+ if $RayDownRight.is_colliding():
+ is_on = is_on or $RayDownRight.get_collider().is_wall($RayDownRight.get_collision_point())
- return bottom >= stage.get_world_boundaries()[Vector2.DOWN]
+ return is_on
func is_below_ceiling() -> bool:
diff --git a/character/character.tscn b/character/character.tscn
index 7fb9776..4c163cd 100644
--- a/character/character.tscn
+++ b/character/character.tscn
@@ -25,11 +25,11 @@ shape = SubResource("RectangleShape2D_wfm33")
[node name="RayLeft" type="RayCast2D" parent="."]
target_position = Vector2(-8, 0)
-collision_mask = 256
+collision_mask = 768
[node name="RayRight" type="RayCast2D" parent="."]
target_position = Vector2(8, 0)
-collision_mask = 256
+collision_mask = 768
[node name="RayUpLeft" type="RayCast2D" parent="."]
position = Vector2(-6, 0)
diff --git a/player/opponent.gd b/player/opponent.gd
index 7fc2ebf..de967fe 100644
--- a/player/opponent.gd
+++ b/player/opponent.gd
@@ -51,7 +51,7 @@ func _on_vertical_timer_timeout() -> void:
if randi_range(0, 100) > 75 and is_below_ledge():
await jump()
- elif randi_range(0, 100) > 50 and not is_on_bottom_floor():
+ elif randi_range(0, 100) > 50 and not is_on_solid_floor():
await fall()
$VerticalTimer.start()
diff --git a/player/player.gd b/player/player.gd
index 9d1d6ee..86284ae 100644
--- a/player/player.gd
+++ b/player/player.gd
@@ -27,7 +27,7 @@ func _process(_delta: float) -> void:
if Input.is_action_pressed("ui_up"):
jump()
if Input.is_action_pressed("ui_down"):
- if not is_on_bottom_floor():
+ if not is_on_solid_floor():
fall()
if not is_on_floor():
diff --git a/player/player.tscn b/player/player.tscn
index 4e0417f..8c86475 100644
--- a/player/player.tscn
+++ b/player/player.tscn
@@ -19,6 +19,12 @@ collision_mask = 18
[node name="Camera2D" type="Camera2D" parent="." index="2"]
+[node name="RayDownLeft" parent="." index="7"]
+position = Vector2(-5, 0)
+
+[node name="RayDownRight" parent="." index="8"]
+position = Vector2(5, 0)
+
[node name="ShoeItemPickUp" type="AudioStreamPlayer" parent="." index="9"]
stream = ExtResource("3_o0r1j")
diff --git a/stage/tile_map_layer.gd b/stage/tile_map_layer.gd
new file mode 100644
index 0000000..456cfaa
--- /dev/null
+++ b/stage/tile_map_layer.gd
@@ -0,0 +1,15 @@
+extends TileMapLayer
+
+
+func is_wall(collision_point: Vector2):
+ var map_coordinates := local_to_map(collision_point)
+ var tile = get_cell_tile_data(map_coordinates)
+
+ return tile.get_collision_polygons_count(0) > 0
+
+
+func is_ledge(collision_point: Vector2):
+ var map_coordinates := local_to_map(collision_point)
+ var tile = get_cell_tile_data(map_coordinates)
+
+ return tile.get_collision_polygons_count(1) > 0
diff --git a/stage/tile_map_layer.tscn b/stage/tile_map_layer.tscn
index 4e9583e..3e2ce48 100644
--- a/stage/tile_map_layer.tscn
+++ b/stage/tile_map_layer.tscn
@@ -1,6 +1,7 @@
-[gd_scene load_steps=4 format=3 uid="uid://dfioemvleakyt"]
+[gd_scene load_steps=5 format=3 uid="uid://dfioemvleakyt"]
[ext_resource type="Texture2D" uid="uid://4sbg8fnguw48" path="res://stage/assets/tileset-01.png" id="1_kgkhx"]
+[ext_resource type="Script" path="res://stage/tile_map_layer.gd" id="2_m3i7n"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_kmxxx"]
texture = ExtResource("1_kgkhx")
@@ -124,3 +125,4 @@ sources/0 = SubResource("TileSetAtlasSource_kmxxx")
[node name="TileMapLayer" type="TileMapLayer"]
texture_filter = 1
tile_set = SubResource("TileSet_277cy")
+script = ExtResource("2_m3i7n")
diff --git a/ui/start_screen.gd b/ui/start_screen.gd
index 418e407..c6a165e 100644
--- a/ui/start_screen.gd
+++ b/ui/start_screen.gd
@@ -5,7 +5,7 @@ func _ready() -> void:
%CountdownTimer.start()
-func _process(delta: float) -> void:
+func _process(_delta: float) -> void:
%CountdownLabel.text = "%.1f" % %CountdownTimer.time_left