Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Area2D
- signal hit
- export (int) var SPEED
- var velocity = Vector2()
- var screensize
- var miejsce_wcisniecia = Vector2()
- func _ready():
- hide()
- screensize = get_viewport_rect().size
- func start(pos):
- position = pos
- show()
- $Collision.disabled = false
- func _input(event):
- if event.is_action_pressed("click"):
- miejsce_wcisniecia = get_global_mouse_position()
- func _process(delta):
- velocity = Vector2()
- if miejsce_wcisniecia:
- velocity = miejsce_wcisniecia - position
- if velocity.length() > 0:
- velocity = velocity.normalized() * SPEED
- $AnimatedSprite.play()
- else:
- $AnimatedSprite.stop()
- position += velocity * delta
- position.x = clamp(position.x, 0, screensize.x)
- position.y = clamp(position.y, 0, screensize.y)
- if velocity.x != 0:
- $AnimatedSprite.animation = "right"
- $AnimatedSprite.flip_v = false
- $AnimatedSprite.flip_h = velocity.x < 0
- elif velocity.y != 0:
- $AnimatedSprite.animation = "up"
- $AnimatedSprite.flip_v = velocity.y > 0
- func _on_Player_body_entered( body ):
- $Collision.disabled = true
- hide()
- emit_signal("hit")
Advertisement
Add Comment
Please, Sign In to add comment