This commit is contained in:
AutumnMayes 2025-12-15 19:10:59 -05:00
parent 58e74612be
commit 07b5ce7c8d
7 changed files with 198 additions and 34 deletions

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=44 format=3 uid="uid://bu8e4iyw8pc03"]
[ext_resource type="Script" uid="uid://dsryf6gxqcm1k" path="res://Scripts/character_body_2d.gd" id="1_0y7nr"]
[ext_resource type="Script" uid="uid://dsryf6gxqcm1k" path="res://Scripts/player.gd" id="1_0y7nr"]
[ext_resource type="Texture2D" uid="uid://rltv4cun6tyw" path="res://Assets/Graphics/Player/Death/adult death.png" id="2_nn08x"]
[ext_resource type="Texture2D" uid="uid://ddqxjf5l3jdjy" path="res://Assets/Graphics/Player/Jump/Adult_jump.png" id="3_52ee3"]
[ext_resource type="Texture2D" uid="uid://c6uobr1ovln4i" path="res://Assets/Graphics/Player/Hurt/adult hurt.png" id="4_bhhdu"]

File diff suppressed because one or more lines are too long

View File

@ -22,12 +22,35 @@ var pushEnabled = false
var direction
var upJump = false
var gravity := ProjectSettings.get_setting("physics/2d/default_gravity") as float
var can_mount_stairs := false
var is_on_stairs := false
var stairs_z_above := 0 # filled by stairs trigger
var stairs_z_below := -1 # filled by stairs trigger
var stairs_node: Node = null
signal deathAnimationCompleteSignal
func _physics_process(delta: float) -> void:
#game loop
handle_input()
#calculate the movement
# --- STAIRS OPT-IN LOGIC ---
if can_mount_stairs and not is_on_stairs:
print("Player: inside stairs trigger, waiting for up/down")
if Input.is_action_just_pressed("ui_up"):
print("Player: ui_up pressed")
if Input.is_action_just_pressed("ui_down"):
print("Player: ui_down pressed")
if Input.is_action_just_pressed("ui_up") or Input.is_action_just_pressed("ui_down"):
print("Player: START stairs mode requested")
_start_stairs_mode()
# ---------------------------
handle_movement(delta)
#change states
update_states()
@ -35,6 +58,9 @@ func _physics_process(delta: float) -> void:
update_animation()
#collision with objects, raycasts
# Gravity
if not is_on_floor():
velocity.y += gravity * delta
move_and_slide()
handle_collisions()
@ -136,6 +162,58 @@ func handle_collisions():
pushEnabled = false
const STAIRS_LAYER := 3 # correct layer number for "stairs"
func _ready() -> void:
_set_stair_collision(false)
# Allow climbing up steeper slopes (default is ~45°)
floor_max_angle = deg_to_rad(60) # you can increase or decrease as needed
func _set_stair_collision(enabled: bool) -> void:
print("[Player] set stair collision to:", enabled)
set_collision_mask_value(STAIRS_LAYER, enabled)
func _start_stairs_mode() -> void:
print("[Player] _start_stairs_mode")
is_on_stairs = true
_set_stair_collision(true)
# When "on" the stairs, draw above (or tune based on your art)
if stairs_node and stairs_node.has_method("get_above_z_index"):
z_index = stairs_node.get_above_z_index()
else:
z_index = 5 # fallback
func _end_stairs_mode() -> void:
print("[Player] _end_stairs_mode")
is_on_stairs = false
_set_stair_collision(false)
# When not on stairs, draw behind (to appear "behind" stair art if overlapping)
if stairs_node and stairs_node.has_method("get_below_z_index"):
z_index = stairs_node.get_below_z_index()
else:
z_index = 0 # fallback
stairs_node = null
# Called by the stairs trigger via signals:
func on_stairs_trigger_enter(stairs: Node, above_z: int, below_z: int) -> void:
print("[Player] on_stairs_trigger_enter from:", stairs.name)
can_mount_stairs = true
stairs_node = stairs
stairs_z_above = above_z
stairs_z_below = below_z
# By default when *not* mounted, draw behind:
z_index = below_z
func on_stairs_trigger_exit(stairs: Node) -> void:
print("[Player] on_stairs_trigger_exit from:", stairs.name)
if stairs_node == stairs:
can_mount_stairs = false
func on_stairs_top_reached(stairs: Node) -> void:
print("[Player] on_stairs_top_reached from:", stairs.name)
if stairs_node == stairs and is_on_stairs:
_end_stairs_mode()
func _on_animation_finished() -> void:
match current_state:
State.JUMP:

25
Scripts/stair.gd Normal file
View File

@ -0,0 +1,25 @@
extends Node2D
@export var z_index_above := 6 # player draws above stairs while climbing
@export var z_index_below := 2 # player draws behind stairs when not climbing
func get_above_z_index(): return z_index_above
func get_below_z_index(): return z_index_below
func _ready():
z_index = 3
func _on_mount_trigger_body_exited(body):
print("[MountTrigger] body_exited:", body.name)
if body.has_method("on_stairs_trigger_exit"):
body.on_stairs_trigger_exit(self)
func _on_mount_trigger_body_entered(body):
print("[MountTrigger] body_entered:", body.name)
if body.has_method("on_stairs_trigger_enter"):
body.on_stairs_trigger_enter(self, z_index_above, z_index_below)
func _on_top_exit_body_entered(body: Node2D) -> void:
print("[Stairs] TopExit entered by:", body.name)
if body.has_method("on_stairs_top_reached"):
body.on_stairs_top_reached(self)

1
Scripts/stair.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://cbp0lclhmd1db

View File

@ -47,3 +47,8 @@ shoot={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":89,"key_label":0,"unicode":121,"location":0,"echo":false,"script":null)
]
}
[layer_names]
2d_physics/layer_1="player"
2d_physics/layer_3="stairs"