Adds enemies

This commit is contained in:
Michel 2025-02-01 22:51:01 +01:00
parent cf8ba8bacb
commit 76e5b1927f
324 changed files with 28447 additions and 106 deletions

View file

@ -0,0 +1,60 @@
#*
#* attack_state.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licenses/MIT.
#* =============================================================================
#*
extends LimboState
## Attack state: Perform 3-part combo attack for as long as player hits attack button.
@export var animation_player: AnimationPlayer
@export var animations: Array[StringName]
@export var hitbox: Hitbox
## Cooldown duration after third attack in the combo is complete.
@export var combo_cooldown: float = 0.1
var anim_index: int = 0
var last_attack_msec: int = -10000
var _can_enter: bool = true
## This func is used to prevent entering this state using LimboState.set_guard().
## Entry is denied for a short duration after the third attack in the combo is complete.
func can_enter() -> bool:
return _can_enter
func _enter() -> void:
if (Time.get_ticks_msec() - last_attack_msec) < 200:
# Perform next attack animation in the 3-part combo, if an attack was recently performed.
anim_index = (anim_index + 1) % 3
else:
anim_index = 0
var horizontal_move: float = Input.get_axis(&"move_left", &"move_right")
if not is_zero_approx(horizontal_move):
agent.face_dir(horizontal_move)
hitbox.damage = 2 if anim_index == 2 else 1 # deal 2 damage on a third attack in the combo
animation_player.play(animations[anim_index])
await animation_player.animation_finished
if is_active():
get_root().dispatch(EVENT_FINISHED)
func _exit() -> void:
hitbox.damage = 1
last_attack_msec = Time.get_ticks_msec()
if anim_index == 2 and _can_enter:
# Prevent entering this state for a short duration after the third attack
# in the combo sequence is complete.
_can_enter = false
await get_tree().create_timer(combo_cooldown).timeout
_can_enter = true

View file

@ -0,0 +1,48 @@
#*
#* dodge_state.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licenses/MIT.
#* =============================================================================
#*
extends LimboState
## Dodge state.
@export var animation_player: AnimationPlayer
@export var animation: StringName
@export var duration: float = 0.4
@export var dodge_speed: float = 1000.0
@export var hurtbox_collision: CollisionShape2D
var move_dir: Vector2
var elapsed_time: float
func _enter() -> void:
elapsed_time = 0.0
hurtbox_collision.disabled = true
var horizontal_move: float = Input.get_axis(&"move_left", &"move_right")
if is_zero_approx(horizontal_move):
move_dir = Vector2.RIGHT * agent.get_facing()
else:
move_dir = Vector2.RIGHT * signf(horizontal_move)
agent.face_dir(move_dir.x)
animation_player.play(animation, 0.1)
func _exit() -> void:
hurtbox_collision.set_deferred(&"disabled", false)
func _update(p_delta: float) -> void:
elapsed_time += p_delta
var desired_velocity: Vector2 = move_dir * dodge_speed
agent.move(desired_velocity)
if elapsed_time > duration:
get_root().dispatch(EVENT_FINISHED)

View file

@ -0,0 +1,27 @@
#*
#* idle_state.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licenses/MIT.
#* =============================================================================
#*
extends LimboState
## Idle state.
@export var animation_player: AnimationPlayer
@export var idle_animation: StringName
func _enter() -> void:
animation_player.play(idle_animation, 0.1)
func _update(_delta: float) -> void:
var horizontal_move: float = Input.get_axis(&"move_left", &"move_right")
var vertical_move: float = Input.get_axis(&"move_up", &"move_down")
if horizontal_move != 0.0 or vertical_move != 0.0:
get_root().dispatch(EVENT_FINISHED)

View file

@ -0,0 +1,37 @@
#*
#* move_state.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licenses/MIT.
#* =============================================================================
#*
extends LimboState
## Move state.
const VERTICAL_FACTOR := 0.8
@export var animation_player: AnimationPlayer
@export var animation: StringName
@export var speed: float = 500.0
func _enter() -> void:
animation_player.play(animation, 0.1)
func _update(_delta: float) -> void:
var horizontal_move: float = Input.get_axis(&"move_left", &"move_right")
var vertical_move: float = Input.get_axis(&"move_up", &"move_down")
if not is_zero_approx(horizontal_move):
agent.face_dir(horizontal_move)
var desired_velocity := Vector2(horizontal_move, vertical_move * VERTICAL_FACTOR) * speed
agent.move(desired_velocity)
if horizontal_move == 0.0 and vertical_move == 0.0:
get_root().dispatch(EVENT_FINISHED)