-
Notifications
You must be signed in to change notification settings - Fork 1
/
Boulder 1.gd
36 lines (27 loc) · 886 Bytes
/
Boulder 1.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
extends KinematicBody2D
signal boulder_removed
signal boulder_hit
export (int) var speed = 100
export (Vector2) var velocity = Vector2()
func _ready():
add_to_group("boulders")
func _physics_process(delta):
_remove_when_offscreen()
var collision = move_and_collide(velocity * delta)
if collision:
_boulder_collision(collision)
func _boulder_collision(collision):
collision.collider.on_boulder_collision(self)
func _remove_when_offscreen():
var screen_size = get_viewport_rect().size
if global_position.y < 0 \
or global_position.y > screen_size.y \
or global_position.x < 0 \
or global_position.x > screen_size.x:
_remove_rock()
func _remove_rock():
queue_free()
emit_signal("boulder_removed")
func on_bullet_hit(bullet):
emit_signal("boulder_hit", self, 1)
_remove_rock()