feature/actual-hit-mechanic #15
|
|
@ -399,7 +399,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_qk6i7")
|
"texture": SubResource("AtlasTexture_qk6i7")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"attack_down",
|
"name": &"attack_down",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -422,7 +422,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_jx8is")
|
"texture": SubResource("AtlasTexture_jx8is")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"attack_left",
|
"name": &"attack_left",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -445,7 +445,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_cbf1i")
|
"texture": SubResource("AtlasTexture_cbf1i")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"attack_right",
|
"name": &"attack_right",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -468,7 +468,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_qmsq4")
|
"texture": SubResource("AtlasTexture_qmsq4")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"attack_up",
|
"name": &"attack_up",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -775,6 +775,9 @@ animations = [{
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_tuyoq"]
|
||||||
|
radius = 30.0
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" unique_id=804585690]
|
[node name="Player" type="CharacterBody2D" unique_id=804585690]
|
||||||
collision_mask = 129
|
collision_mask = 129
|
||||||
motion_mode = 1
|
motion_mode = 1
|
||||||
|
|
@ -786,4 +789,16 @@ shape = SubResource("CapsuleShape2D_u8vuu")
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1616479252]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1616479252]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
sprite_frames = SubResource("SpriteFrames_giy8y")
|
sprite_frames = SubResource("SpriteFrames_giy8y")
|
||||||
animation = &"attack_up"
|
animation = &"attack_left"
|
||||||
|
|
||||||
|
[node name="MeleeArea" type="Area2D" parent="." unique_id=24997730]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="MeleeArea" unique_id=2002113716]
|
||||||
|
shape = SubResource("CircleShape2D_tuyoq")
|
||||||
|
|
||||||
|
[node name="AttackSpeed" type="Timer" parent="." unique_id=2072925004]
|
||||||
|
wait_time = 0.506
|
||||||
|
autostart = true
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="MeleeArea" to="." method="_on_melee_area_body_entered"]
|
||||||
|
[connection signal="timeout" from="AttackSpeed" to="." method="_on_attack_speed_timeout"]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ func _ready() -> void:
|
||||||
speed = 15.0
|
speed = 15.0
|
||||||
max_hp = 25
|
max_hp = 25
|
||||||
hp = max_hp
|
hp = max_hp
|
||||||
$Area2D.body_entered.connect(_on_area_2d_body_entered)
|
# $Area2D.body_entered.connect(_on_area_2d_body_entered)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
super._process(delta)
|
super._process(delta)
|
||||||
|
|
@ -13,6 +13,6 @@ func _process(delta: float) -> void:
|
||||||
return
|
return
|
||||||
_chase_witch()
|
_chase_witch()
|
||||||
|
|
||||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
#func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||||
if body == player:
|
#if body == player:
|
||||||
take_damage(player.damage)
|
#take_damage(player.damage)
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,6 @@ func brew(fruits):
|
||||||
elif grape_count == 3:
|
elif grape_count == 3:
|
||||||
witch.shoot_tornado()
|
witch.shoot_tornado()
|
||||||
elif apple_count == 1 and grape_count == 2:
|
elif apple_count == 1 and grape_count == 2:
|
||||||
witch.shoot_fireballs()
|
|
||||||
witch.shoot_shuriken()
|
witch.shoot_shuriken()
|
||||||
reset_texture()
|
reset_texture()
|
||||||
is_brewing = false
|
is_brewing = false
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,6 @@ func _process(delta: float) -> void:
|
||||||
_chase_witch()
|
_chase_witch()
|
||||||
|
|
||||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||||
if body == player:
|
#if body == player:
|
||||||
take_damage(player.damage)
|
# take_damage(player.damage)
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,15 @@ var max_xp = 5
|
||||||
var level = 1
|
var level = 1
|
||||||
var speed = 200
|
var speed = 200
|
||||||
var damage: int = 10
|
var damage: int = 10
|
||||||
|
var strength = 3
|
||||||
|
var attacks = false
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||||
velocity = direction * speed
|
velocity = direction * speed
|
||||||
|
move_and_slide()
|
||||||
|
if attacks == true:
|
||||||
|
return
|
||||||
if direction == Vector2.ZERO:
|
if direction == Vector2.ZERO:
|
||||||
animated_sprite_2d.play("idle")
|
animated_sprite_2d.play("idle")
|
||||||
elif abs(direction.x) >= abs(direction.y):
|
elif abs(direction.x) >= abs(direction.y):
|
||||||
|
|
@ -24,4 +28,54 @@ func _physics_process(delta):
|
||||||
animated_sprite_2d.play("walk_down")
|
animated_sprite_2d.play("walk_down")
|
||||||
|
|
||||||
|
|
||||||
move_and_slide()
|
|
||||||
|
|
||||||
|
func attack():
|
||||||
|
if attacks:
|
||||||
|
return
|
||||||
|
for body in $MeleeArea.get_overlapping_bodies():
|
||||||
|
if body.is_in_group("enemies"):
|
||||||
|
attacks = true
|
||||||
|
var dir = global_position.direction_to(body.global_position)
|
||||||
|
if dir == Vector2.ZERO:
|
||||||
|
animated_sprite_2d.play("idle")
|
||||||
|
elif abs(dir.x) >= abs(dir.y):
|
||||||
|
if dir.x < 0:
|
||||||
|
animated_sprite_2d.play("attack_left")
|
||||||
|
else:
|
||||||
|
animated_sprite_2d.play("attack_right")
|
||||||
|
else:
|
||||||
|
if dir.y < 0:
|
||||||
|
animated_sprite_2d.play("attack_up")
|
||||||
|
else:
|
||||||
|
animated_sprite_2d.play("attack_down")
|
||||||
|
animated_sprite_2d.speed_scale = 0.5 / $AttackSpeed.wait_time * 1.4
|
||||||
|
var wait_time = $AttackSpeed.wait_time
|
||||||
|
await get_tree().create_timer(wait_time / 2).timeout
|
||||||
|
body.take_damage(strength)
|
||||||
|
var knockback_dir = global_position.direction_to(body.global_position)
|
||||||
|
var enemy_tween = create_tween()
|
||||||
|
enemy_tween.tween_property(body, "global_position", body.global_position + knockback_dir * 20, 0.1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
|
||||||
|
var player_tween = create_tween()
|
||||||
|
player_tween.tween_property(self, "global_position", global_position - knockback_dir * 10, 0.1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
|
||||||
|
await animated_sprite_2d.animation_finished
|
||||||
|
animated_sprite_2d.speed_scale = 1
|
||||||
|
attacks = false
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_attack_speed_timeout() -> void:
|
||||||
|
if $MeleeArea.get_overlapping_bodies().any(func(b): return b.is_in_group("enemies")):
|
||||||
|
attack()
|
||||||
|
else:
|
||||||
|
$AttackSpeed.call_deferred("stop")
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_melee_area_body_entered(body: Node2D) -> void:
|
||||||
|
if body.is_in_group("enemies"):
|
||||||
|
if $AttackSpeed.is_stopped():
|
||||||
|
attack()
|
||||||
|
$AttackSpeed.start()
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,5 @@ func _process(delta: float) -> void:
|
||||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||||
if is_dying:
|
if is_dying:
|
||||||
return
|
return
|
||||||
if body == player:
|
# if body == player:
|
||||||
take_damage(player.damage)
|
# take_damage(player.damage)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue