Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var move_speed = 2
- var attack_range = .1
- var stopping_distance = 1.9
- var health := 50
- var foo : int = 10
- var is_floored = false
- var target_player
- var isAttacking = true
- var player_animations
- export (int) var damage := 10
- onready var attack_timer = $attack_timer
- onready var anim_player = self.get_node("AnimatedSprite3D")
- var state = states.IDLE
- enum states{
- IDLE
- SEEK
- ATTACK_1
- STUNNED
- KNOCKBACK
- FINALKNOCKBACK
- FLOORED
- GETUP
- DISAPEAR
- }
- func _ready():
- target_player = get_tree().current_scene.get_node("player")
- player_animations = target_player.get_node("AnimatedSprite3D")
- func _process(delta):
- match state:
- states.IDLE:
- $CollisionShape.disabled = false
- anim_player.play("idle")
- var direction_to_player = target_player.global_transform.origin - global_transform.origin
- var distance_to_player = direction_to_player.length()
- if distance_to_player < stopping_distance:
- return true
- state = states.SEEK
- states.SEEK:
- anim_player.play("walking")
- var direction_to_player = target_player.global_transform.origin - global_transform.origin
- var distance_to_player = direction_to_player.length()
- direction_to_player = direction_to_player.normalized()
- # check if the enemy is to tyield(get_tree().create_timer(0.7), "timeout")he left or right of the player
- if global_transform.origin.x < target_player.global_transform.origin.x:
- # enemy is to the left of the player, flip the sprite3d horizontally
- anim_player.set_scale(Vector3(-1, 1, 1))
- else:
- # enemy is to the right of the player, flip the sprite3d back to the opposite direction
- anim_player.set_scale(Vector3(1, 1, 1))
- if distance_to_player > stopping_distance:
- var velocity = direction_to_player * move_speed
- move_and_slide(velocity)
- if distance_to_player <= attack_range:
- state = states.ATTACK
- else:
- state = states.IDLE
- states.STUNNED:
- anim_player.play("stunned")
- yield(get_tree().create_timer(0.6), "timeout")
- $CollisionShape.disabled = false
- states.KNOCKBACK:
- anim_player.play("knockback")
- yield(get_tree().create_timer(0.5), "timeout")
- $CollisionShape.disabled = true
- state = states.FLOORED
- states.FINALKNOCKBACK:
- anim_player.play("knockback")
- yield(get_tree().create_timer(0.5), "timeout")
- $CollisionShape.disabled = true
- state = states.DISAPEAR
- states.FLOORED:
- anim_player.play("ontheFloor")
- yield(get_tree().create_timer(0.7), "timeout")
- $CollisionShape.disabled = true
- state = states.GETUP
- states.GETUP:
- anim_player.play("getting_up")
- $CollisionShape.disabled = true
- state = states.IDLE
- states.DISAPEAR:
- anim_player.play("queueFree")
- $CollisionShape.disabled = true
- yield(get_tree().create_timer(0.7), "timeout")
- queue_free()
- states.ATTACK_1:
- anim_player.play("attack_1")
- # THIS IS THE ENEMYS HITCOUNT BAR SO THAT ITS HEALTH CAN DEPLETE ON PLAYERS ATTACKS----
- func Enemyknockback(damage: int):
- health -= damage
- print("enemy was hit!, current health: " + str(health))
- #player.health -= 10 # Subtract 10 health points from the player
- # THIS IS THE PLAYERS KNOCKBACK FUNCTION .INCLUDES ENEMYS REGISTERED ATTACKS AND EFFECTS
- func _on_EnemyHitBox_body_entered(player_body):
- if player_body.has_method("playerknockback"):
- player_body.playerknockback(damage)
- if player_body.health > 0:
- if $EnemyHitBox/CollisionShape.disabled == false:
- state = states.ATTACK_1
- # alternative code player
- #player_body.state = player_body.states.STUNNED
- #yield(get_tree().create_timer(0.3), "timeout")
- #player_body.state = player_body.states.IDLE
- if player_body.health <= 0:
- $EnemyHitBox/CollisionShape.disabled = true
- func _on_AnimatedSprite3D_animation_finished():
- if anim_player.animation == "attack_1":
- state = states.IDLE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement