-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGame.gd
162 lines (148 loc) · 5.86 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
extends Node
class_name Game
@export_category("Development Options")
@export_enum("Normal", "Development") var run_type: int
@export_enum("None", "MainMenu", "Hills", "Wood", "Grasland", "GraslandHouse","SwordCave", "City", "CityShop", "SmallWood") var dev_start_map: String
@onready var world_holder = $WorldHolder
@onready var world_shadow_scene = preload("res://prefab/utils/WorldShadow.tscn")
var player: Player
var loaded_data = null
var new_game: bool = false
var change_player_spawn_location: bool = false
const LevelScenes: Dictionary = {
"MainMenu": preload("res://prefab/UI/MainMenu.tscn"),
"WorldBase": preload("res://world/WorldBase.tscn"),
"SmallCave": preload("res://world/SmallCave.tscn"),
"Wood": preload("res://world/Wood.tscn"),
"SwordCave": preload("res://world/SwordCave.tscn"),
"Grasland": preload("res://world/Grasland.tscn"),
"Hills": preload("res://world/Hills.tscn"),
"City": preload("res://world/City.tscn"),
"CityShop": preload("res://world/CityShop.tscn"),
"GraslandHouse": preload("res://world/GraslandHouse.tscn"),
"GameIntro": preload("res://prefab/UI/GameIntro.tscn"),
"SmallWood": preload("res://world/SmallWood.tscn"),
"CityCellar": preload("res://world/CityCellar.tscn"),
"CityHotel": preload("res://world/CityHotel.tscn"),
"CityAlchemy": preload("res://world/CityAlchemy.tscn"),
"CityFarm": preload("res://world/CityFarm.tscn"),
"WoodCave": preload("res://world/WoodCave.tscn"),
"DevWorld": preload("res://world/DevWorld.tscn")
}
const TELEPORT_SPAWN_LOCATIONS: Dictionary = {
"GraslandHouse": Vector2(1281, 246),
"WoodGrasland": Vector2(-349, 149),
"CityShop": Vector2(-1041, 164),
"WoodSmallWood": Vector2(-673, 271),
"CitySmallWood": Vector2(225, 595),
"CityHotelCity": Vector2(-240, -170),
"CityCellarCityHotel": Vector2(97, -294),
"CityAlchemyCity": Vector2(-816, 661),
"CityFarmCity": Vector2(-2768, -141),
"WoodCaveWood": Vector2(-607, 136)
}
var teleport_spawn_location: Vector2 = Vector2.ZERO
var world_shadow = null
func _process(delta):
G.delta = delta
func _ready():
GameManager.register_node(self)
EventHandler.connect("show_world_shadow", _on_show_world_shadow)
if GameManager.player:
player = GameManager.player
match run_type:
0:
switch_gamelevel("GameIntro")
1:
#_development_start()
switch_gamelevel("MainMenu")
func start_new_game():
QuestManager.reset_quests()
InventoryManager.reset_items()
D._reset_unique_data()
new_game = true
switch_gamelevel("Grasland")
func load_game():
GameManager.load_game = true
QuestManager.reset_quests()
InventoryManager.reset_items()
self.loaded_data = GameManager.load_savegame()
switch_gamelevel(loaded_data['cur_world'])
func _load_profile_game(data):
GameManager.load_game = true
QuestManager.reset_quests()
InventoryManager.reset_items()
self.loaded_data = data
D._load_unique_open_data(self.loaded_data['playername'])
switch_gamelevel(self.loaded_data['cur_world'])
func _on_show_world_shadow():
if world_shadow != null:
world_shadow.queue_free()
world_shadow = null
print("[!] Game: Shadow removed!")
var shadow = world_shadow_scene.instantiate()
GameManager.current_world.map_container.add_child(shadow)
GameManager.current_world.map_container.move_child(shadow, shadow.get_index()-1)
world_shadow = shadow
print("[!] Game: Shadow succesfully applied!")
func switch_gamelevel(levelname: String):
if levelname not in LevelScenes:
printerr("[X] Game: Scene: %s not found!" % levelname)
return
if world_shadow != null:
world_shadow.queue_free()
world_shadow = null
print("[!] Game: Shadow removed!")
if levelname == "MainMenu" or levelname == "GameIntro":
GameManager.on_main_menu = true
GameManager.interface.stat_hud.hide()
GameManager.interface.exp_hud.hide()
QuestManager.reset_quests()
GameManager.player = null
GameManager.interface.dot_hud.hide()
GameManager.interface.micro_menu.hide()
GameManager.current_world = null
GameManager.interface.actionbar.reset_bar()
GameManager.interface.actionbar.hide()
GameManager.interface.hide_ui()
else:
GameManager.interface.actionbar.show()
GameManager.on_main_menu = false
GameManager.interface.stat_hud.show()
GameManager.interface.exp_hud.show()
GameManager.interface.dot_hud.show()
GameManager.interface.micro_menu.show()
GameManager.interface.notice_box.show()
if not new_game:
self.loaded_data = D._load_profile_char_data(GameManager.selected_playername)
if world_holder.get_child_count() > 0:
if GameManager.current_world:
if GameManager.current_world.get_node_or_null("Map/CanvasModulate") != null:
var canvas_node = GameManager.current_world.get_node("Map/CanvasModulate")
canvas_node.get_parent().remove_child(canvas_node)
world_holder.get_child(0).call_deferred("queue_free")
var node = LevelScenes[str(levelname)].instantiate()
world_holder.call_deferred("add_child",node)
print("[!] Game: Current Level: \"%s\" successfully loaded!" % levelname)
func _change_player_spawn(location: String):
match location:
"WoodGrasland":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"GraslandHouse":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CityShop":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CitySmallWood":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"WoodSmallWood":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CityHotelCity":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CityCellarCityHotel":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CityAlchemyCity":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
"CityFarmCity":
self.teleport_spawn_location = self.TELEPORT_SPAWN_LOCATIONS[str(location)]
self.change_player_spawn_location = true
print("[!] Game: Change player spawn @ %s" % location)