aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorjacopograndi <jacopo.grandi@outlook.it>2022-02-08 11:24:51 +0100
committerjacopograndi <jacopo.grandi@outlook.it>2022-02-08 11:24:51 +0100
commiteea642395bb0ef706c7241d4a749f3e0ac4cc460 (patch)
tree6c015c9315b0102247661f942b018ccf8c45551d /scripts
parente8b2ea6b2bf789b7942d86faebbcc4d810741f25 (diff)
revised wave generation
Diffstat (limited to 'scripts')
-rw-r--r--scripts/control.gd59
-rw-r--r--scripts/enemies.gd5
-rw-r--r--scripts/globals.gd4
-rw-r--r--scripts/gui.gd6
-rw-r--r--scripts/gui_bottom_bar.gd4
-rw-r--r--scripts/gui_picker.gd16
-rw-r--r--scripts/load_map.gd17
-rw-r--r--scripts/spawner.gd2
-rw-r--r--scripts/wave.gd35
9 files changed, 124 insertions, 24 deletions
diff --git a/scripts/control.gd b/scripts/control.gd
index fafd3d8..2a9c76e 100644
--- a/scripts/control.gd
+++ b/scripts/control.gd
@@ -59,11 +59,12 @@ func build_option (st, sttype):
opts += [ { "type": "text", "name": "path" } ]
opts += [ { "type": "text", "name": "end path" } ]
Globals.StateType.VOXEL:
- for i in world.voxel_set.size():
+ for i in world.voxel_set.get_ids():
var details = world.voxel_set.get_voxel(i)
var color = Color(1, 0, 1)
if details.has("color"): color = details.color
opts += [ { "type": "color", "name": str(i), "color": color} ]
+ opts += [ { "type": "text", "name": "add" } ]
Globals.PlayerState.EDIT:
match sttype:
@@ -155,8 +156,19 @@ func do (action, par = {}):
Globals.PlayerState.PICK:
match action:
Globals.PlayerActions.PICK:
- selected = par.name
- state = Globals.PlayerState.PLACE
+ match statetype:
+ Globals.StateType.VOXEL:
+ match par.name:
+ "add":
+ selected = "add"
+ gui.edit_palette.popup()
+ build_option(state, statetype)
+ _:
+ selected = par.name
+ state = Globals.PlayerState.PLACE
+ _:
+ selected = par.name
+ state = Globals.PlayerState.PLACE
Globals.PlayerActions.SELECT:
match statetype:
@@ -174,6 +186,21 @@ func do (action, par = {}):
statetype = par.statetype
build_option(state, statetype)
+ Globals.PlayerActions.EDIT:
+ match statetype:
+ Globals.StateType.VOXEL:
+ match par.name:
+ "add":
+ selected = "add"
+ gui.edit_palette.popup()
+ build_option(state, statetype)
+ _:
+ selected = par.name
+ var dict = world.voxel_set.get_voxel(int(par.name))
+ gui.edit_palette.get_node("ColorPicker").color = dict.color
+ gui.edit_palette.popup()
+ build_option(state, statetype)
+
Globals.PlayerState.PLACE:
match action:
Globals.PlayerActions.PLACE:
@@ -205,6 +232,21 @@ func do (action, par = {}):
statetype = par.statetype
build_option(state, statetype)
+ Globals.PlayerActions.EDIT:
+ match statetype:
+ Globals.StateType.VOXEL:
+ match par.name:
+ "add":
+ selected = "add"
+ gui.edit_palette.popup()
+ build_option(state, statetype)
+ _:
+ selected = par.name
+ var dict = world.voxel_set.get_voxel(int(par.name))
+ gui.edit_palette.get_node("ColorPicker").color = dict.color
+ gui.edit_palette.popup()
+ build_option(state, statetype)
+
Globals.PlayerState.EDIT:
match action:
Globals.PlayerActions.PICK:
@@ -315,3 +357,14 @@ func gui_change_map_event (mapname : String):
path.refresh_path(ineditor)
gui.refresh()
+
+func gui_picked_color (color : Color):
+ if selected != "add":
+ var dict = world.voxel_set.get_voxel(int(selected))
+ dict.color = color
+ world.voxel_set.set_voxel(int(selected), dict)
+ else:
+ world.voxel_set.add_voxel({"color":color})
+ world.update_mesh()
+ build_option(state, statetype)
+ gui.refresh()
diff --git a/scripts/enemies.gd b/scripts/enemies.gd
index a0f4416..3e8276d 100644
--- a/scripts/enemies.gd
+++ b/scripts/enemies.gd
@@ -45,13 +45,14 @@ func _ready():
load_shapes = saveload.get_node("load_shapes")
if !load_shapes.loaded: yield(load_shapes, "done_loading")
-func spawn(name, node_cur=0, rel_pos=0):
+func spawn(name, node_cur=0, rel_pos=0, hp=0):
print("spawned " + name)
var instance = _enemy_blue.instance()
add_child(instance)
instance.transform.origin = _path.nodes[0].transform.origin;
instance.name = str(serial_enemy)
var info = load_shapes.info[name]
+ if hp == 0: hp = info.lives
var instance_model = load_shapes.models[info.model_name].instance()
instance.add_child(instance_model)
@@ -60,7 +61,7 @@ func spawn(name, node_cur=0, rel_pos=0):
var axis : Vector3 = Quat(Vector3(0, randf()*TAU, 0)) * Vector3.RIGHT
enemies[serial_enemy] = {
"name": name,
- "hp": info.lives,
+ "hp": hp,
"slow_effect": 0,
"slow_time": 0,
"cur": node_cur,
diff --git a/scripts/globals.gd b/scripts/globals.gd
index dc30b38..17318f7 100644
--- a/scripts/globals.gd
+++ b/scripts/globals.gd
@@ -11,7 +11,6 @@ enum StateType {
ATTACH,
PATH,
VOXEL,
- VOXEL_PALETTE
TARGETING
MODULES
MODULES_PICK
@@ -23,5 +22,6 @@ enum PlayerActions {
PLACE,
SELECT,
DELETE,
- CANCEL
+ CANCEL,
+ EDIT
}
diff --git a/scripts/gui.gd b/scripts/gui.gd
index 2e63483..65ff39b 100644
--- a/scripts/gui.gd
+++ b/scripts/gui.gd
@@ -10,6 +10,7 @@ var wave_ongoing : Panel
var load_map : PanelContainer
var save_as : AcceptDialog
var delete_confirm : AcceptDialog
+var edit_palette : AcceptDialog
var saveload : Node
var saveload_map : Node
@@ -30,6 +31,8 @@ func _fetch ():
save_as.register_text_enter(save_as.get_node("line_edit"))
if delete_confirm == null:
delete_confirm = $delete_confirm
+ if edit_palette == null:
+ edit_palette = $edit_palette
func _ready():
_fetch()
@@ -59,3 +62,6 @@ func _on_delete_confirmed():
func _on_close_load_map():
load_map.visible = false
+
+func _on_edit_palette_confirmed():
+ control.gui_picked_color(edit_palette.get_node("ColorPicker").color)
diff --git a/scripts/gui_bottom_bar.gd b/scripts/gui_bottom_bar.gd
index af987a4..f8012d3 100644
--- a/scripts/gui_bottom_bar.gd
+++ b/scripts/gui_bottom_bar.gd
@@ -42,10 +42,6 @@ func _on_voxel_button_up():
gui.control.do(Globals.PlayerActions.CHANGE_TYPE,
{ "statetype": Globals.StateType.VOXEL })
-func _on_palette_button_up():
- gui.control.do(Globals.PlayerActions.CHANGE_TYPE,
- { "statetype": Globals.StateType.VOXEL_PALETTE })
-
func _on_save_button_up():
gui.control.gui_save_map_event()
diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd
index 85909ec..f9a27fa 100644
--- a/scripts/gui_picker.gd
+++ b/scripts/gui_picker.gd
@@ -40,7 +40,7 @@ func build (options : Array = []):
for child in _hbox.get_children():
child.disconnect("mouse_entered", self, "_on_gui_turret_mouse_entered")
child.disconnect("mouse_exited", self, "_on_gui_turret_mouse_exited")
- child.disconnect("pressed", self, "_on_gui_turret_pressed")
+ child.disconnect("gui_input", self, "_on_gui_turret_input")
child.queue_free()
_options = options
@@ -77,7 +77,7 @@ func build (options : Array = []):
for child in _hbox.get_children():
child.connect("mouse_entered", self, "_on_gui_turret_mouse_entered", [child.option])
child.connect("mouse_exited", self, "_on_gui_turret_mouse_exited", [child.option])
- child.connect("pressed", self, "_on_gui_turret_pressed", [child.option])
+ child.connect("gui_input", self, "_on_gui_turret_input", [child.option])
func refresh ():
_fetch()
@@ -89,4 +89,14 @@ func _on_gui_turret_mouse_exited(option : Dictionary):
hovering = ""
func _on_gui_turret_pressed(option : Dictionary):
- gui.control.do(Globals.PlayerActions.PICK, option)
+ #gui.control.do(Globals.PlayerActions.PICK, option)
+ pass
+
+func _on_gui_turret_input(event, option : Dictionary):
+ if event is InputEventMouseButton and event.pressed:
+ match event.button_index:
+ BUTTON_LEFT:
+ gui.control.do(Globals.PlayerActions.PICK, option)
+ BUTTON_RIGHT:
+ gui.control.do(Globals.PlayerActions.EDIT, option)
+
diff --git a/scripts/load_map.gd b/scripts/load_map.gd
index 13d9255..6a2c67c 100644
--- a/scripts/load_map.gd
+++ b/scripts/load_map.gd
@@ -1,7 +1,7 @@
extends Node
var mapname = "map0.json"
-var mappath = "user://"
+var mappath = "./assets/maps/"
var _world : VoxelMesh = null
var _path_holder : Node = null
@@ -29,6 +29,14 @@ func get_map_state ():
fetch()
var state = {}
+ state["voxels-palette"] = []
+ for id in _world.voxel_set.get_ids():
+ var col : Color = _world.voxel_set.get_voxel(id).color
+ var pal = {
+ "color": [ col.r, col.g, col.b, col.a ],
+ "id": id }
+ state["voxels-palette"] += [pal]
+
state["voxels"] = []
for pos in _world.get_voxels():
var vox = { "pos": [pos.x, pos.y, pos.z], "id":_world.get_voxel_id(pos) }
@@ -60,7 +68,14 @@ func get_map_state ():
func set_map_state (state):
fetch()
+
_world.erase_voxels()
+
+ _world.voxel_set.erase_voxels()
+ for vox in state["voxels-palette"]:
+ var col = Color(vox.color[0], vox.color[1], vox.color[2], vox.color[3])
+ _world.voxel_set.add_voxel({ "color": col })
+
for vox in state["voxels"]:
var vecpos = Vector3(vox.pos[0], vox.pos[1], vox.pos[2]);
_world.set_voxel(vecpos, vox.id)
diff --git a/scripts/spawner.gd b/scripts/spawner.gd
index 9866168..284ae76 100644
--- a/scripts/spawner.gd
+++ b/scripts/spawner.gd
@@ -20,5 +20,5 @@ func _on_timer_batch_timeout():
queue_free()
return
- enemy_holder.spawn(n.enemy)
+ enemy_holder.spawn(n.enemy, 0, 0, n.hp)
start(n.cooldown)
diff --git a/scripts/wave.gd b/scripts/wave.gd
index e61dfef..691b703 100644
--- a/scripts/wave.gd
+++ b/scripts/wave.gd
@@ -10,6 +10,8 @@ var ongoing = false
var load_shapes : Node
var gui : Node
+var rng = RandomNumberGenerator.new()
+
func fetch ():
var root = get_tree().root.get_node("world")
var saveload = root.get_node("saveload")
@@ -22,7 +24,8 @@ func make_queue (spawn):
for n in order.amount:
var e = {
"cooldown": order.cooldown,
- "enemy": order.enemy
+ "enemy": order.enemy,
+ "hp": order.hp
}
queue += [e]
if spawn.random: queue.shuffle()
@@ -50,25 +53,40 @@ func get_affordable_enemies (hp_budget : int):
if load_shapes.info[enemy].cost <= hp_budget:
aff += [load_shapes.info[enemy]]
return aff
+
+func sort_aff_comp(a, b): return a.cost < b.cost
-func pick_enemy (hp_budget : int):
+func pick_enemy (hp_budget : int, density : float, height: float):
var amt = 1
var aff = get_affordable_enemies(hp_budget)
- var enemy = aff[randi() % aff.size()]
+ aff.sort_custom(self, "sort_aff_comp")
+
+ #var rn = rng.randf()
+ #var pick : float = pow(rn, 2*height*(1-rn) + rn)
+ var enemy = aff[round(height * (aff.size()-1))]
+
+ var cooldown : float = rng.randf() * pow(4, density - 0.5)
+
+ var hp_adjusted = max(1, enemy.lives * height)
+ var cost = enemy.cost - enemy.lives + hp_adjusted
+
+ print(cost)
+
var order = {
"amount" : amt,
"enemy": enemy.name,
- "cooldown": 0.5
+ "hp": hp_adjusted,
+ "cooldown": cooldown
}
- return { "enemy": order, "cost": enemy.cost }
+ return { "enemy": order, "cost": cost }
-func gen_wave (wave_num : int):
+func gen_wave (wave_num : int, density : float, height: float):
var hp_budget = get_hp_budget(wave_num)
var enemies = []
for i in range(0, 1000):
if hp_budget < 10: break
- var enemy_cost = pick_enemy(hp_budget)
+ var enemy_cost = pick_enemy(hp_budget, density, height)
enemies += [ enemy_cost.enemy ]
hp_budget -= enemy_cost.cost
@@ -82,10 +100,11 @@ func gen_wave (wave_num : int):
func start():
fetch()
+ rng.randomize()
ongoing = true
var w = null
if wave_num <= waves.size()-1: w = waves[wave_num]
- else: w = gen_wave(wave_num)
+ else: w = gen_wave(wave_num, 0.5, 0.2)
start_wave(w)
func end():