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
|
||||||
|
if bounced or not ricochet:
|
||||||
call_deferred("free")
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue