Deal Damage

main
Luna Brovchuk 2023-10-01 17:12:45 +02:00
parent e0980065c2
commit 3e5d933e21
7 changed files with 72 additions and 23 deletions

View File

@ -15,5 +15,5 @@ void fragment(){
[resource] [resource]
shader = SubResource( 3 ) shader = SubResource( 3 )
shader_param/active = false shader_param/active = true
shader_param/color = Color( 1, 1, 1, 1 ) shader_param/color = Color( 1, 1, 1, 0 )

View File

@ -1,12 +1,23 @@
extends KinematicBody2D extends KinematicBody2D
var speed = 128
var velocity = Vector2.ZERO var velocity = Vector2.ZERO
var speed = 128
var poisoned = false
var damage = 5
var frozen = false
var target var target
func _physics_process(delta): 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_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_sprite_size = Vector2(target_texture.get_width(), target_texture.get_width())
var target_center = target.global_position + (target_sprite_size / 2) var target_center = target.global_position + (target_sprite_size / 2)
self.global_position = self.global_position.move_toward(target_center, delta * speed) 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")

View File

@ -11,6 +11,12 @@ script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."] [node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 ) 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 ) shape = SubResource( 1 )
[connection signal="area_entered" from="Area2D" to="." method="area_entered"]

View File

@ -6,7 +6,7 @@
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7, 9 ) extents = Vector2( 7, 9 )
[node name="Ghost" type="KinematicBody2D" groups=["enemy"]] [node name="Ghost" type="KinematicBody2D" groups=["enemy", "ghost"]]
z_index = 2 z_index = 2
script = ExtResource( 2 ) script = ExtResource( 2 )
@ -14,6 +14,7 @@ script = ExtResource( 2 )
use_parent_material = true use_parent_material = true
frames = ExtResource( 1 ) frames = ExtResource( 1 )
animation = "idle" animation = "idle"
frame = 1
playing = true playing = true
centered = false centered = false

View File

@ -5,6 +5,9 @@ var dash_target = Vector2.ZERO
var dash_timer = .0 var dash_timer = .0
var dashing = false var dashing = false
func _ready():
hp = 8
func _physics_process(delta): func _physics_process(delta):
var dist = global_position.distance_to(player.global_position) var dist = global_position.distance_to(player.global_position)
if dist > 25 and dash_target == Vector2.ZERO: if dist > 25 and dash_target == Vector2.ZERO:

View File

@ -72,9 +72,14 @@ func _shoot():
bullet.global_position.y = self.global_position.y - 4 bullet.global_position.y = self.global_position.y - 4
func _draw(): func _draw():
if target != null: if target != null and is_instance_valid(target):
var dist2enemy = position.distance_to(target.global_position) 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): func _process(_delta):
$Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run") $Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run")
@ -87,11 +92,9 @@ func _physics_process(delta):
get_input() get_input()
invincibility_timer += delta invincibility_timer += delta
recharge_timer += delta
if recharge_timer >= get_recharge(): if recharge_timer <= get_recharge():
_shoot() recharge_timer += delta
recharge_timer = .0
var areas = $EnemyCollision.get_overlapping_areas() var areas = $EnemyCollision.get_overlapping_areas()
slowed = false slowed = false
@ -110,4 +113,11 @@ func _physics_process(delta):
velocity = move_and_slide(velocity * speed_multiplier) velocity = move_and_slide(velocity * speed_multiplier)
choose_target() choose_target()
if target != null and is_instance_valid(target):
target.material = outline_material target.material = outline_material
if recharge_timer >= get_recharge():
_shoot()
recharge_timer = .0

View File

@ -4,17 +4,35 @@ var hp
var poisoned = false var poisoned = false
var poisoned_timer = .0 var poisoned_timer = .0
var speed_multiplier = 1 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 var frozen = false
func check_frozen(): func deal_damage(amount):
speed_multiplier = 1 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: if frozen:
frozen_timer += delta
speed_multiplier = 0.5 speed_multiplier = 0.5
if frozen_timer >= frozen_time:
func check_poisoned(): frozen_time = 0
if poisoned_timer >= 1: frozen = false
hp -= 5 else:
speed_multiplier = 1
func _physics_process(_delta):
check_frozen()
check_poisoned()