-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboss.gd
More file actions
58 lines (43 loc) · 1.18 KB
/
boss.gd
File metadata and controls
58 lines (43 loc) · 1.18 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
49
50
51
52
53
54
55
56
57
58
extends CharacterBody2D
const speed = 50
var startingOrientation = scale.x
var direction = 1
var hasSwitchedDirection = false
var bossHP = 3
func _ready():
var ray_right = $RayCastRight
var ray_down2 = $RayCastDown2
# Example: enable all raycasts
ray_right.enabled = true
ray_down2.enabled = true
func startTimer():
await get_tree().create_timer(0.3).timeout
hasSwitchedDirection = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
velocity.x = direction * speed
if not hasSwitchedDirection:
if $RayCastRight.is_colliding():
direction *= -1
scale.x *= -1
hasSwitchedDirection = true
startTimer()
if not $RayCastDown2.is_colliding():
direction *= -1
scale.x *= -1
hasSwitchedDirection = true
startTimer()
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
move_and_slide()
func _on_killarea_area_entered(area: Area2D) -> void:
if area.is_in_group("sword"):
bossHP -= 1
if position.x >= 0:
position.x += 60
else:
position.x -= 60
if bossHP == 0:
queue_free()