Player changes + projectile fixes

This commit is contained in:
dingo
2026-01-19 15:21:56 -05:00
parent 88737d51c4
commit cefa1cf716
9 changed files with 92 additions and 32 deletions
+10 -2
View File
@@ -42,7 +42,7 @@ var damage_number_scene: PackedScene = null
var projectiles: Dictionary = {} # id -> projectile node
var aim_angle: float = 0.0
var last_attack_time: float = 0.0
var last_attack_time: float = -999.0 # Start far in the past so first attack always works
var attack_cooldown: float = 0.5 # Default attack cooldown in seconds
func _ready():
@@ -261,7 +261,12 @@ func _handle_input():
if Input.is_action_just_pressed("inventory"):
if chat_panel.visible != true:
_toggle_inventory()
# Crafting toggle (C key)
if Input.is_action_just_pressed("crafting"):
if chat_panel.visible != true:
_toggle_crafting()
# Escape handling - close UI panels, or show hint about portals
if Input.is_action_just_pressed("escape_menu"):
# Close UI first (in priority order)
@@ -617,6 +622,9 @@ func _on_damage_number(data: Dictionary):
if mob_id == target_id:
target_pos = mob_node.position
found_target = true
# Play hurt effect on mob
if mob_node.has_method("play_hurt_effect"):
mob_node.play_hurt_effect()
break
elif target_type == "player":
# Check if it's the local player
+19 -1
View File
@@ -483,8 +483,26 @@ func _update_fallback_state(state: String):
func _apply_tint(tint_hex: String):
var tint_color = Color.from_string(tint_hex, Color.WHITE)
if _animated_sprite:
_animated_sprite.modulate = tint_color
elif fallback_sprite:
fallback_sprite.modulate = tint_color
func play_hurt_effect():
"""Flash mob red briefly to show damage"""
var sprite_to_flash = _animated_sprite if _animated_sprite and _animated_sprite.visible else fallback_sprite
if not sprite_to_flash:
return
# Store original color
var original_color = sprite_to_flash.modulate
# Flash red
sprite_to_flash.modulate = Color(1.5, 0.5, 0.5, 1.0) # Bright red flash
# Return to original color after 0.1 seconds
await get_tree().create_timer(0.1).timeout
if is_instance_valid(sprite_to_flash):
sprite_to_flash.modulate = original_color
+30 -18
View File
@@ -143,29 +143,41 @@ func _process(_delta):
func set_aim_angle(angle: float):
aim_angle = angle
# Update facing direction based on aim angle
# Convert angle to direction (down, up, left, right)
var deg = rad_to_deg(angle)
if deg < 0:
deg += 360
if deg >= 315 or deg < 45:
current_direction = "right"
elif deg >= 45 and deg < 135:
current_direction = "down"
elif deg >= 135 and deg < 225:
current_direction = "left"
else:
current_direction = "up"
# Don't update direction from aim - only update from movement
func _update_walk_animation():
if not animated_sprite or not animated_sprite.sprite_frames:
return
var anim_name = "walk_" + current_direction
if animated_sprite.animation != anim_name:
animated_sprite.play(anim_name)
# Update direction based on movement vector
if move_direction.length() > 0.1:
# Player is moving, update direction based on movement
var angle = move_direction.angle()
var deg = rad_to_deg(angle)
if deg < 0:
deg += 360
if deg >= 315 or deg < 45:
current_direction = "right"
elif deg >= 45 and deg < 135:
current_direction = "down"
elif deg >= 135 and deg < 225:
current_direction = "left"
else:
current_direction = "up"
# Play walk animation for current direction (will loop)
var anim_name = "walk_" + current_direction
if animated_sprite.animation != anim_name and not is_attacking:
animated_sprite.play(anim_name)
else:
# Player stopped moving - show idle frame (frame 0 of walk animation)
if not is_attacking:
var anim_name = "walk_" + current_direction
if animated_sprite.animation != anim_name or animated_sprite.is_playing():
animated_sprite.play(anim_name)
animated_sprite.pause()
animated_sprite.frame = 0 # Show first frame as idle
func play_attack_animation(weapon_type: String = "fist"):
"""
+10 -7
View File
@@ -28,26 +28,29 @@ func _ready():
func _use_fallback_sprite():
if not sprite:
print("[Projectile] ERROR: No sprite node to apply fallback to!")
return
# Create a simple circular fallback sprite
if has_node("/root/SpriteGenerator"):
var sprite_gen = get_node("/root/SpriteGenerator")
sprite.texture = sprite_gen.get_circle()
if SpriteGenerator:
sprite.texture = SpriteGenerator.get_circle()
sprite.modulate = Color(1.0, 0.8, 0.2) # Yellowish for projectiles
sprite.scale = Vector2(0.3, 0.3)
sprite.scale = Vector2(0.5, 0.5) # Make it bigger so it's visible
print("[Projectile] Using fallback sprite with SpriteGenerator")
else:
# If no SpriteGenerator, just leave it invisible for now
print("[Projectile] Warning: No SpriteGenerator available for fallback")
func _load_sprite():
if not sprite:
print("[Projectile] ERROR: No sprite node to load texture into!")
return
print("[Projectile] Loading sprite with key: '%s'" % sprite_key)
# Try to load projectile sprite from CDN if UpdateManager exists
if sprite_key and not sprite_key.is_empty() and has_node("/root/UpdateManager"):
var update_manager = get_node("/root/UpdateManager")
var texture = update_manager.load_texture(sprite_key)
if sprite_key and not sprite_key.is_empty() and UpdateManager:
var texture = UpdateManager.load_texture(sprite_key)
if texture:
sprite.texture = texture
sprite.modulate = Color.WHITE # Reset modulate