look like it works now, i did a workaround, dunno what this issue was 💀
This commit is contained in:
parent
7584cf0b19
commit
8c0860a840
8 changed files with 64 additions and 44 deletions
31
braincell.gd
31
braincell.gd
|
|
@ -3,6 +3,8 @@ extends CharacterBody2D
|
|||
|
||||
const SPEED = 170.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
var ready_to_door : bool = true
|
||||
@export var doorBox : Area2D
|
||||
|
||||
|
||||
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.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
|
||||
var direction := Input.get_vector("left","right","up","down")
|
||||
if direction:
|
||||
if direction and Router.player_mode:
|
||||
velocity = direction * SPEED
|
||||
else:
|
||||
velocity = velocity.move_toward(Vector2(0,0), SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
if !doorBox.has_overlapping_areas():
|
||||
ready_to_door = true
|
||||
|
||||
|
||||
func _on_door_box_area_entered(area: Area2D) -> void:
|
||||
print(area.name)
|
||||
if area.name == "DoorIn":
|
||||
global_position = area.get_parent().get_parent().door_out_node.global_position
|
||||
Router.activate_seg.emit(Router.cur_id + 1)
|
||||
# +1 seg
|
||||
elif area.name == "DoorOut":
|
||||
global_position = area.get_parent().get_parent().door_in_node.global_position
|
||||
Router.activate_seg.emit(Router.cur_id - 1)
|
||||
# -1 seg
|
||||
if ready_to_door:
|
||||
if area.name == "DoorIn":
|
||||
global_position = area.get_parent().get_parent().door_out_node.global_position
|
||||
#Router.activate_seg.emit(Router.cur_id + 1)
|
||||
if (area.get_parent().get_parent().prev_seg):
|
||||
Router.activate_seg.emit(area.get_parent().get_parent().prev_seg.seg_id)
|
||||
ready_to_door = false
|
||||
# +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
|
||||
|
|
|
|||
21
camera_2d.gd
21
camera_2d.gd
|
|
@ -1,9 +1,11 @@
|
|||
extends Camera2D
|
||||
|
||||
var target : Node2D
|
||||
@export var temp_segment : Node2D
|
||||
#var target : Node2D
|
||||
#@export var temp_segment : Node2D
|
||||
@export var snake_line : Line2D
|
||||
|
||||
@export var player : Node2D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
|
@ -11,22 +13,21 @@ func _ready() -> void:
|
|||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
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
|
||||
#position = lerp(position, target.position, 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)
|
||||
snake_line.modulate = Color(1,1,1,0.5)
|
||||
snake_line.modulate = Color(1,1,1,1)
|
||||
z_index = 0
|
||||
snake_line.z_index = 9
|
||||
else:
|
||||
position = Vector2(0,0)
|
||||
zoom = Vector2(0.05,0.05)
|
||||
snake_line.modulate = Color(1,1,1,1)
|
||||
snake_line.z_index = 11
|
||||
z_index = 1
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ radius = 16.0
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_q1ksn"]
|
||||
radius = 7.07107
|
||||
|
||||
[node name="Braincell" type="CharacterBody2D"]
|
||||
[node name="Braincell" type="CharacterBody2D" node_paths=PackedStringArray("doorBox")]
|
||||
z_index = 15
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_q1ksn")
|
||||
doorBox = NodePath("doorBox")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_wv6rk")
|
||||
|
|
|
|||
|
|
@ -21,19 +21,21 @@ func _ready() -> void:
|
|||
target_pos = position
|
||||
start_pos = position
|
||||
get_new_target()
|
||||
become_real()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
move_progress += delta * snake_speed
|
||||
if Input.is_action_just_pressed("left"):
|
||||
want_direction = Vector2.LEFT
|
||||
elif Input.is_action_just_pressed("right"):
|
||||
want_direction = Vector2.RIGHT
|
||||
elif Input.is_action_just_pressed("up"):
|
||||
want_direction = Vector2.UP
|
||||
elif Input.is_action_just_pressed("down"):
|
||||
want_direction = Vector2.DOWN
|
||||
if(!Router.player_mode):
|
||||
if Input.is_action_just_pressed("left"):
|
||||
want_direction = Vector2.LEFT
|
||||
elif Input.is_action_just_pressed("right"):
|
||||
want_direction = Vector2.RIGHT
|
||||
elif Input.is_action_just_pressed("up"):
|
||||
want_direction = Vector2.UP
|
||||
elif Input.is_action_just_pressed("down"):
|
||||
want_direction = Vector2.DOWN
|
||||
position = lerp(start_pos,target_pos,move_progress)
|
||||
if move_progress >= 1:
|
||||
get_new_target()
|
||||
|
|
@ -55,7 +57,7 @@ func become_real():
|
|||
pass
|
||||
|
||||
func become_fake():
|
||||
z_index = 0
|
||||
modulate = Color.DIM_GRAY
|
||||
collision_layer = 2
|
||||
#z_index = 0
|
||||
#modulate = Color.DIM_GRAY
|
||||
#collision_layer = 2
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
[ext_resource type="Texture2D" uid="uid://cay1k1dp8yf12" path="res://assets/door.png" id="4_34t3n"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_08kyq"]
|
||||
size = Vector2(16, 64)
|
||||
size = Vector2(8, 64)
|
||||
|
||||
[node name="SnakeSegment" type="AnimatableBody2D" node_paths=PackedStringArray("door")]
|
||||
script = ExtResource("1_3ulhv")
|
||||
|
|
@ -36,7 +36,7 @@ position = Vector2(160, 0)
|
|||
position = Vector2(-22, 0)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArm/Door/DoorIn"]
|
||||
position = Vector2(14, 0)
|
||||
position = Vector2(10, 0)
|
||||
shape = SubResource("RectangleShape2D_08kyq")
|
||||
|
||||
[node name="DoorOut" type="Area2D" parent="DoorArm/Door"]
|
||||
|
|
@ -44,7 +44,7 @@ position = Vector2(22, 0)
|
|||
rotation = 3.14159
|
||||
|
||||
[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")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="DoorArm/Door"]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ signal activate_seg(int)
|
|||
|
||||
var current_seg : Node2D
|
||||
var cur_id : int = 0
|
||||
var player_mode : bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
|
@ -12,4 +13,5 @@ func _ready() -> void:
|
|||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
if (Input.is_action_just_pressed("test_switch_cam")):
|
||||
player_mode = !player_mode
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ func _process(delta: float) -> void:
|
|||
func activate_segment(act_segment : int):
|
||||
Router.current_seg = segements[act_segment]
|
||||
Router.cur_id = act_segment
|
||||
player.reparent(Router.current_seg)
|
||||
for i in segements.size():
|
||||
if act_segment == i:
|
||||
segements[i].become_real()
|
||||
|
||||
else:
|
||||
segements[i].become_fake()
|
||||
player.call_deferred("reparent",Router.current_seg)
|
||||
#player.reparent(Router.current_seg)
|
||||
#for i in segements.size():
|
||||
#if act_segment == i:
|
||||
#segements[i].become_real()
|
||||
#
|
||||
#else:
|
||||
#segements[i].become_fake()
|
||||
|
||||
|
||||
func redraw_line():
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ joint_mode = 2
|
|||
begin_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)
|
||||
script = ExtResource("5_ykrsh")
|
||||
temp_segment = NodePath("../Snake/SegementHolder/SnakeSegment")
|
||||
snake_line = NodePath("../Snake/Line2D")
|
||||
player = NodePath("../Snake/SegementHolder/SnakeSegment/Braincell")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue