Implement Trait: Ricochet
parent
2acab5dd13
commit
4561394340
|
@ -5,8 +5,23 @@ var speed = 128
|
||||||
var poisoned = false
|
var poisoned = false
|
||||||
var damage = 5
|
var damage = 5
|
||||||
var frozen = false
|
var frozen = false
|
||||||
|
var bounced = false
|
||||||
|
var ricochet = false
|
||||||
|
var prev_target
|
||||||
var 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):
|
func _physics_process(delta):
|
||||||
if target != null and is_instance_valid(target) and not target.dead:
|
if target != null and is_instance_valid(target) and not target.dead:
|
||||||
var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0)
|
var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0)
|
||||||
|
@ -20,8 +35,12 @@ func _physics_process(delta):
|
||||||
|
|
||||||
func area_entered(area):
|
func area_entered(area):
|
||||||
var parent = area.get_parent()
|
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.deal_damage(damage)
|
||||||
parent.frozen = frozen
|
parent.frozen = frozen
|
||||||
parent.poisoned = poisoned
|
parent.poisoned = poisoned
|
||||||
call_deferred("free")
|
if bounced or not ricochet:
|
||||||
|
call_deferred("free")
|
||||||
|
choose_target()
|
||||||
|
bounced = true
|
||||||
|
|
|
@ -13,7 +13,7 @@ var mob_threshold = [5, 7, 10, 7]
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Global.playing = true
|
Global.playing = true
|
||||||
Global.play_time = .0
|
Global.play_time = 70
|
||||||
Global.health = 3
|
Global.health = 3
|
||||||
Global.add_health(0)
|
Global.add_health(0)
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ var cell_preload = preload("res://src/models/spell_cell/SpellCell.tscn")
|
||||||
func _ready():
|
func _ready():
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
var spell_cell = cell_preload.instance()
|
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)
|
self.add_child(spell_cell)
|
||||||
|
|
Loading…
Reference in New Issue