Added player and a basic test level
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user