Added player and a basic test level
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var wallCheck: ShapeCast2D
|
||||
@export var floorCheck: RayCast2D
|
||||
@export var ledgeGrabBox: CollisionShape2D
|
||||
|
||||
|
||||
@export_category("Fall State")
|
||||
@export var coyoteTime: float = .2
|
||||
var coyoteJump: bool
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.airFriction
|
||||
|
||||
var fallTimeAmount: int = 10
|
||||
var fallTime: float
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
fallTime += fallTimeAmount * delta
|
||||
#print(fallTime)
|
||||
if !player.is_on_floor():
|
||||
get_coyte_time()
|
||||
player.velocity.y += GRAVITY * delta
|
||||
#player.velocity.x = move_toward(player.velocity.x, 0, friction)
|
||||
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
|
||||
if direction == 0:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
|
||||
|
||||
|
||||
transition_states()
|
||||
|
||||
func get_coyte_time() -> void:
|
||||
await get_tree().create_timer(coyoteTime).timeout
|
||||
coyoteJump = false
|
||||
|
||||
func enter() -> void:
|
||||
animatedSprite2D.play("Fall")
|
||||
fallTime = 0
|
||||
ledgeGrabBox.disabled = false
|
||||
if player.is_on_floor():
|
||||
ledgeGrabBox.disabled = true
|
||||
return
|
||||
coyoteJump = true
|
||||
|
||||
func exit() -> void:
|
||||
fallTime = 0
|
||||
ledgeGrabBox.disabled = true
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
#transitioning state
|
||||
|
||||
#idle state
|
||||
if player.is_on_floor() and fallTime > 5:
|
||||
transition.emit("Land")
|
||||
|
||||
elif player.is_on_floor() and fallTime <= 5:
|
||||
transition.emit("idle")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
transition.emit("jump")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input() and coyoteJump:
|
||||
transition.emit("jump")
|
||||
|
||||
if wallCheck.is_colliding() and !floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
|
||||
transition.emit("Grab")
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://rdj1553spwa8
|
||||
@@ -0,0 +1,86 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var wallCheck: ShapeCast2D
|
||||
@export var floorCheck: RayCast2D
|
||||
@export var ledgeGrabBox: CollisionShape2D
|
||||
|
||||
|
||||
const jumpGravity = player.GRAVITY
|
||||
@onready var jumpHight = player.jumpHight
|
||||
@onready var maxJumpCount = player.maxJumpCount
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.friction
|
||||
|
||||
var currentJumpCount: int
|
||||
var coyoteJump: bool
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _physics_process(delta: float) -> void:
|
||||
await player.move
|
||||
if player.is_on_floor() or (player.is_on_wall() and GameInputEvents.wall_cling_input()):
|
||||
currentJumpCount = 0
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
player.velocity.y += jumpGravity * delta
|
||||
if player.is_on_floor():
|
||||
currentJumpCount = 0
|
||||
player.velocity.y = jumpHight
|
||||
coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
|
||||
if coyoteJump and currentJumpCount != maxJumpCount:
|
||||
player.velocity.y = jumpHight
|
||||
coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
|
||||
#multi jumps
|
||||
if !player.is_on_floor() and GameInputEvents.jump_input() and currentJumpCount != maxJumpCount:
|
||||
player.velocity.y = jumpHight
|
||||
currentJumpCount += 1
|
||||
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
|
||||
if direction == 0:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
|
||||
|
||||
await player.move
|
||||
|
||||
transition_states()
|
||||
|
||||
func enter() -> void:
|
||||
ledgeGrabBox.disabled = false
|
||||
animatedSprite2D.play("Jump")
|
||||
coyoteJump = true
|
||||
|
||||
func exit() -> void:
|
||||
ledgeGrabBox.disabled = true
|
||||
coyoteJump = false
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
#transition states
|
||||
|
||||
#idle state
|
||||
if player.is_on_floor():
|
||||
transition.emit("idle")
|
||||
|
||||
#fall state
|
||||
if player.velocity.y > 0:
|
||||
transition.emit("fall")
|
||||
|
||||
if wallCheck.is_colliding() and not floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
|
||||
transition.emit("Grab")
|
||||
@@ -0,0 +1 @@
|
||||
uid://j4lec2sab50d
|
||||
@@ -0,0 +1,32 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
|
||||
@onready var friction = player.friction
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
|
||||
|
||||
if !animatedSprite2D.is_playing():
|
||||
transition.emit("idle")
|
||||
|
||||
var direction = GameInputEvents.movement_input()
|
||||
|
||||
if direction != 0 and animatedSprite2D.frame > 4:
|
||||
transition.emit("Run")
|
||||
|
||||
if GameInputEvents.jump_input() and animatedSprite2D.frame > 4:
|
||||
transition.emit("Jump")
|
||||
|
||||
func enter() -> void:
|
||||
animatedSprite2D.play("Land")
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
uid://iu5jv2o1im70
|
||||
Reference in New Issue
Block a user