knockback and mine damage
This commit is contained in:
@@ -13,17 +13,15 @@ func _on_area_entered(area: Area2D) -> void:
|
||||
if self.get_parent().is_in_group("Virus"):
|
||||
# Prevent friendly fire
|
||||
return
|
||||
print_debug("Cursor bullet hit %s" % area.name)
|
||||
var area_parent = area.get_parent()
|
||||
if (area_parent.is_in_group("Virus")):
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 200, knockback_strength)
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 50, knockback_strength)
|
||||
self.queue_free()
|
||||
|
||||
func _on_body_entered(body):
|
||||
if self.get_parent() == body:
|
||||
return
|
||||
print_debug("Cursor bullet hit %s" % body.name)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 200, knockback_strength)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 50, knockback_strength)
|
||||
self.queue_free()
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Node2D
|
||||
|
||||
@export var damage = 5
|
||||
@export var knockback_strength = 3
|
||||
@export var damage = 8
|
||||
@export var knockback_strength = 2
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if self.get_parent().is_in_group("Virus"):
|
||||
@@ -9,10 +9,9 @@ func _on_area_entered(area: Area2D) -> void:
|
||||
return
|
||||
var area_parent = area.get_parent()
|
||||
if (area_parent.is_in_group("Virus")):
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 200, knockback_strength)
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 100, knockback_strength)
|
||||
|
||||
func _on_body_entered(body):
|
||||
if self.get_parent() == body:
|
||||
return
|
||||
print_debug("Cursor bullet hit %s" % body.name)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 200, knockback_strength)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 100, knockback_strength)
|
||||
@@ -1,5 +1,21 @@
|
||||
extends Node2D
|
||||
|
||||
@export var damage = 5
|
||||
@export var knockback_strength = 4
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if self.get_parent().is_in_group("Virus"):
|
||||
# Prevent friendly fire
|
||||
return
|
||||
var area_parent = area.get_parent()
|
||||
if (area_parent.is_in_group("Virus")):
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 50, knockback_strength)
|
||||
|
||||
func _on_body_entered(body):
|
||||
if self.get_parent() == body:
|
||||
return
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 50, knockback_strength)
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
self.queue_free()
|
||||
self.queue_free()
|
||||
@@ -76,6 +76,7 @@ func dash():
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size
|
||||
knockback_timer.one_shot = true
|
||||
add_child(knockback_timer);
|
||||
|
||||
func _process(delta):
|
||||
update_target_coords();
|
||||
|
||||
@@ -16,6 +16,9 @@ enum ActionState {Blocked, Waiting, Running}
|
||||
var spawning_state
|
||||
var action_state
|
||||
|
||||
var knockback_timer: Timer = Timer.new()
|
||||
var knockback = Vector2.ZERO
|
||||
|
||||
# temp 0 because of if len == 0 in process
|
||||
var targets = [0] # who the virus will attack
|
||||
|
||||
@@ -24,6 +27,8 @@ func _ready():
|
||||
self.action_state = ActionState.Waiting
|
||||
self.add_to_group("Virus")
|
||||
$AnimationTree.set("parameters/transition/transition_request", "processing")
|
||||
knockback_timer.one_shot = true
|
||||
add_child(knockback_timer);
|
||||
|
||||
func _process(delta):
|
||||
if self.spawning_state != SpawningState.Spawned:
|
||||
@@ -40,9 +45,13 @@ func _process(delta):
|
||||
if shortest_distance < self.attack_range:
|
||||
self.attack(nearest_target)
|
||||
|
||||
# --- move towards nearest target
|
||||
self.position += \
|
||||
self.position.direction_to(nearest_target) * self.speed * delta
|
||||
if knockback_timer.time_left > 0:
|
||||
print_debug("knockback timer left: %f %s" % [knockback_timer.time_left, knockback])
|
||||
self.position += knockback * delta
|
||||
else:
|
||||
# --- move towards nearest target
|
||||
self.position += \
|
||||
self.position.direction_to(nearest_target) * self.speed * delta
|
||||
|
||||
func attack(target):
|
||||
# do attack, block until timer
|
||||
@@ -54,11 +63,12 @@ func set_spawning():
|
||||
func set_spawned():
|
||||
self.spawning_state = SpawningState.Spawned
|
||||
|
||||
func take_hit(damage, _knockback_vector, _knockback_strength = 1):
|
||||
func take_hit(damage, knockback_vector, knockback_strength = 1):
|
||||
$HitSFX.play();
|
||||
health -= damage
|
||||
if health <= 0:
|
||||
queue_free()
|
||||
else:
|
||||
# Flash white for now
|
||||
pass
|
||||
elif knockback_strength > 0:
|
||||
knockback = -knockback_vector;
|
||||
knockback_timer.start(0.2 * knockback_strength);
|
||||
# Flash white?
|
||||
|
||||
Reference in New Issue
Block a user