fight system and whatnot

This commit is contained in:
2025-10-29 01:47:45 +01:00
parent 527be3ee5d
commit 84f75cb2a7
41 changed files with 1433 additions and 57 deletions

View File

@@ -1,18 +1,22 @@
class_name Player
extends CharacterBody2D
const SPEED: int = 800
const SPEED: int = 1000
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var fight_animation: AnimatedSprite2D = $FightAnimation
@onready var cam: Camera2D = $Camera2D
@onready var raycast: RayCast2D = $RayCast2D
const RAYCAST_RAGE: int = 32
@onready var cursor_hide_timer: Timer = $CursorHideTimer
const RAYCAST_RANGE: int = 22
@export var tilemap: TileMapLayer
var tilesize: int = 32
var position_limit_rect: Rect2
const STILL_POSITIONS: Array[String] = ["sit", "hand_down", "hand_side", "hand_up"]
const STILL_POSITIONS: Array[String] = ["sit_down", "sit_side", "hand_down", "hand_side", "hand_up"]
var health: int = 10
var damage: int = 2
func _ready() -> void:
EventManager.player = self
@@ -35,9 +39,55 @@ func _ready() -> void:
)
func _process(_delta: float) -> void:
if EventManager.player_free && !EventManager.animation_player.is_playing() && Input.is_action_just_pressed("interact") && raycast.is_colliding() && raycast.get_collider() is Interactable:
var interactable: Interactable = raycast.get_collider()
if EventManager.player_free && !EventManager.animation_player.is_playing() && Input.is_action_just_pressed("interact"):
interact()
func interact() -> void:
var interactable: Interactable
if raycast.is_colliding() && raycast.get_collider() is Interactable:
interactable = raycast.get_collider()
else:
interactable = null
var fightable: Fightable
if raycast.is_colliding() && raycast.get_collider() is Fightable:
fightable = raycast.get_collider()
else:
fightable = null
match animated_sprite.animation:
"down":
animated_sprite.play("hand_down")
if interactable == null:
fight_animation.rotation_degrees = 0
fight_animation.play()
if !fight_animation.is_playing():
fight_animation.play()
await animated_sprite.animation_finished
animated_sprite.animation = "down"
"up":
animated_sprite.play("hand_up")
if interactable == null:
fight_animation.rotation_degrees = 180
fight_animation.play()
if !fight_animation.is_playing():
fight_animation.play()
await animated_sprite.animation_finished
animated_sprite.animation = "up"
"side":
animated_sprite.play("hand_side")
if interactable == null:
if animated_sprite.flip_h:
fight_animation.rotation_degrees = 90
else:
fight_animation.rotation_degrees = -90
if !fight_animation.is_playing():
fight_animation.play()
await animated_sprite.animation_finished
animated_sprite.animation = "side"
if interactable != null:
interactable.interact(self)
elif fightable != null:
fightable.fight(self)
func _physics_process(delta: float) -> void:
if !STILL_POSITIONS.has(animated_sprite.animation) && EventManager.player_free && !EventManager.animation_player.is_playing():
@@ -49,7 +99,7 @@ func _physics_process(delta: float) -> void:
elif abs(input.y) > 0:
raycast_input.y = sign(input.y)
if raycast_input != Vector2.ZERO:
raycast.target_position = raycast_input * RAYCAST_RAGE
raycast.target_position = raycast_input * RAYCAST_RANGE
velocity = input * delta * SPEED * 3
@@ -71,6 +121,10 @@ func _physics_process(delta: float) -> void:
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouse:
cursor_hide_timer.stop()
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
elif EventManager.player_free && !EventManager.animation_player.is_playing() && !event.is_action("escape"):
if cursor_hide_timer.is_stopped():
cursor_hide_timer.start()
await cursor_hide_timer.timeout
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN