-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.gd
147 lines (118 loc) · 4.62 KB
/
game.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
extends Node2D
var second_counter = 0
var time_minutes = 0
var time_hours = 7
var time_days = 0
var daystate = "day"
var inter = 0
var standlerp = 0
var grim_camera_focus = false
onready var crowspawn = preload("res://crow.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
$CanvasLayer/pause/volume.value = Global.volume
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var cancrowspawn = false
for i in Global.inventory:
if Global.inventory[i]>0 and !(i in ["mill-o-tron", "scythe+", "fertilizer", "crow cash"]):
cancrowspawn = true
if Input.is_action_just_pressed("one"):
Global.held_item = 0
if Input.is_action_just_pressed("two"):
Global.held_item = 1
if Input.is_action_just_pressed("three"):
Global.held_item = 2
match Global.slots[2]:
"":
$CanvasLayer/gui/slot3/TextureRect.texture = null
"wheat seed":
$CanvasLayer/gui/slot3/TextureRect.texture = preload("res://assets/crops/wheat/1.png")
"barley seed":
$CanvasLayer/gui/slot3/TextureRect.texture = preload("res://assets/crops/barley/1.png")
"oat seed":
$CanvasLayer/gui/slot3/TextureRect.texture = preload("res://assets/crops/oats/1.png")
"rice seed":
$CanvasLayer/gui/slot3/TextureRect.texture = preload("res://assets/crops/rice/1.png")
second_counter += delta * Global.time_scale
$AudioStreamPlayer.pitch_scale = clamp(Global.time_scale,0.01,1)
if second_counter >= 1:
time_minutes += 10
second_counter = 0
if time_minutes>=60:
time_hours += 1
time_minutes = 0
if time_hours % 3 == 0 and cancrowspawn:
var c = crowspawn.instance()
add_child(c)
if time_hours>=24:
time_hours = 0
time_days += 1
if time_days % 3 == 0:
Global.time_going = false
Global.grim_reaper = true
grim_camera_focus = true
print("grim reaper")
$CanvasLayer/inventory.visible = false
$player.state = "free"
# stand opening and closing times
if time_hours == 12:
$CanvasLayer/notification.notify("shops opened at the top!")
if time_hours>=12 and time_hours<18:
standlerp += 0.01
$stands.visible = true
else:
$stands.visible = false
standlerp -= 0.01
standlerp = clamp(standlerp,0,1)
$stands.position.y = lerp(-64,0,standlerp)
if time_hours>=18:
daystate = "night"
if time_hours>=6 and time_hours<18:
daystate = "day"
$CanvasLayer/gui/time_and_cash.bbcode_text = "[right]"
$CanvasLayer/gui/time_and_cash.bbcode_text += str(time_hours)+":"+str(time_minutes)
if time_minutes<10:
$CanvasLayer/gui/time_and_cash.bbcode_text += "0"
$CanvasLayer/gui/time_and_cash.bbcode_text += "\n"+daystate+" "+str(time_days)+"\n"
$CanvasLayer/gui/time_and_cash.bbcode_text += "[color=#FFD700]$"+str(Global.money)+"[/color]"
if grim_camera_focus:
$Camera2D.position.x = clamp($grim_reaper.position.x,0+$Camera2D.get_viewport_rect().size.x/2,384-$Camera2D.get_viewport_rect().size.x/2)
$Camera2D.position.y = clamp($grim_reaper.position.y,0+$Camera2D.get_viewport_rect().size.y/2,384-$Camera2D.get_viewport_rect().size.y/2)
else:
$Camera2D.position.x = clamp($player.position.x,0+$Camera2D.get_viewport_rect().size.x/2,384-$Camera2D.get_viewport_rect().size.x/2)
$Camera2D.position.y = clamp($player.position.y,0+$Camera2D.get_viewport_rect().size.y/2,384-$Camera2D.get_viewport_rect().size.y/2)
if Input.is_action_just_pressed("inventory"):
$CanvasLayer/inventory.visible = not $CanvasLayer/inventory.visible
if Input.is_action_just_pressed("pause") and !$CanvasLayer/inventory.visible and !$CanvasLayer/selling_menu.visible:
pass # pause game
if Input.is_action_just_pressed("pause") and $CanvasLayer/inventory.visible:
$CanvasLayer/inventory.visible = false
if Input.is_action_just_pressed("pause") and $CanvasLayer/selling_menu.visible:
$CanvasLayer/selling_menu.visible = false
if daystate == "night":
inter += delta/6
if daystate == "day":
inter -= delta/6
inter = clamp(inter,0,1)
$CanvasModulate.color = lerp(Color(1,1,1),Color(0.5,0.5,0.8),inter)
func _on_close_pressed(): # close inventory
$CanvasLayer/inventory.visible = false
func _on_selling_close_pressed():
$CanvasLayer/selling_menu.visible = false
func _on_sell_pressed():
if not $CanvasLayer/inventory.visible:
$CanvasLayer/selling_menu.show()
$CanvasLayer/upgrades.visible = false
func _on_closeupgrad_pressed():
$CanvasLayer/upgrades.visible = false
func _on_magic_pressed():
if not $CanvasLayer/upgrades.visible:
$CanvasLayer/upgrades.show()
$CanvasLayer/selling_menu.visible = false
func _on_volume_value_changed(value):
Global.volume = value
func _on_menu_pressed():
get_tree().change_scene("res://menu.tscn")