-
Notifications
You must be signed in to change notification settings - Fork 0
/
Daemon.gd
52 lines (40 loc) · 1.09 KB
/
Daemon.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
extends KinematicBody2D
const SPEED = 100
const GRAVITY = 750
var velocity = Vector2()
var direction = -1
func set_direction(direction_: int):
if direction_ == -1:
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = true
elif direction_ == 1:
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = false
elif direction_ == 0:
$AnimatedSprite.play("idle")
else:
return
direction = direction_
func _ready():
set_direction(0)
onready var player = get_node(@"/root/Main/Player")
func distance_to(target_node):
var a = Vector2(target_node.get_pos() - $".".get_pos())
return sqrt((a.x * a.x) + (a.y * a.y))
func _physics_process(delta):
var a = Vector2(player.position - position)
var dist = sqrt((a.x * a.x) + (a.y * a.y))
for i in get_slide_count():
var collision = get_slide_collision(i)
if collision.collider.name == "Player":
print("Попался!")
if dist < 250:
if a.x > 0:
set_direction(1)
else:
set_direction(-1)
else:
set_direction(0)
velocity.x = SPEED * direction
velocity.y += GRAVITY * delta
velocity = move_and_slide(velocity, Vector2.UP)