look like it works now, i did a workaround, dunno what this issue was 💀

This commit is contained in:
Tabby 2025-08-11 23:34:05 +10:00
parent 7584cf0b19
commit 8c0860a840
8 changed files with 64 additions and 44 deletions

View file

@ -3,6 +3,8 @@ extends CharacterBody2D
const SPEED = 170.0 const SPEED = 170.0
const JUMP_VELOCITY = -400.0 const JUMP_VELOCITY = -400.0
var ready_to_door : bool = true
@export var doorBox : Area2D
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
@ -16,22 +18,33 @@ func _physics_process(delta: float) -> void:
# Get the input direction and handle the movement/deceleration. # Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions. # As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_vector("left","right","up","down") var direction := Input.get_vector("left","right","up","down")
if direction: if direction and Router.player_mode:
velocity = direction * SPEED velocity = direction * SPEED
else: else:
velocity = velocity.move_toward(Vector2(0,0), SPEED) velocity = velocity.move_toward(Vector2(0,0), SPEED)
move_and_slide() move_and_slide()
if !doorBox.has_overlapping_areas():
ready_to_door = true
func _on_door_box_area_entered(area: Area2D) -> void: func _on_door_box_area_entered(area: Area2D) -> void:
print(area.name) print(area.name)
if area.name == "DoorIn": if ready_to_door:
global_position = area.get_parent().get_parent().door_out_node.global_position if area.name == "DoorIn":
Router.activate_seg.emit(Router.cur_id + 1) global_position = area.get_parent().get_parent().door_out_node.global_position
# +1 seg #Router.activate_seg.emit(Router.cur_id + 1)
elif area.name == "DoorOut": if (area.get_parent().get_parent().prev_seg):
global_position = area.get_parent().get_parent().door_in_node.global_position Router.activate_seg.emit(area.get_parent().get_parent().prev_seg.seg_id)
Router.activate_seg.emit(Router.cur_id - 1) ready_to_door = false
# -1 seg # +1 seg
elif area.name == "DoorOut":
global_position = area.get_parent().get_parent().door_in_node.global_position
if (area.get_parent().get_parent().this_seg):
Router.activate_seg.emit(area.get_parent().get_parent().this_seg.seg_id)
ready_to_door = false
#Router.activate_seg.emit(Router.cur_id - 1)
# -1 seg

View file

@ -1,9 +1,11 @@
extends Camera2D extends Camera2D
var target : Node2D #var target : Node2D
@export var temp_segment : Node2D #@export var temp_segment : Node2D
@export var snake_line : Line2D @export var snake_line : Line2D
@export var player : Node2D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
pass # Replace with function body. pass # Replace with function body.
@ -11,22 +13,21 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
if (Input.is_action_just_pressed("test_switch_cam")):
if(target):
target = null
else:
target = temp_segment
if target:
if Router.player_mode:
# TODO FIX # TODO FIX
#position = lerp(position, target.position, 0.6 * delta) #position = lerp(position, target.position, 0.6 * delta)
#zoom = lerp(zoom, Vector2(1,1),0.6 * delta) #zoom = lerp(zoom, Vector2(1,1),0.6 * delta)
position = target.position #position = Router.current_seg.position
position = player.global_position
zoom = Vector2(1,1) zoom = Vector2(1,1)
snake_line.modulate = Color(1,1,1,0.5) snake_line.modulate = Color(1,1,1,1)
z_index = 0 z_index = 0
snake_line.z_index = 9
else: else:
position = Vector2(0,0) position = Vector2(0,0)
zoom = Vector2(0.05,0.05) zoom = Vector2(0.05,0.05)
snake_line.modulate = Color(1,1,1,1) snake_line.modulate = Color(1,1,1,1)
snake_line.z_index = 11
z_index = 1 z_index = 1

View file

@ -9,10 +9,11 @@ radius = 16.0
[sub_resource type="CircleShape2D" id="CircleShape2D_q1ksn"] [sub_resource type="CircleShape2D" id="CircleShape2D_q1ksn"]
radius = 7.07107 radius = 7.07107
[node name="Braincell" type="CharacterBody2D"] [node name="Braincell" type="CharacterBody2D" node_paths=PackedStringArray("doorBox")]
z_index = 15 z_index = 15
motion_mode = 1 motion_mode = 1
script = ExtResource("1_q1ksn") script = ExtResource("1_q1ksn")
doorBox = NodePath("doorBox")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_wv6rk") texture = ExtResource("2_wv6rk")

View file

@ -21,19 +21,21 @@ func _ready() -> void:
target_pos = position target_pos = position
start_pos = position start_pos = position
get_new_target() get_new_target()
become_real()
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
move_progress += delta * snake_speed move_progress += delta * snake_speed
if Input.is_action_just_pressed("left"): if(!Router.player_mode):
want_direction = Vector2.LEFT if Input.is_action_just_pressed("left"):
elif Input.is_action_just_pressed("right"): want_direction = Vector2.LEFT
want_direction = Vector2.RIGHT elif Input.is_action_just_pressed("right"):
elif Input.is_action_just_pressed("up"): want_direction = Vector2.RIGHT
want_direction = Vector2.UP elif Input.is_action_just_pressed("up"):
elif Input.is_action_just_pressed("down"): want_direction = Vector2.UP
want_direction = Vector2.DOWN elif Input.is_action_just_pressed("down"):
want_direction = Vector2.DOWN
position = lerp(start_pos,target_pos,move_progress) position = lerp(start_pos,target_pos,move_progress)
if move_progress >= 1: if move_progress >= 1:
get_new_target() get_new_target()
@ -55,7 +57,7 @@ func become_real():
pass pass
func become_fake(): func become_fake():
z_index = 0 #z_index = 0
modulate = Color.DIM_GRAY #modulate = Color.DIM_GRAY
collision_layer = 2 #collision_layer = 2
pass pass

View file

@ -7,7 +7,7 @@
[ext_resource type="Texture2D" uid="uid://cay1k1dp8yf12" path="res://assets/door.png" id="4_34t3n"] [ext_resource type="Texture2D" uid="uid://cay1k1dp8yf12" path="res://assets/door.png" id="4_34t3n"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_08kyq"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_08kyq"]
size = Vector2(16, 64) size = Vector2(8, 64)
[node name="SnakeSegment" type="AnimatableBody2D" node_paths=PackedStringArray("door")] [node name="SnakeSegment" type="AnimatableBody2D" node_paths=PackedStringArray("door")]
script = ExtResource("1_3ulhv") script = ExtResource("1_3ulhv")
@ -36,7 +36,7 @@ position = Vector2(160, 0)
position = Vector2(-22, 0) position = Vector2(-22, 0)
[node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArm/Door/DoorIn"] [node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArm/Door/DoorIn"]
position = Vector2(14, 0) position = Vector2(10, 0)
shape = SubResource("RectangleShape2D_08kyq") shape = SubResource("RectangleShape2D_08kyq")
[node name="DoorOut" type="Area2D" parent="DoorArm/Door"] [node name="DoorOut" type="Area2D" parent="DoorArm/Door"]
@ -44,7 +44,7 @@ position = Vector2(22, 0)
rotation = 3.14159 rotation = 3.14159
[node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArm/Door/DoorOut"] [node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArm/Door/DoorOut"]
position = Vector2(14, 3.54925e-05) position = Vector2(10, 2.53518e-05)
shape = SubResource("RectangleShape2D_08kyq") shape = SubResource("RectangleShape2D_08kyq")
[node name="Sprite2D" type="Sprite2D" parent="DoorArm/Door"] [node name="Sprite2D" type="Sprite2D" parent="DoorArm/Door"]

View file

@ -4,6 +4,7 @@ signal activate_seg(int)
var current_seg : Node2D var current_seg : Node2D
var cur_id : int = 0 var cur_id : int = 0
var player_mode : bool = false
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
@ -12,4 +13,5 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
pass if (Input.is_action_just_pressed("test_switch_cam")):
player_mode = !player_mode

View file

@ -33,13 +33,14 @@ func _process(delta: float) -> void:
func activate_segment(act_segment : int): func activate_segment(act_segment : int):
Router.current_seg = segements[act_segment] Router.current_seg = segements[act_segment]
Router.cur_id = act_segment Router.cur_id = act_segment
player.reparent(Router.current_seg) player.call_deferred("reparent",Router.current_seg)
for i in segements.size(): #player.reparent(Router.current_seg)
if act_segment == i: #for i in segements.size():
segements[i].become_real() #if act_segment == i:
#segements[i].become_real()
else: #
segements[i].become_fake() #else:
#segements[i].become_fake()
func redraw_line(): func redraw_line():

View file

@ -42,8 +42,8 @@ joint_mode = 2
begin_cap_mode = 2 begin_cap_mode = 2
end_cap_mode = 2 end_cap_mode = 2
[node name="Camera2D" type="Camera2D" parent="." node_paths=PackedStringArray("temp_segment", "snake_line")] [node name="Camera2D" type="Camera2D" parent="." node_paths=PackedStringArray("snake_line", "player")]
zoom = Vector2(0.05, 0.05) zoom = Vector2(0.05, 0.05)
script = ExtResource("5_ykrsh") script = ExtResource("5_ykrsh")
temp_segment = NodePath("../Snake/SegementHolder/SnakeSegment")
snake_line = NodePath("../Snake/Line2D") snake_line = NodePath("../Snake/Line2D")
player = NodePath("../Snake/SegementHolder/SnakeSegment/Braincell")