-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun.gd
25 lines (21 loc) · 719 Bytes
/
gun.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
extends Area2D
var game_over : bool
var shoot_speed : float
@onready var timer = %ShootTimer
func _physics_process(_delta):
shoot_speed = SceneSwitcher.shoot_speed
timer.wait_time = shoot_speed
game_over = SceneSwitcher.game_over
var enemies_in_range = get_overlapping_bodies()
if enemies_in_range.size() > 0:
var target_enemy = enemies_in_range.front()
look_at(target_enemy.position)
func shoot():
const BULLET = preload("res://bullet.tscn")
var new_bullet = BULLET.instantiate()
new_bullet.global_position = %shootingPoint.global_position
new_bullet.global_rotation = %shootingPoint.global_rotation
%shootingPoint.add_child(new_bullet)
func _on_timer_timeout():
if game_over == false:
shoot()