-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.gd
More file actions
48 lines (36 loc) · 1.24 KB
/
enemy.gd
File metadata and controls
48 lines (36 loc) · 1.24 KB
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
extends KinematicBody2D
var speed = 50
var velocity = Vector2()
export var direction = -1
export var detects_cliffs = true
func _ready():
if direction == 1:
$AnimatedSprite.flip_h = true
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction
$floor_checker.enabled = detects_cliffs
if detects_cliffs:
set_modulate(Color(1.2,0,5,1))
func _physics_process(delta):
if is_on_wall() or not $floor_checker.is_colliding() and detects_cliffs and is_on_floor():
direction = direction * -1
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction
velocity.y += 20
velocity.x = speed * direction
velocity = move_and_slide(velocity,Vector2.UP)
func _on_top_checker_body_entered(body):
$AnimatedSprite.play("squashed")
speed = 0
set_collision_layer_bit(4,false)
set_collision_mask_bit(0,false)
$top_checker.set_collision_layer_bit(4,false)
$top_checker.set_collision_mask_bit(0,false)
$sides_checker.set_collision_layer_bit(4,false)
$sides_checker.set_collision_mask_bit(0,false)
$Timer.start()
body.bounce()
$SoundSquash.play()
func _on_sides_checker_body_entered(body):
body.ouch(position.x)
func _on_Timer_timeout():
queue_free()