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
|
||||
@@ -0,0 +1,57 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var weapons: Weapons
|
||||
|
||||
|
||||
@export_category("Shoot State")
|
||||
@export var stateMachine: NodeStateMachine
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var friction = player.friction
|
||||
@onready var airFriction = player.airFriction
|
||||
var canAttack: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
animatedSprite2D.animation_looped.connect(on_loop)
|
||||
weapons.on_weapon_change.connect(on_weapon_change)
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
if player.is_on_floor():
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
|
||||
elif !player.is_on_floor():
|
||||
player.velocity.y += GRAVITY * delta
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, airFriction * delta)
|
||||
|
||||
if animatedSprite2D.frame == weapons.get_weapon_attack_frame() and canAttack:
|
||||
weapons.attack()
|
||||
canAttack = false
|
||||
|
||||
func enter() -> void:
|
||||
canAttack = true
|
||||
weapons.on_start_attack()
|
||||
play_correct_animation()
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
weapons.on_attack_end()
|
||||
|
||||
func on_loop() -> void:
|
||||
canAttack = true
|
||||
if GameInputEvents.is_first_attack_held() or GameInputEvents.is_second_attack_held():
|
||||
pass
|
||||
elif stateMachine.currentNodeState == self:
|
||||
transition.emit("idle")
|
||||
|
||||
func play_correct_animation() -> void:
|
||||
animatedSprite2D.play(weapons.get_weapon_attack_aninmation_type(), weapons.get_weapon_speed())
|
||||
|
||||
func on_weapon_change() -> void:
|
||||
canAttack = true
|
||||
play_correct_animation()
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2p1m7vqxyjj7
|
||||
23
Entities/Player/player_state_scripts/game_input_events.gd
Normal file
23
Entities/Player/player_state_scripts/game_input_events.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
class_name GameInputEvents
|
||||
extends Node
|
||||
|
||||
static func movement_input() -> float:
|
||||
var direction : float = Input.get_axis("move_left", "move_right")
|
||||
return direction
|
||||
|
||||
static func jump_input() -> bool:
|
||||
var jumpInput: bool = Input.is_action_just_pressed("move_jump")
|
||||
var jumpRelesed: bool = Input.is_action_pressed("move_jump")
|
||||
return jumpInput or jumpRelesed
|
||||
|
||||
static func crouch_input() -> bool:
|
||||
var crouchInput: bool = Input.is_action_just_pressed("crouch")
|
||||
return crouchInput
|
||||
|
||||
static func fall_input() -> bool:
|
||||
var fallInput: bool = Input.is_action_just_pressed("force_fall")
|
||||
return fallInput
|
||||
|
||||
static func wall_cling_input() -> bool:
|
||||
var wallClingInput: bool = Input.is_action_just_pressed("wall_cling")
|
||||
return wallClingInput
|
||||
@@ -0,0 +1 @@
|
||||
uid://d38hxs4nttxcm
|
||||
@@ -0,0 +1,51 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var collisionShapeMove: AnimationPlayer
|
||||
|
||||
@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)
|
||||
|
||||
transition_states()
|
||||
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
collisionShapeMove.play("Crouch")
|
||||
animatedSprite2D.play("Crouch")
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
#transition states
|
||||
|
||||
#run state
|
||||
var direction = GameInputEvents.movement_input()
|
||||
|
||||
if !player.is_on_floor():
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("fall")
|
||||
|
||||
if direction and player.is_on_floor():
|
||||
transition.emit("crouchwalk")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("jump")
|
||||
|
||||
#idle state
|
||||
if not Input.is_action_pressed("crouch"):
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("idle")
|
||||
@@ -0,0 +1 @@
|
||||
uid://cmtajhnx8xaqt
|
||||
@@ -0,0 +1,56 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var collisionShapeMove: AnimationPlayer
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var speed: float = player.speed /3
|
||||
@onready var maxSpeed: float = player.maxSpeed /3
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
var direction = 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
|
||||
|
||||
|
||||
transition_states(direction)
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
collisionShapeMove.play("Crouch")
|
||||
animatedSprite2D.play("Crouch Walk")
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states(direction) -> void:
|
||||
|
||||
#transition states
|
||||
|
||||
#fall state
|
||||
if !player.is_on_floor():
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("fall")
|
||||
|
||||
#idle state
|
||||
if direction == 0:
|
||||
transition.emit("crouchidle")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("jump")
|
||||
|
||||
if not Input.is_action_pressed("crouch"):
|
||||
collisionShapeMove.play("Normal")
|
||||
transition.emit("run")
|
||||
@@ -0,0 +1 @@
|
||||
uid://c2lag80wot5k
|
||||
@@ -0,0 +1,46 @@
|
||||
extends NodeState
|
||||
|
||||
@export_category("nodes")
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var ledgeGrabBox: CollisionShape2D
|
||||
@export var wallCheck: ShapeCast2D
|
||||
@export var floorCheck: RayCast2D
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
var collision = wallCheck.get_collision_normal(0)
|
||||
if collision.x == -1:
|
||||
animatedSprite2D.flip_h = false
|
||||
if collision.x == 1:
|
||||
animatedSprite2D.flip_h = true
|
||||
|
||||
transition_states()
|
||||
|
||||
func enter() -> void:
|
||||
player.velocity.x = 0
|
||||
ledgeGrabBox.disabled = false
|
||||
animatedSprite2D.play("Ledge Grab")
|
||||
|
||||
func exit() -> void:
|
||||
ledgeGrabBox.disabled = true
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
|
||||
if GameInputEvents.jump_input():
|
||||
transition.emit("jump")
|
||||
|
||||
if floorCheck.is_colliding():
|
||||
transition.emit("idle")
|
||||
|
||||
if GameInputEvents.crouch_input():
|
||||
ledgeGrabBox.disabled = true
|
||||
transition.emit("fall")
|
||||
@@ -0,0 +1 @@
|
||||
uid://d3t3fweggs161
|
||||
@@ -0,0 +1,44 @@
|
||||
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)
|
||||
|
||||
|
||||
transition_states()
|
||||
|
||||
func enter() -> void:
|
||||
animatedSprite2D.play("Idle")
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
#transitioning state
|
||||
|
||||
#fall state
|
||||
if !player.is_on_floor():
|
||||
transition.emit("fall")
|
||||
|
||||
#run state
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
if direction and player.is_on_floor():
|
||||
transition.emit("Run")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
transition.emit("jump")
|
||||
|
||||
#shoot crouch state
|
||||
if Input.is_action_pressed("crouch"):
|
||||
transition.emit("CrouchIdle")
|
||||
@@ -0,0 +1 @@
|
||||
uid://boof2qmi8clv3
|
||||
@@ -0,0 +1,53 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
var direction = 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
|
||||
|
||||
|
||||
transition_states(direction)
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
animatedSprite2D.play("Run")
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states(direction) -> void:
|
||||
|
||||
|
||||
#transition states
|
||||
|
||||
#fall state
|
||||
if !player.is_on_floor():
|
||||
transition.emit("fall")
|
||||
|
||||
#idle state
|
||||
if direction == 0:
|
||||
transition.emit("idle")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
transition.emit("jump")
|
||||
#Crouch state
|
||||
#TODO make work better
|
||||
if GameInputEvents.crouch_input():
|
||||
transition.emit("crouchwalk")
|
||||
@@ -0,0 +1 @@
|
||||
uid://orlqcyink5er
|
||||
@@ -0,0 +1,21 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var collisionShapeMove: AnimationPlayer
|
||||
|
||||
func enter() -> void:
|
||||
collisionShapeMove.play("Crouch")
|
||||
|
||||
func on_phyisics_process(_delta: float) -> void:
|
||||
|
||||
transition_states()
|
||||
|
||||
func on_process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
func exit() -> void:
|
||||
collisionShapeMove.play("Normal")
|
||||
|
||||
func transition_states() -> void:
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
uid://cywssm5t3d5uv
|
||||
Reference in New Issue
Block a user