Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- export var MAX_SPEED = 80
- export var acceleration = 500
- export var friction = 500
- enum {
- MOVE,
- ATTACK,
- DEAD
- }
- var state = MOVE
- var velocity = Vector2.ZERO
- onready var animationPlayer = $AnimationPlayer
- #Animation -> Parameters si de acolo setezi in ce pozitie sa inceapa caracterul
- # SECOND METHOD
- """
- var Whatever = null
- func _ready():
- Whatever = $AnimationWhatever
- sunt 2 metode prin care se acceseaza nodul din "main" nush cum sa-i zic
- """
- var roll_vector = Vector2.RIGHT
- var stats = PlayerStats
- onready var animationTree = $AnimationTree
- onready var animationState = animationTree.get("parameters/playback") #animation tree -> playback iei ce e acl
- onready var swordHitbox = $HitboxPivot/SwordHitbox
- onready var hurtBox = $HurtBox
- onready var blinkAnimationPlayer = $BlinkAnimationPlayer
- onready var sceneTransition = $SceneTransitionRect
- const PlayerHurtSound = preload("res://Character/PlayerHurtSound.tscn")
- func _ready():
- #stats.connect("no_health", self, "dead")
- animationTree.active = true
- swordHitbox.knockback_vector = roll_vector
- func _physics_process(delta):
- match state:
- MOVE:
- move_state(delta)
- ATTACK:
- attack_state(delta)
- DEAD:
- dead_state()
- sceneTransition.transition_to("res://Menu/MainMenu.tscn")
- var input_vector = Vector2.ZERO
- var velocity_aux
- func move_state(delta):
- input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
- input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
- input_vector = input_vector.normalized()
- if input_vector != Vector2.ZERO:
- roll_vector = input_vector
- swordHitbox.knockback_vector = input_vector
- animationTree.set("parameters/Idle/blend_position", input_vector)
- animationTree.set("parameters/Run/blend_position", input_vector)
- animationTree.set("parameters/Attack/blend_position", input_vector)
- #animationTree.set("parameters/DeathAnimation/blend_position", input_vector)
- animationState.travel("Run")
- velocity = velocity.move_toward(input_vector * MAX_SPEED, acceleration * delta)
- else:
- animationState.travel("Idle")
- if velocity != Vector2.ZERO:
- velocity_aux = velocity
- velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
- move()
- if Input.is_action_just_pressed("attack"):
- state = ATTACK
- func attack_state(_delta):
- velocity = Vector2.ZERO
- animationState.travel("Attack")
- func attack_animation_ended():
- state = MOVE
- func move():
- velocity = move_and_slide(velocity)
- func dead_state():
- animationTree.set("parameters/DeathAnimation/blend_position", velocity_aux)
- animationState.travel("DeathAnimation")
- $Collision1.disabled = true
- $HurtBox/CollisionShape2D.disabled = true
- func _on_HurtBox_area_entered(area):
- stats.health -= area.damage
- if stats.health <= 0:
- state = DEAD
- hurtBox.start_invincibility(0.6)
- hurtBox.create_hit_effect()
- var playerHurtSounds = PlayerHurtSound.instance()
- get_tree().current_scene.add_child(playerHurtSounds)
- func _on_HurtBox_invincibility_started():
- blinkAnimationPlayer.play("Start")
- func _on_HurtBox_invincibility_ended():
- blinkAnimationPlayer.play("Stop")
Add Comment
Please, Sign In to add comment