diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-14 00:06:52 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-14 00:06:52 +0100 |
commit | 90af765b430e3a75daa9b2b4d0343ae58ad5c33d (patch) | |
tree | 024e803ce9b7476ed310fc156b54eb5ebced3c4f /scripts | |
parent | 7cb4290601010459b09376396c7833ec391c25bf (diff) |
secret work
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/debug.gd | 21 | ||||
-rw-r--r-- | scripts/gui_picker.gd | 17 | ||||
-rw-r--r-- | scripts/gui_turret_detail.gd | 63 | ||||
-rw-r--r-- | scripts/load_turrets.gd | 2 | ||||
-rw-r--r-- | scripts/movement.gd | 5 | ||||
-rw-r--r-- | scripts/placer.gd | 71 | ||||
-rw-r--r-- | scripts/turret.gd | 29 |
7 files changed, 150 insertions, 58 deletions
diff --git a/scripts/debug.gd b/scripts/debug.gd deleted file mode 100644 index b65bd79..0000000 --- a/scripts/debug.gd +++ /dev/null @@ -1,21 +0,0 @@ -extends Panel - -var _player -var _path -var _enemies - -func _ready(): - _path = get_tree().root.get_child(0).get_node("path") - _player = get_tree().root.get_child(0).get_node("player") - _enemies = get_tree().root.get_child(0).get_node("enemies") - -func _process(delta): - pass - - -func _on_Button_button_down(): - _enemies.spawn() - -func _on_Button2_button_down(): - var res = _path.load_nodes() - _path.hide() diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd index df4ee9b..0dc4dcb 100644 --- a/scripts/gui_picker.gd +++ b/scripts/gui_picker.gd @@ -2,14 +2,17 @@ extends Panel var _hbox : HBoxContainer var _gui_button : Resource = load("res://scenes/gui/gui_turret.tscn") +var _gui_detail : Resource = load("res://scenes/gui/gui_turret.tscn") var _options = [] var gui : Control +var hovering = "" + func _fetch (): if gui == null: gui = get_parent().gui - if _hbox == null: _hbox = $ScrollContainer/Hbox + if _hbox == null: _hbox = $Hbox func build (options : Array = []): _fetch() @@ -27,23 +30,23 @@ func build (options : Array = []): for child in _hbox.get_children(): if child.get_signal_connection_list("pressed").size() == 0: child.connect("mouse_entered", self, "_on_gui_turret_mouse_entered", [child.name]) - child.connect("mouse_exited", self, "_on_gui_turret_mouse_entered", [child.name]) + child.connect("mouse_exited", self, "_on_gui_turret_mouse_exited", [child.name]) child.connect("pressed", self, "_on_gui_turret_pressed", [child.name]) -func refresh (sel = ""): +func refresh (sel): _fetch() - if sel.type == "": + if sel.type == "idle": for child in _hbox.get_children(): child.picked = false if sel.type == name: for child in _hbox.get_children(): child.picked = child.name == sel.name func _on_gui_turret_mouse_entered(name : String): - print(name + " entered from " + self.name) + hovering = name; func _on_gui_turret_mouse_exited(name : String): - print(name + " exited from " + self.name) + hovering = "" func _on_gui_turret_pressed(name : String): - print(name + " pressed from " + self.name) + print(self.name + ' ' + name) gui.player.selected_event(name, self.name) diff --git a/scripts/gui_turret_detail.gd b/scripts/gui_turret_detail.gd new file mode 100644 index 0000000..df89c14 --- /dev/null +++ b/scripts/gui_turret_detail.gd @@ -0,0 +1,63 @@ +extends Panel + +var hbox_labels +var hbox_global +var _turret_values : Resource = load("res://scenes/gui/gui_turret_values.tscn") +var load_turrets : Node + +var gui : Control + +func _fetch (): + if gui == null: gui = get_parent() + if hbox_labels != null: return; + hbox_labels = $"hbox_global/hbox_labels" + hbox_global = $"hbox_global" + + var root = get_tree().root.get_child(0) + load_turrets = root.get_node("saveload").get_node("load_turrets") + if !load_turrets.loaded: yield(load_turrets, "done_loading") + + +func refresh (turret : Dictionary, upgraded : Dictionary = {}): + _fetch() + if upgraded == null: rect_min_size.x = 200 + else: rect_min_size.x = 230 + + get_node("name_label").text = "name: " + turret.name + + var dict = { + "damage": turret.get("damage", "-"), + "range": turret.get("range", "-"), + "turn speed": turret.get("turn_speed", "-"), + "cooldown": turret.get("cooldown", "-"), + "projectile": turret.get("projectile", {}).get("type", "-"), + "spread": turret.get("projectile", {}).get("spread", "-"), + "projectile speed": turret.get("projectile", {}).get("speed", "-"), + "projectiles per shot": turret.get("projectile", {}).get("amount", "-"), + "modules": turret.get("modules_max", "-"), + } + + var base_values = hbox_global.get_node("hbox_values") + for k in dict: + base_values.get_node(k).text = str(dict[k]); + +func _process(delta): + _fetch() + + var info = null; + + var hovering = gui.bottom_bar.turret_picker.hovering + if gui.player.highlight != null: + info = gui.player.highlight.info + elif gui.player.sel.type == "turrets": + info = load_turrets.info[gui.player.sel.name] + elif hovering != "": + info = load_turrets.info[hovering] + elif gui.player.placer.colliding \ + and "turrets" in gui.player.placer.colliding_group: + info = gui.player.placer.colliding_node.info + + if info != null: + refresh(info) + self.visible = true + else: self.visible = false diff --git a/scripts/load_turrets.gd b/scripts/load_turrets.gd index 3c9f378..ba2e198 100644 --- a/scripts/load_turrets.gd +++ b/scripts/load_turrets.gd @@ -25,7 +25,7 @@ func get_base_turrets(): var flag = true for oth in info.values(): if oth.name == turr.name: continue - if turr.name in oth.upgrades: + if turr.name in oth.get("upgrades", {}): flag = false if flag: results.append(turr) return results diff --git a/scripts/movement.gd b/scripts/movement.gd index 587b338..fb9e7bd 100644 --- a/scripts/movement.gd +++ b/scripts/movement.gd @@ -28,10 +28,12 @@ var ptr : Node var _enemies : Node var sel = { - "type": "", + "type": "idle", "name": "" } +var highlight : Spatial + func _ready(): camera = $camera placer = $placer @@ -76,6 +78,7 @@ func selected_event (sel_name, sel_type): _gui.refresh(in_editor) if sel_type == "turrets": + for child in ptr.get_children(): child.queue_free(); var info = load_turrets.info[sel.name] var model = load_turrets.models[info.model_name] var instance_model = model.instance() diff --git a/scripts/placer.gd b/scripts/placer.gd index f06944e..e68ef5b 100644 --- a/scripts/placer.gd +++ b/scripts/placer.gd @@ -39,24 +39,31 @@ func _physics_process(_delta): _pointer() func check_overlap_pointer(): - var overlap = false + var overlap = "clear" var space = get_world().direct_space_state var center = ptr.transform.origin + normal*0.25 - var shape: = BoxShape.new() + var shape = BoxShape.new() shape.extents = Vector3(0.24, 0.24, 0.24) + var info = load_turrets.info[player.sel.name] + if info.has("collider"): + if info.collider == "sphere": + shape = SphereShape.new() + shape.radius = 0.24 + var params: = PhysicsShapeQueryParameters.new() params.set_shape(shape) params.collision_mask = 3 - params.transform = Transform.IDENTITY + params.transform = ptr.transform params.transform.origin = center + params.transform.basis = ptr.transform.basis var result = space.intersect_shape(params) for body in result: if !body.collider.get_parent().is_in_group("attach"): - overlap = true + overlap = "world" break for pos in world.get_voxels(): @@ -64,14 +71,14 @@ func check_overlap_pointer(): wpos += Vector3.ONE * (0.5 / 2) var dist = (wpos - center).length_squared() if dist < 0.1: - overlap = true + overlap = "voxels" break for node in path_holder.get_children(): var pos = node.transform.origin var dist = (pos - center).length_squared() if dist < 0.1: - overlap = true + overlap = "path" break return overlap @@ -90,8 +97,24 @@ func _inst_turret (pos, rot): instance.add_child(instance_model) instance.refresh_model() + for child in instance.pivot.get_children(): + if "attach" in child.name: + child.add_to_group("attach") + var apos = child.global_transform.origin + var arot = child.global_transform.basis.get_rotation_quat() + instance.pivot.add_child(_inst_attach(apos, arot)) + child.queue_free() + instance.refresh_info(info) + var sb = instance.get_node("turret") + if info.has("collider"): + if info.collider == "sphere": + sb.get_node("CollisionShapeBox").queue_free(); + sb.get_node("CollisionShapeSphere").disabled = false; + else: + sb.get_node("CollisionShapeSphere").queue_free(); + func _inst_path_start (pos, rot): var instance = load_scenes.path_start.instance() path_holder.add_child(instance) @@ -117,11 +140,14 @@ func _inst_attach (pos, rot): attach_point_holder.add_child(instance) instance.transform.origin = pos; instance.transform.basis = Basis(rot); + return instance func place (group, inst : FuncRef): if Input.is_action_just_pressed("use"): if colliding && group in colliding_group: - if !check_overlap_pointer(): + var overlap = check_overlap_pointer() + print(overlap) + if overlap == "clear": inst.call_func(ptr.transform.origin, ptr.transform.basis.get_rotation_quat()) return "ok" @@ -130,8 +156,6 @@ func delete (group): if colliding && group in colliding_group: colliding_node.queue_free() -func select (): - pass func _pointer (): if player.sel.name == "" or player.sel.type == "": ptr.visible = false @@ -147,6 +171,8 @@ func _pointer (): var mask = 1 if player.sel.name.find("path") != -1: mask = 3 + var voxelpos = null; + var result = space.intersect_ray(from, to, [], mask) if result.size() > 0: ptr.visible = true @@ -160,8 +186,8 @@ func _pointer (): colliding_group = node.get_groups() if ("voxels" in colliding_group or "path" in colliding_group): - var cpos = result.position - normal * (0.5 / 2) - var cursor_position = (cpos / 0.5).floor() * 0.5 + voxelpos = result.position - normal * (0.5 / 2) + var cursor_position = (voxelpos / 0.5).floor() * 0.5 cursor_position += Vector3.ONE * (0.5 / 2) + normal * (0.5 / 2) collision_point = cursor_position @@ -173,10 +199,11 @@ func _pointer (): ptr.transform.origin = collision_point else: colliding = false + colliding_node = null colliding_group = [] ptr.visible = false - var placed = "" + var placed = "not ok" match player.sel.type: "map_tools": match player.sel.name: @@ -193,18 +220,30 @@ func _pointer (): place("voxels", funcref(self, "_inst_attach")) delete("attach") "voxels": - pass + if voxelpos != null: + var pos = Voxel.world_to_grid(voxelpos) + if Input.is_action_just_pressed("use"): + world.set_voxel(pos + normal, int(player.sel.name)) + world.update_mesh() + if Input.is_action_just_pressed("cancel"): + world.erase_voxel(pos) + world.update_mesh() "turrets": placed = place("attach", funcref(self, "_inst_turret")) if placed == "ok" and !player.in_editor: resources.sub(load_turrets.info[player.sel.name].cost) delete("turret") + + "idle": + if Input.is_action_just_pressed("use"): + if "turrets" in colliding_group: + player.highlight = colliding_node + else: player.highlight = null + if placed == "ok": player.sel.name = "" - player.sel.type = "" + player.sel.type = "idle" if ptr.has_node("preview"): ptr.get_node("preview").queue_free() player.refresh_gui() - else: - select() diff --git a/scripts/turret.gd b/scripts/turret.gd index 9dce497..4e6f840 100644 --- a/scripts/turret.gd +++ b/scripts/turret.gd @@ -5,8 +5,9 @@ var _enemies : Node var _projectiles_holder : Node var _enemies_holder : Node -var _base : Spatial -var _gun : Spatial +var pivot : Spatial +var base : Spatial +var gun : Spatial var _shooting_point : Vector3 var _normal : Vector3 @@ -33,9 +34,11 @@ func refresh_normal (): _shooting_point = transform.origin + 0.25 * _normal func refresh_model(): - _base = get_node("model").find_node("pivot*").find_node("base*") - _gun = _base.find_node("gun*") - + pivot = get_node("model").find_node("pivot*", true, true) + base = pivot.find_node("base*", true, true) + if base != null: + gun = base.find_node("gun*", true, true) + func refresh_info(tinfo): self.info = tinfo @@ -75,6 +78,8 @@ func get_target(): else: return null func _physics_process(delta): + if !info.has("damage"): return + if !_enemies.enemies.has(_target): _target = null else: @@ -101,19 +106,19 @@ func _physics_process(delta): gun_rot = gun_rot.normalized() gun_rot = base_rot.inverse() * gun_rot - var base_basis = _base.global_transform.basis.get_rotation_quat() + var base_basis = base.global_transform.basis.get_rotation_quat() var base_angle = base_basis.angle_to(base_rot) if base_angle > 0.01: var base_amt = (info.turn_speed * delta) / base_angle base_amt = min(1, base_amt) - _base.global_transform.basis = Basis(base_basis.slerp(Basis(base_rot), base_amt)) + base.global_transform.basis = Basis(base_basis.slerp(Basis(base_rot), base_amt)) - var gun_basis = _gun.transform.basis.get_rotation_quat() + var gun_basis = gun.transform.basis.get_rotation_quat() var gun_angle = gun_basis.angle_to(gun_rot) if gun_angle > 0.01: var gun_amt = (info.turn_speed * delta) / gun_angle gun_amt = min(1, gun_amt) - _gun.transform.basis = Basis(gun_basis.slerp(Basis(gun_rot), gun_amt)) + gun.transform.basis = Basis(gun_basis.slerp(Basis(gun_rot), gun_amt)) cooldown_timer += delta if cooldown_timer > info.cooldown: @@ -124,7 +129,7 @@ func spread (amt : int) -> Array: var dirs = [] var width : int = ceil(sqrt(amt)) for i in amt: - var dir = _gun.global_transform.basis + var dir = gun.global_transform.basis var x = floor(i%width)-width/2+(width+1)%2*0.5 var y = floor(i/width)-floor(sqrt(amt)-1)/2 var spread = info.projectile.spread @@ -141,8 +146,8 @@ func shoot (): "ray": shoot_ray(dir) else: match info.projectile.type: - "bullet": shoot_bullet(_gun.global_transform.basis) - "ray": shoot_ray(_gun.global_transform.basis) + "bullet": shoot_bullet(gun.global_transform.basis) + "ray": shoot_ray(gun.global_transform.basis) func shoot_bullet (dir : Basis): var instance = projectile.instance() |