diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bullet.gd | 39 | ||||
-rw-r--r-- | scripts/gui_picker.gd | 1 | ||||
-rw-r--r-- | scripts/movement.gd | 3 | ||||
-rw-r--r-- | scripts/placer.gd | 6 | ||||
-rw-r--r-- | scripts/turret.gd | 23 |
5 files changed, 54 insertions, 18 deletions
diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 994d3d1..3716a4e 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -9,6 +9,8 @@ var timer = 0 var time_life = 3 var speed = 7 var hit_something = false +var bounce = false +var hitlist = [] func _ready(): _enemies_holder = get_tree().root.get_child(0).find_node("enemies") @@ -16,8 +18,31 @@ func _ready(): func _physics_process(delta): var forward_dir = -global_transform.basis.z.normalized() - global_translate(forward_dir * speed * delta) - + if bounce: + var space: PhysicsDirectSpaceState = get_world().direct_space_state + var from = transform.origin + var to = transform.origin + forward_dir * speed * delta + var mask = 0b0101 + var result = space.intersect_ray(from, to, [], mask) + if result.size() > 0: + hitlist.clear() + var bounced = forward_dir.bounce(result.normal).normalized() + var z = -bounced; + var x = bounced.cross(result.normal).normalized(); + var y = x.cross(z).normalized(); + var basis = Basis(x, y, z); + global_transform.basis = basis + forward_dir = -global_transform.basis.z.normalized() + var dist = transform.origin.distance_to(result.position) + transform.origin = result.position + var amt = speed * delta - dist + global_translate(forward_dir * amt) + else: + global_translate(forward_dir * speed * delta) + else: + global_translate(forward_dir * speed * delta) + + timer += delta if timer >= time_life: queue_free() @@ -25,11 +50,17 @@ func _physics_process(delta): func collided(body): var parent = body.get_parent() if parent == shooter: return + if parent in hitlist: return if hit_something == false: var groups = parent.get_groups() if "enemies" in groups: _enemies_holder.damage(parent.name, damage) + + + if !bounce: + hit_something = true + queue_free() + else: + hitlist.append(parent) - hit_something = true - queue_free() diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd index 0dc4dcb..21f6b4c 100644 --- a/scripts/gui_picker.gd +++ b/scripts/gui_picker.gd @@ -2,7 +2,6 @@ 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 = [] diff --git a/scripts/movement.gd b/scripts/movement.gd index fb9e7bd..3247a2f 100644 --- a/scripts/movement.gd +++ b/scripts/movement.gd @@ -78,7 +78,8 @@ func selected_event (sel_name, sel_type): _gui.refresh(in_editor) if sel_type == "turrets": - for child in ptr.get_children(): child.queue_free(); + for child in ptr.get_children(): + if child.name != "base": 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 e68ef5b..dbff4d7 100644 --- a/scripts/placer.gd +++ b/scripts/placer.gd @@ -55,7 +55,7 @@ func check_overlap_pointer(): var params: = PhysicsShapeQueryParameters.new() params.set_shape(shape) - params.collision_mask = 3 + params.collision_mask = 0b1101 params.transform = ptr.transform params.transform.origin = center params.transform.basis = ptr.transform.basis @@ -168,8 +168,8 @@ func _pointer (): ptr.transform.origin = to - var mask = 1 - if player.sel.name.find("path") != -1: mask = 3 + var mask = 0b1101 + if player.sel.name.find("path") != -1: mask = 0b1111 var voxelpos = null; diff --git a/scripts/turret.gd b/scripts/turret.gd index 4e6f840..59d6146 100644 --- a/scripts/turret.gd +++ b/scripts/turret.gd @@ -54,12 +54,13 @@ func filter_in_range(set): func filter_visible(set): var space: PhysicsDirectSpaceState = get_world().direct_space_state var from = _shooting_point + var mask = 0b1101 var filtered = [] for target in set: var node = _enemies.node_from_id(target) var to = node.transform.origin - var result = space.intersect_ray(from, to, _path.nodes, 1) + var result = space.intersect_ray(from, to, _path.nodes, mask) if result.size() > 0: var hit = result.collider.get_parent() if hit == node: @@ -141,15 +142,17 @@ func spread (amt : int) -> Array: func shoot (): if info.projectile.amount > 1: for dir in spread(info.projectile.amount): - match info.projectile.type: - "bullet": shoot_bullet(dir) - "ray": shoot_ray(dir) + shoot_switch(dir) else: - match info.projectile.type: - "bullet": shoot_bullet(gun.global_transform.basis) - "ray": shoot_ray(gun.global_transform.basis) + shoot_switch(gun.global_transform.basis) + +func shoot_switch (dir : Basis): + match info.projectile.type: + "bullet": shoot_bullet(dir) + "ray": shoot_ray(dir) + "bounce": shoot_bullet(dir, true) -func shoot_bullet (dir : Basis): +func shoot_bullet (dir : Basis, bounce = false): var instance = projectile.instance() _projectiles_holder.add_child(instance) instance.transform.basis = dir @@ -157,13 +160,15 @@ func shoot_bullet (dir : Basis): instance.shooter = self instance.damage = info.damage instance.speed = info.projectile.speed + instance.bounce = bounce func shoot_ray (dir : Basis): var space: PhysicsDirectSpaceState = get_world().direct_space_state var from = _shooting_point var to = _shooting_point - dir.z*info.range; + var mask = 0b1101 - var result = space.intersect_ray(from, to, _path.nodes, 1) + var result = space.intersect_ray(from, to, _path.nodes, mask) if result.size() > 0: var parent = result.collider.get_parent() var groups = parent.get_groups() |