Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var AnimSprite = $AnimatedSprite3D
- var velocity = Vector3()
- var speed = 3
- var isAttacking = false
- var isJumping = false
- var jump_impulse = 300
- var input_vector = Vector3.ZERO
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- var canMove = false
- var AttackPoints = 3
- var health := 50
- var foo : int = 10
- var timer = null
- var crouch_delay = 0.5
- var isCrouch = true
- var current_animation
- enum states {
- IDLE,
- WALK,
- ATTACK1,
- ATTACK2,
- ATTACK3,
- STUNNED
- }
- var player_state = states.IDLE
- var state = 0 # removing this line re-enables movement and attack animations plus changing 'match state'
- # in line 101 to 'match (player_state)'.
- func _ready():
- $attackArea/CollisionShape.disabled = true
- func _physics_process(delta):
- get_input()
- update_animation()
- combo()
- func get_input():
- if not isAttacking:
- velocity.x = speed * Input.get_axis("ui_left", "ui_right")
- velocity.z = speed * Input.get_axis("ui_up", "ui_down")
- player_state = states.WALK
- if velocity.x == 0 and velocity.z == 0:
- player_state = states.IDLE
- isAttacking = false
- velocity = move_and_slide(velocity, Vector3.UP)
- var motion = velocity.normalized() * speed
- func combo():
- if isAttacking:
- $attackArea/CollisionShape.disabled = true
- if Input.is_action_just_pressed("attack") && AttackPoints == 3:
- $AttackResetTimer.start()
- velocity.x = 0
- velocity.z = 0
- player_state = states.ATTACK1
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- isAttacking = true
- elif Input.is_action_just_pressed("attack") && AttackPoints == 2:
- $AttackResetTimer.start()
- velocity.x = 0
- velocity.z = 0
- player_state = states.ATTACK2
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- isAttacking = true
- elif Input.is_action_just_pressed("attack") && AttackPoints == 1:
- $AttackResetTimer.start()
- velocity.x = 0
- velocity.z = 0
- player_state = states.ATTACK3
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- isAttacking = true
- elif isAttacking == false:
- speed = 1.5
- velocity = move_and_slide(velocity, Vector3.UP)
- var motion = velocity.normalized() * speed
- func update_animation():
- match (player_state):
- states.IDLE:
- $AnimatedSprite3D.play("idle")
- states.WALK:
- $AnimatedSprite3D.play("walking")
- states.ATTACK1:
- $AnimatedSprite3D.play("Attack_1")
- states.ATTACK2:
- $AnimatedSprite3D.play("Attack_2")
- states.ATTACK3:
- $AnimatedSprite3D.play("Attack_3")
- states.STUNNED:
- $AnimatedSprite3D.play("stunned")
- func _on_AttackResetTimer_timeout():
- AttackPoints = 3
- func _on_AnimatedSprite3D_animation_finished():
- if $AnimatedSprite3D.animation == "Attack_1":
- $AnimatedSprite3D.play("idle")
- elif $AnimatedSprite3D.animation == "Attack_2":
- $AnimatedSprite3D.play("idle")
- elif $AnimatedSprite3D.animation == "Attack_3":
- $AnimatedSprite3D.play("idle")
- isAttacking = false
- # THIS IS THE ENEMYS KNOCKBACK FUNCTION WITH PLAYERS CODE TO REGISTER THE ATTACKS-----
- func _on_attackArea_body_entered(body):
- if body.has_method("Enemyknockback"):
- body.Enemyknockback(damage)
- if body.health > 0:
- if AnimSprite.animation == "Attack_1" or AnimSprite.animation == "Attack_2":
- if body.state != body.states.KNOCKBACK:
- if body.state != body.states.STUNNED:
- body.state = body.states.STUNNED
- yield(get_tree().create_timer(0.5), "timeout")
- body.state = body.states.IDLE
- if AnimSprite.animation == "Attack_3":
- body.state = body.states.KNOCKBACK
- print("knockback")
- if body.health <= 0:
- body.state = body.states.FINALKNOCKBACK
- $CollisionShape.disabled = true
- # THIS IS THE PLAYERS HITCOUNT BAR SO THE ENEMYS ATTACKS CAN REGISTER ------
- func playerknockback(damage: int):
- health -= damage
- print("player was hit!, current health: " + str(health))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement