Teleporters and some helper methods for getting safe and death tiles

master
Wynd 2024-09-17 00:49:40 +03:00
parent 3d59128b0b
commit c8eaba5591
8 changed files with 133 additions and 35 deletions

View File

@ -2,7 +2,7 @@ class_name Player
extends CharacterBody2D
@onready var raycast: RayCast2D = $RayCast2D
@onready var tile_map: TileMapLayer = $"../TileMapLayer"
@onready var tile_map: MainLevel = $"../TileMap"
@export var speed: float = 40
@export var respawn_point: Marker2D
@ -14,7 +14,6 @@ var should_move = false
var input_dir: Vector2
func _ready():
print(tile_map)
_respawn()
pass
@ -59,9 +58,8 @@ func _try_move():
)
func _post_movement_check():
var current_tile: Vector2i = tile_map.local_to_map(tile_map.to_local(global_position))
var tile_data: TileData = tile_map.get_cell_tile_data(current_tile)
if tile_data and tile_data.get_custom_data("death"):
var is_death_tile = tile_map.is_death_tile(global_position)
if is_death_tile:
die()
func die():

View File

@ -5,6 +5,7 @@ extends PuzzleElement
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var audio_player: AudioStreamPlayer2D = $AudioStreamPlayer2D
@onready var manager: BoxPuzzle = $"../"
@onready var tile_map: MainLevel = get_tree().root.get_child(0).get_node("TileMap")
const TILE_SIZE = 8
@ -27,6 +28,9 @@ func interact(player: Player):
raycast.target_position = player.input_dir * 8
raycast.force_raycast_update()
if tile_map.is_death_tile(global_position + raycast.target_position):
return
var collider = raycast.get_collider()
var is_switch = collider is BoxSwitch
if raycast.is_colliding() and not is_switch:

View File

@ -0,0 +1,34 @@
class_name MainLevel
extends Node
func _get_tile_data(position: Vector2):
var results = []
for layer in self.get_children():
if not (layer as TileMapLayer).enabled:
continue
var current_tile: Vector2i = layer.local_to_map(layer.to_local(position))
var tile_data: TileData = layer.get_cell_tile_data(current_tile)
if tile_data:
results.push_back(tile_data)
return results
func is_walkable_tile(position: Vector2):
var results = _get_tile_data(position)
for tile_data in results:
if (tile_data as TileData).get_custom_data("walkable"):
return true
return false
func is_death_tile(position: Vector2):
var is_death_tile = false
var results = _get_tile_data(position)
for tile_data in results:
if (tile_data as TileData).get_custom_data("death"):
is_death_tile = true
break;
if is_death_tile:
for tile_data in results:
if (tile_data as TileData).get_custom_data("walkable"):
is_death_tile = false
break;
return is_death_tile

View File

@ -1,11 +1,15 @@
extends PuzzleManager
#@onready var demo_puzzle = $DemoGravePuzzle1
@onready var next_room_fog = $NextRoomFog
@export var next_room_fog: TileMapLayer
@export var next_room_fog_2: TileMapLayer
var mark_as_finished = false
func _process(delta):
if is_room_finished():
pass
if is_room_finished() and not mark_as_finished:
next_room_fog_2.queue_free()
mark_as_finished = true
pass
func _on_demo_grave_puzzle_complete():

View File

@ -0,0 +1,8 @@
extends Area2D
@export var teleport_marker: Marker2D
func _on_body_entered(body):
if body is Player:
body.global_position = teleport_marker.global_position

View File

@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://dk5oyn3pi1soj"]
[ext_resource type="Script" path="res://puzzles/teleporter/teleporter.gd" id="1_0ext0"]
[ext_resource type="Texture2D" uid="uid://cbuibrshdpkm1" path="res://scenes/assets/tileset.png" id="1_yn5l0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kuq27"]
size = Vector2(6, 5)
[node name="WallOpening" type="Area2D"]
script = ExtResource("1_0ext0")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_yn5l0")
hframes = 8
vframes = 8
frame = 14
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 0.5)
shape = SubResource("RectangleShape2D_kuq27")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -18,11 +18,12 @@ texture_region_size = Vector2i(8, 8)
4:1/0 = 0
4:1/0/custom_data_0 = true
5:1/0 = 0
5:1/0/custom_data_0 = true
6:1/0 = 0
6:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
6:1/0/custom_data_0 = true
7:1/0 = 0
7:0/0 = 0
7:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
7:0/0/custom_data_0 = true
1:1/0 = 0
0:1/animation_columns = 1
0:1/animation_speed = 2.0
@ -31,14 +32,14 @@ texture_region_size = Vector2i(8, 8)
0:1/0 = 0
2:0/animation_mode = 1
2:0/0 = 0
2:0/0/probability = 0.5
2:0/0/probability = 0.2
2:0/0/custom_data_0 = true
3:0/animation_columns = 1
3:0/animation_mode = 1
3:0/animation_frame_0/duration = 1.0
3:0/animation_frame_1/duration = 1.0
3:0/0 = 0
3:0/0/probability = 0.2
3:0/0/probability = 0.05
3:0/0/custom_data_0 = true
0:6/0 = 0
1:6/0 = 0
@ -49,7 +50,6 @@ texture_region_size = Vector2i(8, 8)
[resource]
tile_size = Vector2i(8, 8)
physics_layer_0/collision_layer = 1
physics_layer_1/collision_layer = 1
custom_data_layer_0/name = "walkable"
custom_data_layer_0/type = 1
custom_data_layer_1/name = "death"

File diff suppressed because one or more lines are too long