feat: tatoebaspil m kiva hammasbaksu au andrjoku

This commit is contained in:
Sheldon Cooper 2026-10-20 18:31:52 -04:00
parent b2d5ab61d2
commit 050e8f9e22
104 changed files with 3017 additions and 27 deletions

View file

@ -0,0 +1,16 @@
extends Area2D
@onready var character = get_parent()
var damage = 1
func _on_area_entered(target: Area2D) -> void:
# Damage target area if it has _take_damage method
if target.has_method("_take_damage"):
target._take_damage(damage)
character._take_damage()
# Damage target area parent if it has _take_damage method
if target.get_parent().has_method("_take_damage"):
target.get_parent()._take_damage(damage)
character._take_damage()

View file

@ -0,0 +1 @@
uid://dekx8meo31r21

View file

@ -0,0 +1,59 @@
extends CharacterBody2D
@export var speed: float = 40.0
var move_right = true
@onready var ground_ray_left = %GroundRayLeft
@onready var ground_ray_right = %GroundRayRight
@onready var wall_ray_left = %WallRayLeft
@onready var wall_ray_right = %WallRayRight
@onready var attack_box = %AttackBox
@onready var animator = %Animator
@onready var sprite = %Sprite
@onready var death_sound_player: AudioStreamPlayer = %DeathSoundPlayer
func _ready() -> void:
animator.play("walk")
func _physics_process(delta):
# Set the velocity to move in the given direction
if !wall_ray_left.is_colliding() and !wall_ray_right.is_colliding():
if !ground_ray_left.is_colliding() or !ground_ray_right.is_colliding():
if velocity.x >0:
move_right = false
else :
move_right = true
else:
if velocity.x >0:
move_right = false
else :
move_right = true
if move_right:
velocity.x = 1 * speed
else :
velocity.x = -1 * speed
# Optionally, flip the sprite to face the new direction
sprite.flip_h = !move_right
# Move the enemy according to the velocity
move_and_slide()
func _take_damage():
# Disable attack box so it can't hurt the player
attack_box.monitoring = false
death_sound_player.play()
# Blink red
sprite.modulate = Color(255, 0,0)
# Delay death
await get_tree().create_timer(0.1).timeout
queue_free()

View file

@ -0,0 +1 @@
uid://ow780v11j4gt

View file

@ -0,0 +1,17 @@
extends ShapeCast2D
@onready var character = get_parent()
func _process(delta: float) -> void:
if get_collider(0):
if character.velocity.y > 0 and get_collider(0):
var target = get_collider(0)
# Damage target if it has _take_damage method
if target.has_method("_take_damage"):
target._take_damage()
character.velocity.y = -300
# Damage target parent if it has _take_damage method
elif target.get_parent().has_method("_take_damage"):
target.get_parent()._take_damage()
character.velocity.y = -300

View file

@ -0,0 +1 @@
uid://5p5u8dtod1cj

View file

@ -0,0 +1,185 @@
extends CharacterBody2D
# === Stat Settings ===
@export var health = 3
# === Movement Settings ===
@export var speed: float = 100.0
@export var jump_velocity: float = -300.0
@export var gravity: float = 1200.0
@export var max_fall_speed: float = 1200.0
# === Jump Features ===
@export var coyote_time: float = 0.15
@export var jump_buffer_time: float = 0.15
# === Double Jump ===
@export var allow_double_jump: bool = true
@export var max_jumps: int = 2 # 1 = normal jump only, 2 = double jump, etc.
var jumps_left: int = 0
# === Animation Lock ===
@export var landing_animation_duration: float = 0.1
# === Internal Timers ===
var coyote_timer: float = 0.0
var jump_buffer_timer: float = 0.0
var jump_cutoff_timer: float = 0.0
var landing_lock_timer: float = 0.0
var was_on_floor: bool = false
# === Nodes ===
@onready var sprite: Sprite2D = %MainSprite
@onready var animator: AnimationPlayer = %Animator
@onready var attack_ray: ShapeCast2D = %AttackRay
@onready var jump_audio_player: AudioStreamPlayer = %JumpSound
@onready var hurt_audio_player: AudioStreamPlayer = %HurtSound
func _ready() -> void:
DataBusSingleton.player = self
func _physics_process(delta):
# === Handle Timers ===
_update_timers(delta)
# === Handle Input ===
var direction = Input.get_axis("move_left", "move_right")
var is_jumping = Input.is_action_just_pressed("jump")
var holding_jump = Input.is_action_pressed("jump")
# === Horizontal Movement ===
velocity.x = direction * speed
# === Jump Logic ===
_process_jump(is_jumping, holding_jump)
# === Apply Gravity ===
_apply_gravity(delta)
# === Movement ===
move_and_slide()
# === Landing Detection ===
_check_landing()
# === Sprite Orientation ===
_flip_sprite()
# === Play Animations ===
_play_animations(direction)
# === Update Data Bus ===
_update_data_bus()
# === Debug ===
_debug(true) # Change to false to disable
# --------------------------
# === HELPER FUNCTIONS ===
# --------------------------
func _update_timers(delta):
if is_on_floor():
coyote_timer = coyote_time
else:
coyote_timer -= delta
if Input.is_action_just_pressed("jump"):
jump_buffer_timer = jump_buffer_time
jump_audio_player.play()
else:
jump_buffer_timer -= delta
jump_cutoff_timer = max(jump_cutoff_timer - delta, 0.0)
landing_lock_timer = max(landing_lock_timer - delta, 0.0)
func _process_jump(is_jumping: bool, holding_jump: bool):
if is_jumping:
# Ground or coyote jump
if (coyote_timer > 0.0 or is_on_floor()) and jumps_left > 0:
velocity.y = jump_velocity
jump_buffer_timer = 0.0
coyote_timer = 0.0
jump_cutoff_timer = 0.0
jumps_left -= 1
# Mid-air jump (double jump)
elif allow_double_jump and jumps_left > 0:
velocity.y = jump_velocity
jumps_left -= 1
jump_cutoff_timer = 0.0
jump_buffer_timer = 0.0
# Variable Jump Height (cutoff when button released early)
if jump_cutoff_timer <= 0.0 and not holding_jump and velocity.y < 0:
velocity.y *= 0.5
func _apply_gravity(delta):
velocity.y += gravity * delta
if velocity.y > max_fall_speed:
velocity.y = max_fall_speed
func _check_landing():
var just_landed = not was_on_floor and is_on_floor()
was_on_floor = is_on_floor()
if just_landed:
landing_lock_timer = landing_animation_duration
animator.play("land")
jumps_left = max_jumps # Reset jumps on landing
# Also reset on floor contact in general
if is_on_floor():
jumps_left = max_jumps
func _flip_sprite():
if velocity.x < -1:
sprite.flip_h = true
elif velocity.x > 1:
sprite.flip_h = false
func _play_animations(direction):
if landing_lock_timer > 0.0:
return
if not is_on_floor():
animator.play("jump")
elif abs(velocity.x) > 1:
animator.play("run")
else:
animator.play("idle")
# Change animation speed based on movement speed for the run animation
# so it doesn't animate at full speed when walking slowly
if animator.current_animation == "run":
animator.speed_scale = abs(direction)
else:
animator.speed_scale = 1.0
func _update_data_bus():
# Updates DataBusSingleton - an autoload scene for transfering data between scenes
DataBusSingleton.player_health = health
func _debug(enabled):
# If enabled prints out various metrics
if enabled:
print("Health: ", health)
print("Velocity X and Y: ", velocity)
print("Jumps Left: ", jumps_left)
func _take_damage(damage):
# Function activated from other nodes
health -= damage
# Change sprite color to solid red and play hurt sound
sprite.modulate = Color(255, 0, 0, 255)
hurt_audio_player.play()
# If health is lower than 1 - die
if health < 1:
DataBusSingleton._spawn_fail_screen()
# Wait a bit for color to reset
await get_tree().create_timer(0.1).timeout
sprite.modulate = Color(1, 1, 1, 1)

View file

@ -0,0 +1 @@
uid://dt3v7jvorf4o3