-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.gd
More file actions
148 lines (126 loc) · 3.11 KB
/
Copy pathGameManager.gd
File metadata and controls
148 lines (126 loc) · 3.11 KB
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
extends Node
const SAVEFILE : String = 'user://SAVEFILE.save'
var is_vertical : bool = false
var is_loaded_from_disk : bool = false
# Player location
var location : Dictionary = {
'last_scene':'',
'current_scene':'',
'player_pos': Vector2.ZERO,
'checkpoint_scene':'',
'last_checkpoint':Vector2.ZERO
}
# Player stats
var stats : Dictionary = {
'HP':8,
'max_HP':8,
'MP':8,
'max_MP' : 8,
'XP':1,
'max_XP':8,
'LV':1,
'coins': 0,
'STR' : 4,
'DEF' : 4,
'INT' : 8,
'LCK' : 8
}
# Formula de subida de nivel en juegos RPG
# Formula exponencial
# ---
# XP para el siguiente nivel = (nivel actual ^ 2) * constante
## Formula lineal - sirve para fuerza, inteligencia, suerte, etc
# XP para el siguiente nivel = nivel actual * constante
# Player skills
var skills : Dictionary = {
'wall_jump' : false,
'dash' : false,
'wide_attack' : false
}
var _current_XP : int
var _current_LV : int
const STATS_CONST : Dictionary = {
'LV' : 8,
'HP' : 8,
'MP' : 8,
'INT': 8,
'STR': 8,
'DEF': 8,
'LCK': 8
}
# Called when the node enters the scene tree for the first time.
#func _ready(): pass # Replace with function body.
func _process(_delta):
if Input.is_action_just_pressed("Test"): PLAYER.reset_character()
if stats.XP != _current_XP:
stats.max_XP = (stats.LV ** 2) * STATS_CONST.LV
_current_XP = stats.XP
if stats.XP >= stats.max_XP:
stats.LV += 1
GUI.set_skill_message('Level Up')
if stats.LV != _current_LV:
stats.max_HP = stats.LV * STATS_CONST.HP
stats.max_MP = stats.LV * STATS_CONST.MP
stats.STR = stats.LV * STATS_CONST.STR
stats.DEF = stats.LV * STATS_CONST.DEF
stats.INT = stats.LV * STATS_CONST.INT
stats.LCK = stats.LV * STATS_CONST.LCK
func restore_health(HP: int):
stats.HP = stats.max_HP if HP + stats.HP > stats.max_HP else stats.HP + HP
func restore_MP(MP: int):
stats.MP = stats.max_MP if MP + stats.MP > stats.max_MP else stats.MP + MP
func load_data():
var file = FileAccess.open(SAVEFILE,FileAccess.READ)
if file == null:
save_data()
else:
var full_data = file.get_var()
print(full_data)
location = full_data.location
stats = full_data.stats
skills = full_data.skills
file = null
func save_data():
var file = FileAccess.open(SAVEFILE, FileAccess.WRITE)
var full_data : Dictionary = {
'location':location,
'stats':stats,
'skills':skills
}
file.store_var(full_data)
file = null
func default_data():
# Usado para el reinicio de los stats
var default_stats : Dictionary = {
'HP':8,
'max_HP':8,
'MP':8,
'max_MP' : 8,
'XP':1,
'max_XP':8,
'LV':1,
'coins': 0,
'STR' : 4,
'DEF' : 4,
'INT' : 8,
'LCK' : 8
}
# Player skills
var default_skills : Dictionary = {
'wall_jump' : false,
'dash' : false,
'wide_attack' : false
}
_current_XP = 0
_current_LV = 1
stats = default_stats
skills = default_skills
func restart_data(load_from_disk : bool):
# Es necesario borrar Last-Scene para que el personaje no sea cargado en sitios aleatorios
# Aun existe un error al accionar el Boton CONTINUE en main menu
location.last_scene = ''
is_loaded_from_disk = load_from_disk
if load_from_disk:
load_data()
else:
default_data()