diff --git a/src/models/bullet/bullet.gd b/src/models/bullet/bullet.gd index 57821e7..0741a91 100644 --- a/src/models/bullet/bullet.gd +++ b/src/models/bullet/bullet.gd @@ -5,8 +5,23 @@ var speed = 128 var poisoned = false var damage = 5 var frozen = false +var bounced = false +var ricochet = false +var prev_target var target +func choose_target(): + target = null + var least_dist = 4000 + var enemy_dist + var enemies = get_tree().get_nodes_in_group("enemy") + for enemy in enemies: + enemy.material = null + enemy_dist = global_position.distance_to(enemy.global_position) + if enemy_dist < least_dist and enemy != prev_target: + least_dist = enemy_dist + target = enemy + func _physics_process(delta): if target != null and is_instance_valid(target) and not target.dead: var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0) @@ -20,8 +35,12 @@ func _physics_process(delta): func area_entered(area): var parent = area.get_parent() - if parent.is_in_group("enemy"): + if parent.is_in_group("enemy") and parent != prev_target: + prev_target = parent parent.deal_damage(damage) parent.frozen = frozen parent.poisoned = poisoned - call_deferred("free") + if bounced or not ricochet: + call_deferred("free") + choose_target() + bounced = true diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd index d86a330..3869fe6 100644 --- a/src/scenes/game/game.gd +++ b/src/scenes/game/game.gd @@ -13,7 +13,7 @@ var mob_threshold = [5, 7, 10, 7] func _ready(): Global.playing = true - Global.play_time = .0 + Global.play_time = 70 Global.health = 3 Global.add_health(0) diff --git a/src/scenes/game/spell_holder.gd b/src/scenes/game/spell_holder.gd index 7893742..95b8628 100644 --- a/src/scenes/game/spell_holder.gd +++ b/src/scenes/game/spell_holder.gd @@ -5,5 +5,5 @@ var cell_preload = preload("res://src/models/spell_cell/SpellCell.tscn") func _ready(): for i in range(5): var spell_cell = cell_preload.instance() - spell_cell.rect_position.x += i * (14 + 2) + spell_cell.rect_position.x += i * (14 + 2) self.add_child(spell_cell)