-
Notifications
You must be signed in to change notification settings - Fork 0
/
crow.gd
75 lines (63 loc) · 2.31 KB
/
crow.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
69
70
71
72
73
74
75
extends Area2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var dir = 0
var target = null
var spawn = Vector2()
var stole = ""
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
position.x = 160*((randi()%3) - 1)
position.y = 160*((randi()%3) - 1)
spawn = position
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var cansteal = false
if !stole:
for i in Global.inventory:
if Global.inventory[i]>0 and !(i in ["mill-o-tron", "scythe+", "fertilizer", "crow cash"]):
cansteal = true
if cansteal:
if target == null:
target = get_node("../player")
if target != null:
position += position.direction_to(target.global_position).normalized()*(0.02/delta) * Global.time_scale
$Sprite.rotation = position.angle_to_point(target.global_position) + PI
else:
position += position.direction_to(spawn).normalized()*(0.02/delta) * Global.time_scale
$Sprite.rotation = position.angle_to_point(spawn) + PI
if position.distance_to(spawn) <8:
queue_free()
else:
position += position.direction_to(spawn).normalized()*(0.02/delta) * Global.time_scale
$Sprite.rotation = position.angle_to_point(spawn) + PI
if position.distance_to(spawn) <8:
queue_free()
func _on_crow_area_entered(area):
if area in get_tree().get_nodes_in_group("player_scythe"):
Global.money += Global.inventory["crow cash"]
var c = preload("res://crowsplosion.tscn").instance()
c.position = self.position
get_parent().add_child(c)
c.emitting = true
c.get_node("AudioStreamPlayer2D").play()
if stole:
Global.inventory[stole] +=1
self.queue_free()
func _on_crow_body_entered(body):
var cansteal = false
for i in Global.inventory:
if Global.inventory[i]>0 and !(i in ["mill-o-tron", "scythe+", "fertilizer", "crow cash"]):
cansteal = true
if body.name == "player" and cansteal:
var list_of_stealables = []
for i in Global.inventory:
if Global.inventory[i]>0 and !(i in ["mill-o-tron", "scythe+", "fertilizer", "crow cash"]):
list_of_stealables.append(i)
var thing = list_of_stealables[randi() % len(list_of_stealables)]
get_parent().get_node("CanvasLayer/notification").notify("a crow stole "+thing)
Global.inventory[thing] -= 1
stole = thing