Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var lifetimer = 0
- var thrown = false #A variable activated by the enemy script to throw the sword
- var velocity = Vector2.ZERO
- #IGNORE - For damaging the player
- var curr_kb_dir = Vector2(1, -0.9)
- var curr_kb_strength = 400
- var curr_damage = 1
- onready var over_parent = $Area2D.overlaps_body(get_parent())
- func _physics_process(delta):
- #IGNORE - Collision with the enemy
- over_parent = $Area2D.overlaps_body(get_parent())
- #IGNORE - For dealing knockback to the player
- if $Sprite.flip_h == false:
- curr_kb_dir.x = 1
- else:
- curr_kb_dir.x = -1
- #--------------------------------------------
- #For rotating the sword sprite
- if $Sprite.flip_h == false:
- $Sprite.rotation_degrees += 30
- else:
- $Sprite.rotation_degrees -= 30
- if thrown == true:
- visible = true
- $AnimationPlayer.play("active")
- #Throw it
- if lifetimer < 30:
- lifetimer += 1
- move_and_slide(velocity)
- if $Sprite.flip_h == false:
- velocity.x = 450
- else:
- velocity.x = -450
- #Stop for a bit
- elif lifetimer <= 45:
- velocity *= 0.92
- move_and_slide(velocity)
- lifetimer += 1
- #Come back
- else:
- velocity = Vector2.ZERO
- position = position.move_toward(get_parent().position, delta*lifetimer)
- lifetimer += 15
- #IGNORE - Hiding the sword once it's returned to the enemy
- if thrown == false:
- visible = false
- $AnimationPlayer.play("not active")
- position = Vector2.ZERO
- lifetimer = 0
Add Comment
Please, Sign In to add comment