-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.gd
44 lines (40 loc) · 1.24 KB
/
enemy.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
extends KinematicBody2D
# Declare member variables here. Examples:
var life: int = 1 #hits
var speed: int = 200
var vel: Vector2 = Vector2()
var screen_width = ProjectSettings.get_setting("display/window/size/width")
var screen_height = ProjectSettings.get_setting("display/window/size/height")
onready var sprite: Sprite = get_node("enemy_spaceship")
onready var user_interface: Node = get_node("/root/main_scene/canvas_ui/user_interface")
onready var sfx_player: Node = get_node("/root/main_scene/audio_player")
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _draw():
pass
func _notification(what):
#match what:
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
vel.y = 0
if position.y < screen_height:
vel.y += speed
elif position.y >= screen_height:
restart()
var collision_info = move_and_collide(vel * delta)
if collision_info:
if collision_info.collider.name.find("player",0) != -1:
user_interface.score_down(1)
restart()
func hit():
sfx_player.damage()
life -= 1
if life <= 0:
user_interface.score_up(1)
restart()
func restart():
life = 2
position.y = 0
position.x = randi()%screen_width