-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.gd
68 lines (48 loc) · 2.18 KB
/
character.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extends Spatial
onready var _projectile_manager := get_parent().get_node("ProjectileManager")
onready var _barrel := $Barrel
export var move_speed := 5.0
export var _spread_shot := true
export var _spread_amount := 10 #Total amount will be n^2
export var _spread_angle := 90.0 #In euler degrees
export var _firing_time := 0.1
var _elapsed_firing_time := 0.0
var _look_plane := Plane()
func _init() -> void:
_look_plane.normal = Vector3.UP
func _ready() -> void:
_projectile_manager.projectile_speed = 25.0
_projectile_manager.projectile_lifetime = 3.0
_projectile_manager.enemy_health = 10
_projectile_manager.enemy_speed = 1.0
_projectile_manager.enemy_target = self
func _process(delta: float) -> void:
var mouse = get_viewport().get_mouse_position()
var camera = get_viewport().get_camera()
var origin = camera.project_ray_origin(mouse)
var direction = camera.project_ray_normal(mouse)
var result = _look_plane.intersects_ray(origin, direction)
if result:
var look_transform = transform.looking_at(result, Vector3.UP)
transform = look_transform
var horizontal = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
var vertical = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
var move_direction = Vector3(horizontal, 0, vertical).normalized()
translation += move_direction * move_speed * delta
if Input.is_mouse_button_pressed(BUTTON_LEFT):
if _elapsed_firing_time >= _firing_time:
if _spread_shot:
_projectile_manager.create_projectiles_spreadshot(_spread_amount, _barrel.global_transform, _spread_angle)
else:
_projectile_manager.create_projectiles(1000, _barrel.global_transform)
_elapsed_firing_time = 0.0
if Input.is_mouse_button_pressed(BUTTON_RIGHT):
var begin = 0
var end = min(100, _projectile_manager.get_projectile_count())
if end <= _projectile_manager.get_projectile_count():
_projectile_manager.destroy_projectiles(begin, end)
_elapsed_firing_time += delta
if Input.is_key_pressed(KEY_SPACE):
var radius = 20
var position = Vector3(rand_range(-radius, radius), 0, rand_range(-radius, radius))
_projectile_manager.create_enemies(1, Transform(Basis(), position))