Deal Damage
parent
e0980065c2
commit
3e5d933e21
|
@ -15,5 +15,5 @@ void fragment(){
|
|||
|
||||
[resource]
|
||||
shader = SubResource( 3 )
|
||||
shader_param/active = false
|
||||
shader_param/color = Color( 1, 1, 1, 1 )
|
||||
shader_param/active = true
|
||||
shader_param/color = Color( 1, 1, 1, 0 )
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
var speed = 128
|
||||
var velocity = Vector2.ZERO
|
||||
var speed = 128
|
||||
var poisoned = false
|
||||
var damage = 5
|
||||
var frozen = false
|
||||
var target
|
||||
|
||||
func _physics_process(delta):
|
||||
if target != null:
|
||||
if target != null and is_instance_valid(target):
|
||||
var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0)
|
||||
var target_sprite_size = Vector2(target_texture.get_width(), target_texture.get_width())
|
||||
var target_center = target.global_position + (target_sprite_size / 2)
|
||||
self.global_position = self.global_position.move_toward(target_center, delta * speed)
|
||||
|
||||
func area_entered(area):
|
||||
var parent = area.get_parent()
|
||||
if parent.is_in_group("enemy"):
|
||||
parent.deal_damage(damage)
|
||||
parent.frozen = frozen
|
||||
parent.poisoned = poisoned
|
||||
call_deferred("free")
|
||||
|
|
|
@ -11,6 +11,12 @@ script = ExtResource( 2 )
|
|||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2( 3.5, 3.5 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[connection signal="area_entered" from="Area2D" to="." method="area_entered"]
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 7, 9 )
|
||||
|
||||
[node name="Ghost" type="KinematicBody2D" groups=["enemy"]]
|
||||
[node name="Ghost" type="KinematicBody2D" groups=["enemy", "ghost"]]
|
||||
z_index = 2
|
||||
script = ExtResource( 2 )
|
||||
|
||||
|
@ -14,6 +14,7 @@ script = ExtResource( 2 )
|
|||
use_parent_material = true
|
||||
frames = ExtResource( 1 )
|
||||
animation = "idle"
|
||||
frame = 1
|
||||
playing = true
|
||||
centered = false
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ var dash_target = Vector2.ZERO
|
|||
var dash_timer = .0
|
||||
var dashing = false
|
||||
|
||||
func _ready():
|
||||
hp = 8
|
||||
|
||||
func _physics_process(delta):
|
||||
var dist = global_position.distance_to(player.global_position)
|
||||
if dist > 25 and dash_target == Vector2.ZERO:
|
||||
|
|
|
@ -72,9 +72,14 @@ func _shoot():
|
|||
bullet.global_position.y = self.global_position.y - 4
|
||||
|
||||
func _draw():
|
||||
if target != null:
|
||||
if target != null and is_instance_valid(target):
|
||||
var dist2enemy = position.distance_to(target.global_position)
|
||||
draw_dashed_line(Vector2(12, 12), target.global_position - self.global_position + Vector2(8, 7), Color("ffde00"), 1)
|
||||
var mob_offset = Vector2.ZERO
|
||||
if target.is_in_group("bat"):
|
||||
mob_offset = Vector2(8, 7)
|
||||
if target.is_in_group("ghost"):
|
||||
mob_offset = Vector2(8, 12)
|
||||
draw_dashed_line(Vector2(12, 12), target.global_position - self.global_position + mob_offset, Color("ffde00"), 1)
|
||||
|
||||
func _process(_delta):
|
||||
$Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run")
|
||||
|
@ -87,11 +92,9 @@ func _physics_process(delta):
|
|||
get_input()
|
||||
|
||||
invincibility_timer += delta
|
||||
recharge_timer += delta
|
||||
|
||||
if recharge_timer >= get_recharge():
|
||||
_shoot()
|
||||
recharge_timer = .0
|
||||
if recharge_timer <= get_recharge():
|
||||
recharge_timer += delta
|
||||
|
||||
var areas = $EnemyCollision.get_overlapping_areas()
|
||||
slowed = false
|
||||
|
@ -110,4 +113,11 @@ func _physics_process(delta):
|
|||
|
||||
velocity = move_and_slide(velocity * speed_multiplier)
|
||||
choose_target()
|
||||
target.material = outline_material
|
||||
|
||||
if target != null and is_instance_valid(target):
|
||||
target.material = outline_material
|
||||
|
||||
if recharge_timer >= get_recharge():
|
||||
_shoot()
|
||||
recharge_timer = .0
|
||||
|
||||
|
|
|
@ -4,17 +4,35 @@ var hp
|
|||
var poisoned = false
|
||||
var poisoned_timer = .0
|
||||
var speed_multiplier = 1
|
||||
var frozen_timer = .0
|
||||
var frozen_time = 2
|
||||
var poisoned_time = 3
|
||||
var poisoned_damage = 5
|
||||
var poison_damage_timer = .0
|
||||
|
||||
var frozen = false
|
||||
|
||||
func check_frozen():
|
||||
speed_multiplier = 1
|
||||
func deal_damage(amount):
|
||||
hp -= amount
|
||||
if hp <= 0:
|
||||
call_deferred("free")
|
||||
|
||||
func _physics_process(delta):
|
||||
if poisoned:
|
||||
poisoned_timer += delta
|
||||
poison_damage_timer += delta
|
||||
if poisoned_timer >= poisoned_time:
|
||||
poisoned_timer = .0
|
||||
poison_damage_timer = .0
|
||||
poisoned = false
|
||||
if poison_damage_timer >= 1:
|
||||
deal_damage(poisoned_damage)
|
||||
|
||||
if frozen:
|
||||
frozen_timer += delta
|
||||
speed_multiplier = 0.5
|
||||
|
||||
func check_poisoned():
|
||||
if poisoned_timer >= 1:
|
||||
hp -= 5
|
||||
|
||||
func _physics_process(_delta):
|
||||
check_frozen()
|
||||
check_poisoned()
|
||||
if frozen_timer >= frozen_time:
|
||||
frozen_time = 0
|
||||
frozen = false
|
||||
else:
|
||||
speed_multiplier = 1
|
||||
|
|
Loading…
Reference in New Issue