-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMob.gd
52 lines (40 loc) · 1.08 KB
/
Mob.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
extends RigidBody2D
func setup(mobType):
$AnimatedSprite.playing = true
$AnimatedSprite.animation = mobType.name
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_start_game():
queue_free()
func get_mob_props(mobInstance, spawn):
var id = randi() % 3 + 1
var name
var speed
if(id == 1):
name = "enemySlow"
speed = 100
if(id == 2):
name = "enemyMedium"
speed = 300
if(id == 3):
name = "enemyFast"
speed = 500
# Set the mob's direction perpendicular to the path direction.
var direction = spawn.rotation + PI / 2
# Set the mob's position to a random location.
mobInstance.position = spawn.position
# Add some randomness to the direction.
direction += rand_range(-PI / 4, PI / 4)
mobInstance.rotation = direction
# Choose the velocity.
var velocity = Vector2(speed, 0)
mobInstance.linear_velocity = velocity.rotated(direction)
return {
"name": name,
"speed": speed,
"direction": direction,
"position": mobInstance.position,
"rotation": mobInstance.rotation,
"velocity": velocity,
"linear_velocity": mobInstance.linear_velocity
}