forked from Chaitanyassr/Monster-Smash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFO4.gd
43 lines (37 loc) · 1.02 KB
/
UFO4.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
extends Node2D
var speed = 100
var direction = Vector2()
var width
var height
var hit = false
var lose = false
var clicks = score.score1
func _ready():
position = get_viewport_rect().size / 2
direction.x = rand_range(-1, 1)
direction.y = rand_range(-1, 1)
direction = direction.normalized()
width = get_viewport_rect().size.x
height = get_viewport_rect().size.y
func _process(delta):
position += direction * speed * delta
if position.x < 0:
direction.x = -direction.x
if position.x > width:
direction.x = -direction.x
if position.y < 0:
direction.y = -direction.y
if position.y > height:
direction.y = -direction.y
func _on_UFO_input_event( viewpoint, event, shape_idx ):
if lose:
return
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
direction.x = rand_range(-1, 1)
direction.y = rand_range(-1, 1)
direction = direction.normalized()
position.x = rand_range(1, width -1)
position.y = rand_range(1, height -1)
speed += 600
hit = true
$HITSound.play()