no message
This commit is contained in:
42
sidescroller/scripts/State Machine.gd
Normal file
42
sidescroller/scripts/State Machine.gd
Normal file
@ -0,0 +1,42 @@
|
||||
extends Node
|
||||
|
||||
@export var player: Node # In Godot im Inspector zuweisen!
|
||||
@export var initial_state : State
|
||||
|
||||
var current_state : State
|
||||
|
||||
var states : Dictionary = {}
|
||||
|
||||
func _ready():
|
||||
for child in get_children():
|
||||
if child is State:
|
||||
states[child.name.to_lower()] = child
|
||||
child.Transitioned.connect(on_child_transitioned)
|
||||
child.player = player
|
||||
|
||||
if initial_state:
|
||||
initial_state.enter()
|
||||
current_state = initial_state
|
||||
|
||||
func _process(delta):
|
||||
if current_state:
|
||||
current_state.update(delta)
|
||||
|
||||
func _physics_process(delta):
|
||||
if current_state:
|
||||
current_state.physics_update(delta)
|
||||
|
||||
func on_child_transitioned(state, new_state_name):
|
||||
if state != current_state:
|
||||
return
|
||||
|
||||
var new_state = states.get(new_state_name.to_lower())
|
||||
if !new_state:
|
||||
return
|
||||
|
||||
if current_state:
|
||||
current_state.exit()
|
||||
|
||||
new_state.enter()
|
||||
|
||||
current_state = new_state
|
||||
1
sidescroller/scripts/State Machine.gd.uid
Normal file
1
sidescroller/scripts/State Machine.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://c0iqbs1ms86cw
|
||||
19
sidescroller/scripts/State.gd
Normal file
19
sidescroller/scripts/State.gd
Normal file
@ -0,0 +1,19 @@
|
||||
extends Node
|
||||
|
||||
class_name State
|
||||
|
||||
@export var player: CharacterBody2D # HIER hinzugefügt
|
||||
|
||||
signal Transitioned
|
||||
|
||||
func enter():
|
||||
pass
|
||||
|
||||
func exit():
|
||||
pass
|
||||
|
||||
func update(_delta: float):
|
||||
pass
|
||||
|
||||
func physics_update(_delta: float):
|
||||
pass
|
||||
1
sidescroller/scripts/State.gd.uid
Normal file
1
sidescroller/scripts/State.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://c6qk0yh300myk
|
||||
@ -1,113 +1,114 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 350
|
||||
@export var gravity = 40
|
||||
@export var grav = 40
|
||||
@export var jump_force = 800
|
||||
@export var fallvelocity_cap = 1000 # How fast the player can get when falling
|
||||
@export var max_air_jumps = 1 # Number of total jumps allowed (1 = normal, 2 = double jump)
|
||||
@export var crouch_mult = 1
|
||||
@export var sprint_mult = 1
|
||||
|
||||
var input_direction = 0
|
||||
var direction_locked = false
|
||||
var facing_direction = 1 # 1 = right, -1 = left
|
||||
|
||||
@export var sprint_mult = 1.5
|
||||
@export var crouch_mult = 0.4
|
||||
|
||||
@onready var ap = $AnimationPlayer
|
||||
@onready var sprite = $Sprite2D
|
||||
@onready var cshape = $mainbody
|
||||
@onready var crouch_raycast1 = $crouchrc1
|
||||
@onready var crouch_raycast2 = $crouchrc2
|
||||
@onready var topcheck1 = $topcheck1
|
||||
@onready var topcheck2 = $topcheck2
|
||||
|
||||
@onready var statemachine = $StateMachine
|
||||
|
||||
@onready var wallrun_raycast_left1 = $wallrunrcleft1
|
||||
@onready var wallrun_raycast_left2 = $wallrunrcleft2
|
||||
@onready var wallrun_raycast_right1 = $wallrunrcright1
|
||||
@onready var wallrun_raycast_right2 = $wallrunrcright2
|
||||
@onready var wallcheck = $wallcheck
|
||||
@onready var wallcheckright = $wallcheckright
|
||||
@onready var wallcheckleft = $wallcheckleft
|
||||
@onready var floorcheck = $floorcheck
|
||||
|
||||
var horizontal_direction = 0
|
||||
var v_mult = 1 #velocity multiplier
|
||||
var v_push = 0 #velocity push in either direction
|
||||
|
||||
var air_jumps_done = 0
|
||||
var is_crouching = false
|
||||
|
||||
var stuck_under_object = false
|
||||
|
||||
var wallrun_available := true
|
||||
var wallrun_timer := 0.0 #:= bedeutet, dass der Typ fest festgelegt ist (z.B int, bool etc.)
|
||||
var wallrun_time := 1 # Dauer des Wallruns in Sekunden
|
||||
var wallrun_speed := -250.0 # Geschwindigkeit nach oben (negativ wegen y-Achse)
|
||||
|
||||
var wallpushoff_force := 450 # Stärke des Abstoßens
|
||||
var wallpushoff_mult := 0.3 # schränkt die velocity.x Kontrolle des Spielers ein.
|
||||
var wallpushoff_timer := 0.0
|
||||
var wallpushoff_time := 0.5 # dauer des pushoffs
|
||||
var wallrunning := false
|
||||
var pushingoffwall := false
|
||||
var wallrun_direction := 0 # -1 = links, 1 = rechts
|
||||
|
||||
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
||||
var crouching_cshape = preload("res://resources/player crouching cshape.tres")
|
||||
var climbup_pos1 = Vector2(0, 0)
|
||||
var climbup_pos2 = Vector2(0, 0)
|
||||
var climbup_pos1_reached = false
|
||||
var climbup_speed_y = 100
|
||||
var climbup_speed_x = 500
|
||||
|
||||
func _process(delta):
|
||||
#turnmovement()
|
||||
pass
|
||||
|
||||
func _physics_process(delta):
|
||||
var horizontal_direction = Input.get_axis("move_left", "move_right")
|
||||
|
||||
if !is_on_floor():
|
||||
velocity.y += gravity
|
||||
if velocity.y > fallvelocity_cap:
|
||||
velocity.y = fallvelocity_cap
|
||||
else:
|
||||
air_jumps_done = 0
|
||||
wallrun_available = true
|
||||
|
||||
if Input.is_action_just_pressed("jump") && Input.is_action_pressed("move_right") && wall_detected_right() && wallrun_available:
|
||||
start_wallrun(1)
|
||||
elif Input.is_action_just_pressed("jump") && Input.is_action_pressed("move_left") && wall_detected_left() && wallrun_available:
|
||||
start_wallrun(-1)
|
||||
elif Input.is_action_just_pressed("jump"):
|
||||
if is_on_floor():
|
||||
velocity.y = -jump_force
|
||||
elif air_jumps_done < max_air_jumps:
|
||||
velocity.y = -jump_force
|
||||
air_jumps_done += 1
|
||||
|
||||
if wallrunning:
|
||||
wallrun_timer += delta
|
||||
velocity.y = wallrun_speed # Bewegt nach oben
|
||||
|
||||
if wallrun_direction > 0 && !wallrun_raycast_right2.is_colliding():
|
||||
ledgedetected()
|
||||
if wallrun_direction < 1 && !wallrun_raycast_left2.is_colliding():
|
||||
ledgedetected()
|
||||
elif wallrun_timer >= wallrun_time:
|
||||
wallpushoff()
|
||||
|
||||
elif pushingoffwall:
|
||||
wallpushoff_timer += delta
|
||||
velocity.x = speed * 0.3 * horizontal_direction + (-wallrun_direction * wallpushoff_force)
|
||||
|
||||
if wallpushoff_timer >= wallpushoff_time:
|
||||
pushingoffwall = false
|
||||
|
||||
else:
|
||||
velocity.x = speed * horizontal_direction * crouch_mult
|
||||
if horizontal_direction != 0:
|
||||
switchdirection(horizontal_direction)
|
||||
|
||||
|
||||
if Input.is_action_just_pressed("crouch"):
|
||||
crouch()
|
||||
elif Input.is_action_just_released("crouch"):
|
||||
if above_head_empty():
|
||||
stand()
|
||||
else:
|
||||
if stuck_under_object != true:
|
||||
stuck_under_object = true
|
||||
print("player stuck under object")
|
||||
|
||||
if stuck_under_object && above_head_empty():
|
||||
if !Input.is_action_pressed("crouch"):
|
||||
stand()
|
||||
stuck_under_object = false
|
||||
|
||||
move_and_slide()
|
||||
|
||||
update_animation(horizontal_direction)
|
||||
|
||||
func above_head_empty() -> bool:
|
||||
var result = !crouch_raycast1.is_colliding() && !crouch_raycast2.is_colliding()
|
||||
func _physics_process(delta):
|
||||
|
||||
move_and_slide()
|
||||
input_direction = Input.get_axis("move_left", "move_right")
|
||||
|
||||
#print(statemachine.current_state.get_state_name()) # zum debuggen aktivieren
|
||||
|
||||
if statemachine.current_state.get_state_name() not in ["PlayerWallrun", "PlayerClimbUp"]:
|
||||
gravity()
|
||||
|
||||
if statemachine.current_state.get_state_name() not in ["PlayerWallrun", "PlayerWallrunPushoff", "PlayerLedgeGrab", "PlayerClimbUp"]:
|
||||
turnmovement()
|
||||
|
||||
|
||||
$ledgecollision.disabled = statemachine.current_state.get_state_name() in ["PlayerIdle", "PlayerRun", "PlayerCrouch", "PlayerCrouchWalk", "PlayerJump", "PlayerWallrun", "PlayerClimbUp"] or velocity.y < 0 or Input.is_action_pressed("crouch") or(topcheck1.is_colliding() and topcheck2.is_colliding() and statemachine.current_state.get_state_name() != "PlayerLedgeGrab")
|
||||
|
||||
func movement():
|
||||
velocity.x = speed * input_direction * v_mult + v_push
|
||||
|
||||
func turnmovement():
|
||||
movement()
|
||||
|
||||
if direction_locked:
|
||||
return
|
||||
|
||||
if input_direction != 0 and sign(input_direction) != facing_direction:
|
||||
switch_direction(sign(input_direction))
|
||||
|
||||
func switch_direction(new_direction):
|
||||
facing_direction = new_direction
|
||||
sprite.flip_h = (facing_direction == -1)
|
||||
|
||||
func set_facing_direction(dir: int): #manual flip
|
||||
if direction_locked:
|
||||
return
|
||||
if dir in [-1, 1] and dir != facing_direction:
|
||||
switch_direction(dir)
|
||||
|
||||
func lock_direction():
|
||||
direction_locked = true
|
||||
|
||||
func unlock_direction():
|
||||
direction_locked = false
|
||||
|
||||
func gravity():
|
||||
velocity.y += grav
|
||||
if velocity.y > fallvelocity_cap:
|
||||
velocity.y = fallvelocity_cap
|
||||
|
||||
func head_clear() -> bool:
|
||||
var result = !topcheck1.is_colliding() && !topcheck2.is_colliding()
|
||||
return result
|
||||
|
||||
func wall_detected_left() -> bool:
|
||||
@ -117,67 +118,42 @@ func wall_detected_left() -> bool:
|
||||
func wall_detected_right() -> bool:
|
||||
var result = wallrun_raycast_right1.is_colliding() && wallrun_raycast_right2.is_colliding()
|
||||
return result
|
||||
|
||||
# transition functions
|
||||
|
||||
func transitionidle() -> bool:
|
||||
var result = Input.get_axis("move_left", "move_right") == 0 && is_on_floor()
|
||||
return result
|
||||
|
||||
func start_wallrun(direction: int):
|
||||
wallrunning = true
|
||||
wallrun_available = false
|
||||
wallrun_direction = direction
|
||||
velocity.x = 1000 * wallrun_direction # An Wand haften
|
||||
print("start wallrun called")
|
||||
func transitionrun() -> bool:
|
||||
var result = Input.get_axis("move_left", "move_right") != 0 && is_on_floor()
|
||||
return result
|
||||
|
||||
func wallpushoff():
|
||||
wallrunning = false
|
||||
pushingoffwall = true
|
||||
wallpushoff_timer = 0.0
|
||||
wallrun_timer = 0.0
|
||||
print("stop wallrun called")
|
||||
func transitionjump() -> bool:
|
||||
var result = Input.is_action_just_pressed("jump") && is_on_floor()
|
||||
return result
|
||||
|
||||
func ledgedetected():
|
||||
wallrunning = false
|
||||
wallrun_timer = 0.0
|
||||
func transitiondoublejump() -> bool:
|
||||
var result = Input.is_action_just_pressed("jump") && !is_on_floor() && (air_jumps_done < max_air_jumps)
|
||||
return result
|
||||
|
||||
func checkledgegrab() -> bool:
|
||||
var result = wallcheck.is_colliding() && !floorcheck.is_colliding() && velocity.y == 0
|
||||
func transitionfall() -> bool:
|
||||
var result = velocity.y > 0 && !is_on_floor()
|
||||
return result
|
||||
|
||||
func transitionledgegrab() -> bool:
|
||||
var result = !floorcheck.is_colliding() && velocity.y - grav == 0 && (wallcheckright.is_colliding() or wallcheckleft.is_colliding())
|
||||
return result
|
||||
|
||||
func update_animation(horizontal_direction):
|
||||
if is_on_floor():
|
||||
if horizontal_direction == 0:
|
||||
if is_crouching:
|
||||
ap.play("crouch idle")
|
||||
else:
|
||||
ap.play("idle")
|
||||
else:
|
||||
if is_crouching:
|
||||
ap.play("crouch walk")
|
||||
else:
|
||||
ap.play("run")
|
||||
else:
|
||||
if velocity.y < 0:
|
||||
if air_jumps_done == 0 :
|
||||
ap.play("jump")
|
||||
elif air_jumps_done == 1:
|
||||
ap.play("double jump")
|
||||
elif velocity.y > 0:
|
||||
ap.play("fall")
|
||||
|
||||
func crouch():
|
||||
if is_crouching:
|
||||
return
|
||||
is_crouching = true
|
||||
crouch_mult = 0.4
|
||||
cshape.shape = crouching_cshape
|
||||
cshape.position.y = -31
|
||||
func transitioncrouch() -> bool:
|
||||
var result = is_on_floor() && Input.is_action_pressed("crouch")
|
||||
return result
|
||||
|
||||
func stand():
|
||||
if is_crouching == false:
|
||||
return
|
||||
is_crouching = false
|
||||
crouch_mult = 1
|
||||
cshape.shape = standing_cshape
|
||||
cshape.position.y = -44
|
||||
func transitioncrouchwalk() -> bool:
|
||||
var result = is_on_floor() && Input.is_action_pressed("crouch") && Input.get_axis("move_left", "move_right") != 0
|
||||
return result
|
||||
|
||||
func switchdirection(horizontal_direction):
|
||||
sprite.flip_h = (horizontal_direction == -1)
|
||||
sprite.position.x = horizontal_direction * 4
|
||||
func transitionwallrun() -> bool:
|
||||
var result = Input.is_action_just_pressed("jump") and ((Input.is_action_pressed("move_right") && wall_detected_right()) or (Input.is_action_pressed("move_left") && wall_detected_left())) and wallrun_available
|
||||
return result
|
||||
|
||||
|
||||
46
sidescroller/scripts/playerclimbup.gd
Normal file
46
sidescroller/scripts/playerclimbup.gd
Normal file
@ -0,0 +1,46 @@
|
||||
extends State
|
||||
class_name PlayerClimbUp
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
var ledge_cshape = preload("res://resources/player ledge cshape.tres")
|
||||
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
||||
|
||||
func enter():
|
||||
|
||||
player.climbup_pos1 = player.position + Vector2(0, -52)
|
||||
player.climbup_pos2 = player.position + Vector2(player.facing_direction * 40, -52)
|
||||
|
||||
print(player.position)
|
||||
print (player.climbup_pos1)
|
||||
|
||||
player.ap.play("climb up")
|
||||
player.sprite.position.x = player.facing_direction * 11
|
||||
player.sprite.position.y = -60
|
||||
|
||||
player.cshape.shape = ledge_cshape
|
||||
player.cshape.position.y = -69
|
||||
|
||||
func exit():
|
||||
player.cshape.shape = standing_cshape
|
||||
player.cshape.position.y = -43
|
||||
|
||||
player.sprite.position.x = 0
|
||||
player.sprite.position.y = -48
|
||||
|
||||
player.climbup_pos1_reached = false
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func physics_update(delta):
|
||||
|
||||
if player.position != player.climbup_pos1 && !player.climbup_pos1_reached:
|
||||
player.position = player.position.move_toward(player.climbup_pos1, player.climbup_speed_y * delta)
|
||||
if player.position == player.climbup_pos1:
|
||||
player.climbup_pos1_reached = true
|
||||
elif player.position != player.climbup_pos2 && player.climbup_pos1_reached:
|
||||
player.position = player.position.move_toward(player.climbup_pos2, player.climbup_speed_x * delta)
|
||||
elif player.position == player.climbup_pos2:
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
1
sidescroller/scripts/playerclimbup.gd.uid
Normal file
1
sidescroller/scripts/playerclimbup.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://boe7p8pcolkln
|
||||
37
sidescroller/scripts/playercrouch.gd
Normal file
37
sidescroller/scripts/playercrouch.gd
Normal file
@ -0,0 +1,37 @@
|
||||
extends State
|
||||
class_name PlayerCrouch
|
||||
|
||||
var crouching_cshape = preload("res://resources/player crouching cshape.tres")
|
||||
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.cshape.shape = crouching_cshape
|
||||
player.cshape.position.y = -31
|
||||
|
||||
func exit():
|
||||
player.cshape.shape = standing_cshape
|
||||
player.cshape.position.y = -44
|
||||
|
||||
func update(delta):
|
||||
|
||||
var horizontal_direction = Input.get_axis("move_left", "move_right")
|
||||
|
||||
if player.is_on_floor():
|
||||
if horizontal_direction == 0:
|
||||
player.ap.play("crouch idle")
|
||||
else:
|
||||
Transitioned.emit(self, "PlayerCrouchwalk")
|
||||
|
||||
if player.head_clear() and (Input.is_action_just_released("crouch") or !Input.is_action_pressed("crouch")):
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
player.stuck_under_object = false
|
||||
elif !player.head_clear():
|
||||
if player.stuck_under_object != true:
|
||||
player.stuck_under_object = true
|
||||
print("player stuck under object", player.stuck_under_object)
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playercrouch.gd.uid
Normal file
1
sidescroller/scripts/playercrouch.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cawr3av2aa8jb
|
||||
32
sidescroller/scripts/playercrouchwalk.gd
Normal file
32
sidescroller/scripts/playercrouchwalk.gd
Normal file
@ -0,0 +1,32 @@
|
||||
extends State
|
||||
class_name PlayerCrouchWalk
|
||||
|
||||
var crouching_cshape = preload("res://resources/player crouching cshape.tres")
|
||||
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.cshape.shape = crouching_cshape
|
||||
player.cshape.position.y = -31
|
||||
player.v_mult = player.crouch_mult
|
||||
func exit():
|
||||
player.cshape.shape = standing_cshape
|
||||
player.cshape.position.y = -44
|
||||
player.v_mult = 1
|
||||
func update(delta):
|
||||
player.ap.play("crouch walk")
|
||||
|
||||
if player.head_clear() and (Input.is_action_just_released("crouch") or !Input.is_action_pressed("crouch")):
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
player.stuck_under_object = false
|
||||
elif Input.get_axis("move_left", "move_right") == 0:
|
||||
Transitioned.emit(self, "PlayerCrouch")
|
||||
elif !player.head_clear():
|
||||
if player.stuck_under_object != true:
|
||||
player.stuck_under_object = true
|
||||
print("player stuck under object")
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playercrouchwalk.gd.uid
Normal file
1
sidescroller/scripts/playercrouchwalk.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dhvehwhg63p2h
|
||||
26
sidescroller/scripts/playerdoublejump.gd
Normal file
26
sidescroller/scripts/playerdoublejump.gd
Normal file
@ -0,0 +1,26 @@
|
||||
extends State
|
||||
class_name PlayerDoubleJump
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.ap.play("double jump")
|
||||
player.velocity.y = -player.jump_force
|
||||
player.air_jumps_done += 1
|
||||
|
||||
func exit():
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
if player.velocity.y > 0 and !player.is_on_floor():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
elif !player.is_on_floor() and Input.is_action_just_pressed("jump") and (player.air_jumps_done < player.max_air_jumps):
|
||||
Transitioned.emit(self, "PlayerDoubleJump")
|
||||
elif player.is_on_floor() && player.velocity.x != 0:
|
||||
Transitioned.emit(self, "PlayerRun")
|
||||
elif player.is_on_floor():
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playerdoublejump.gd.uid
Normal file
1
sidescroller/scripts/playerdoublejump.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cgsyaphtn6k6q
|
||||
30
sidescroller/scripts/playerfall.gd
Normal file
30
sidescroller/scripts/playerfall.gd
Normal file
@ -0,0 +1,30 @@
|
||||
extends State
|
||||
class_name PlayerFall
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
pass
|
||||
|
||||
func exit():
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
player.ap.play("fall")
|
||||
|
||||
if player.transitionledgegrab():
|
||||
Transitioned.emit(self, "PlayerLedgeGrab")
|
||||
elif player.transitiondoublejump():
|
||||
Transitioned.emit(self, "PlayerDoubleJump")
|
||||
elif player.transitionidle():
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
elif player.transitionrun():
|
||||
Transitioned.emit(self, "PlayerRun")
|
||||
|
||||
player.gravity()
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
#player.turnmovement()
|
||||
|
||||
1
sidescroller/scripts/playerfall.gd.uid
Normal file
1
sidescroller/scripts/playerfall.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://whap2d3r3yk
|
||||
27
sidescroller/scripts/playeridle.gd
Normal file
27
sidescroller/scripts/playeridle.gd
Normal file
@ -0,0 +1,27 @@
|
||||
extends State
|
||||
class_name PlayerIdle
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.air_jumps_done = 0
|
||||
player.wallrun_available = true
|
||||
|
||||
func exit():
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
player.ap.play("idle")
|
||||
|
||||
if player.transitionfall():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
elif player.transitionrun():
|
||||
Transitioned.emit(self, "PlayerRun")
|
||||
elif player.transitioncrouch():
|
||||
Transitioned.emit(self, "PlayerCrouch")
|
||||
elif player.transitionjump():
|
||||
Transitioned.emit(self, "PlayerJump")
|
||||
|
||||
func physics_update(delta):
|
||||
player.gravity()
|
||||
1
sidescroller/scripts/playeridle.gd.uid
Normal file
1
sidescroller/scripts/playeridle.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://d34ia87aolokd
|
||||
25
sidescroller/scripts/playerjump.gd
Normal file
25
sidescroller/scripts/playerjump.gd
Normal file
@ -0,0 +1,25 @@
|
||||
extends State
|
||||
class_name PlayerJump
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.ap.play("jump")
|
||||
player.velocity.y = -player.jump_force
|
||||
func exit():
|
||||
pass
|
||||
func update(delta):
|
||||
|
||||
if player.transitionledgegrab():
|
||||
Transitioned.emit(self, "PlayerLedgeGrab")
|
||||
elif player.transitionfall():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
elif !player.is_on_floor() and Input.is_action_just_pressed("jump") and (player.air_jumps_done < player.max_air_jumps):
|
||||
Transitioned.emit(self, "PlayerDoubleJump")
|
||||
elif player.is_on_floor() && player.velocity.x != 0:
|
||||
Transitioned.emit(self, "PlayerRun")
|
||||
elif player.is_on_floor():
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playerjump.gd.uid
Normal file
1
sidescroller/scripts/playerjump.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://d0cc7xgq16onu
|
||||
38
sidescroller/scripts/playerledgegrab.gd
Normal file
38
sidescroller/scripts/playerledgegrab.gd
Normal file
@ -0,0 +1,38 @@
|
||||
extends State
|
||||
class_name PlayerLedgeGrab
|
||||
|
||||
var ledge_cshape = preload("res://resources/player ledge cshape.tres")
|
||||
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
if player.wallcheckright.is_colliding() and player.facing_direction == -1:
|
||||
player.set_facing_direction(1)
|
||||
elif player.wallcheckleft.is_colliding() and player.facing_direction == 1:
|
||||
player.set_facing_direction(-1)
|
||||
|
||||
player.ap.play("ledge hang")
|
||||
player.sprite.position.x = player.facing_direction * 11
|
||||
player.sprite.position.y = -54
|
||||
|
||||
player.cshape.shape = ledge_cshape
|
||||
player.cshape.position.y = -55
|
||||
|
||||
func exit():
|
||||
player.cshape.shape = standing_cshape
|
||||
player.cshape.position.y = -43
|
||||
|
||||
player.sprite.position.x = 0
|
||||
player.sprite.position.y = -48
|
||||
|
||||
func update(delta):
|
||||
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
Transitioned.emit(self, "PlayerClimbUp")
|
||||
elif player.floorcheck.is_colliding() or (!player.wallcheckright.is_colliding() and !player.wallcheckleft.is_colliding()) or Input.is_action_pressed("crouch"):
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playerledgegrab.gd.uid
Normal file
1
sidescroller/scripts/playerledgegrab.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://c46i4062efgw1
|
||||
28
sidescroller/scripts/playerrun.gd
Normal file
28
sidescroller/scripts/playerrun.gd
Normal file
@ -0,0 +1,28 @@
|
||||
extends State
|
||||
class_name PlayerRun
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.air_jumps_done = 0
|
||||
player.wallrun_available = true
|
||||
player.v_mult = 1
|
||||
func exit():
|
||||
pass
|
||||
func update(delta):
|
||||
player.ap.play("run")
|
||||
|
||||
if player.transitionidle():
|
||||
Transitioned.emit(self, "PlayerIdle")
|
||||
elif player.transitioncrouch():
|
||||
Transitioned.emit(self, "PlayerCrouchwalk")
|
||||
elif player.transitionwallrun():
|
||||
Transitioned.emit(self, "PlayerWallrun")
|
||||
elif player.transitionjump():
|
||||
Transitioned.emit(self, "PlayerJump")
|
||||
elif player.transitionfall():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
|
||||
func physics_update(delta):
|
||||
pass
|
||||
1
sidescroller/scripts/playerrun.gd.uid
Normal file
1
sidescroller/scripts/playerrun.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dyee6xwb8js1s
|
||||
31
sidescroller/scripts/playerwallrun.gd
Normal file
31
sidescroller/scripts/playerwallrun.gd
Normal file
@ -0,0 +1,31 @@
|
||||
extends State
|
||||
class_name PlayerWallrun
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.wallrun_available = false
|
||||
|
||||
player.velocity.x = 2000 * player.facing_direction # An Wand haften
|
||||
|
||||
func exit():
|
||||
player.wallrun_timer = 0.0
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func physics_update(delta):
|
||||
player.wallrun_timer += delta
|
||||
player.velocity.y = player.wallrun_speed # Bewegt nach oben
|
||||
|
||||
if player.facing_direction > 0 && !player.wallrun_raycast_right2.is_colliding():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
if player.facing_direction < 1 && !player.wallrun_raycast_left2.is_colliding():
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
elif player.wallrun_timer >= player.wallrun_time:
|
||||
Transitioned.emit(self, "PlayerWallrunPushoff")
|
||||
|
||||
func transitionwallrunpushoff() -> bool:
|
||||
var result = player.wallrun_timer >= player.wallrun_time
|
||||
return result
|
||||
1
sidescroller/scripts/playerwallrun.gd.uid
Normal file
1
sidescroller/scripts/playerwallrun.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bcnm70o0yo87k
|
||||
27
sidescroller/scripts/playerwallrunpushoff.gd
Normal file
27
sidescroller/scripts/playerwallrunpushoff.gd
Normal file
@ -0,0 +1,27 @@
|
||||
extends State
|
||||
class_name PlayerWallrunPushoff
|
||||
|
||||
func get_state_name():
|
||||
return str(self).split(":")[0]
|
||||
|
||||
func enter():
|
||||
player.v_mult = player.wallpushoff_mult
|
||||
player.v_push = -player.facing_direction * player.wallpushoff_force
|
||||
print("pushoff entered")
|
||||
|
||||
func exit():
|
||||
player.wallpushoff_timer = 0.0
|
||||
player.v_mult = 1
|
||||
player.v_push = 0
|
||||
player.set_facing_direction(-player.facing_direction)
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func physics_update(delta):
|
||||
player.movement()
|
||||
|
||||
player.wallpushoff_timer += delta
|
||||
|
||||
if player.wallpushoff_timer >= player.wallpushoff_time:
|
||||
Transitioned.emit(self, "PlayerFall")
|
||||
1
sidescroller/scripts/playerwallrunpushoff.gd.uid
Normal file
1
sidescroller/scripts/playerwallrunpushoff.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bxkdsl12qa7jy
|
||||
Reference in New Issue
Block a user