* animate slime faster

* show loot text above head much closer to head
This commit is contained in:
2026-01-11 04:32:42 +01:00
parent a43a17ed10
commit 464f499b36
7 changed files with 160 additions and 80 deletions

View File

@@ -13,14 +13,44 @@ var detection_range: float = 70.0 # Range to detect players (much smaller)
# Jump mechanics
var is_jumping: bool = false
var jump_anim_frames = [2, 3, 4, 5, 7, 2] # Jump animation sequence
var jump_anim_index: int = 0
# Animation frames
const FRAME_IDLE = 0
const FRAMES_MOVE = [0, 1, 2] # Slow move
const FRAMES_DAMAGE = [8, 9]
const FRAMES_DEATH = [8, 9, 10, 11, 12, 13, 14]
# Animation system (similar to player)
const ANIMATIONS = {
"IDLE": {
"frames": [0],
"frameDurations": [500],
"loop": true,
"nextAnimation": null
},
"MOVE": {
"frames": [0, 1, 2],
"frameDurations": [200, 200, 200],
"loop": true,
"nextAnimation": null
},
"JUMP": {
"frames": [2, 3, 4, 5, 7, 2],
"frameDurations": [100, 100, 100, 100, 100, 100],
"loop": false,
"nextAnimation": "MOVE"
},
"DAMAGE": {
"frames": [8, 9],
"frameDurations": [150, 150],
"loop": false,
"nextAnimation": "IDLE"
},
"DIE": {
"frames": [8, 9, 10, 11, 12, 13, 14],
"frameDurations": [70, 70, 70, 70, 70, 70, 200],
"loop": false,
"nextAnimation": null
}
}
var current_animation = "IDLE"
var current_frame = 0
var time_since_last_frame = 0.0
func _ready():
super._ready()
@@ -71,7 +101,7 @@ func _ai_behavior(delta):
func _idle_behavior(_delta):
velocity = Vector2.ZERO
anim_frame = FRAME_IDLE
_set_animation("IDLE")
# Check if player is nearby
if target_player:
@@ -94,6 +124,8 @@ func _idle_behavior(_delta):
state_timer = move_duration
func _moving_behavior(_delta):
_set_animation("MOVE")
# Move slowly towards player
if target_player and is_instance_valid(target_player):
var direction = (target_player.global_position - global_position).normalized()
@@ -117,9 +149,8 @@ func _moving_behavior(_delta):
func _start_jump():
state = SlimeState.JUMPING
is_jumping = true
jump_anim_index = 0
state_timer = 0.6 # Jump duration
anim_time = 0.0
_set_animation("JUMP")
# Jump towards player if nearby
if target_player and is_instance_valid(target_player):
@@ -142,57 +173,46 @@ func _jumping_behavior(_delta):
func _damaged_behavior(_delta):
velocity = Vector2.ZERO
_set_animation("DAMAGE")
# Stay in damaged state briefly
if state_timer <= 0:
state = SlimeState.IDLE
state_timer = idle_duration
func _set_animation(anim_name: String):
if current_animation != anim_name:
current_animation = anim_name
current_frame = 0
time_since_last_frame = 0.0
func _update_animation(delta):
if state == SlimeState.DYING or state == SlimeState.DAMAGED:
return # Animation handled elsewhere
# Update animation frame timing
time_since_last_frame += delta
if time_since_last_frame >= ANIMATIONS[current_animation]["frameDurations"][current_frame] / 1000.0:
current_frame += 1
if current_frame >= len(ANIMATIONS[current_animation]["frames"]):
current_frame -= 1 # Prevent out of bounds
if ANIMATIONS[current_animation]["loop"]:
current_frame = 0
elif ANIMATIONS[current_animation]["nextAnimation"] != null:
current_frame = 0
current_animation = ANIMATIONS[current_animation]["nextAnimation"]
time_since_last_frame = 0.0
if state == SlimeState.IDLE:
anim_frame = FRAME_IDLE
elif state == SlimeState.JUMPING:
# Animate jump sequence
anim_time += delta
if anim_time >= 0.1: # Fast jump animation
anim_time = 0.0
jump_anim_index += 1
if jump_anim_index < jump_anim_frames.size():
anim_frame = jump_anim_frames[jump_anim_index]
elif state == SlimeState.MOVING:
# Animate slow move (frames 0, 1, 2)
anim_time += delta
if anim_time >= anim_speed:
anim_time = 0.0
var move_index = FRAMES_MOVE.find(anim_frame)
if move_index == -1:
move_index = 0
else:
move_index = (move_index + 1) % FRAMES_MOVE.size()
anim_frame = FRAMES_MOVE[move_index]
# Calculate frame index
var frame_index = ANIMATIONS[current_animation]["frames"][current_frame]
# Set sprite frame (slime looks same in all directions)
if sprite:
sprite.frame = anim_frame
sprite.frame = frame_index
anim_frame = frame_index # Keep anim_frame updated for compatibility
func _on_take_damage():
# Play damage animation
state = SlimeState.DAMAGED
state_timer = 0.3
anim_time = 0.0
# Animate damage frames
_play_damage_anim()
func _play_damage_anim():
for frame in FRAMES_DAMAGE:
anim_frame = frame
if sprite:
sprite.frame = frame
await get_tree().create_timer(0.1).timeout
_set_animation("DAMAGE")
func _die():
if is_dead:
@@ -204,6 +224,7 @@ func _die():
# Set state before calling parent _die()
state = SlimeState.DYING
velocity = Vector2.ZERO
_set_animation("DIE")
# Call parent _die() which handles death sync and _play_death_animation()
super._die()
@@ -220,12 +241,13 @@ func _update_client_visuals():
sprite.frame = anim_frame
func _play_death_animation():
# Play death animation sequence
for frame in FRAMES_DEATH:
anim_frame = frame
if sprite:
sprite.frame = frame
await get_tree().create_timer(0.15).timeout
_set_animation("DIE")
# Wait for death animation to complete
var total_duration = 0.0
for duration in ANIMATIONS["DIE"]["frameDurations"]:
total_duration += duration / 1000.0
await get_tree().create_timer(total_duration).timeout
# Fade out
if sprite: