Player changes
This commit is contained in:
@@ -10,6 +10,12 @@ var source_type: String = "" # "player" or "mob"
|
||||
var source_id: int = 0
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
var sprite_key: String = ""
|
||||
var is_linear: bool = false
|
||||
var front_x: int = 0 # Arrow tip X coordinate in sprite
|
||||
var front_y: int = 0 # Arrow tip Y coordinate in sprite
|
||||
var back_x: int = 0 # Arrow tail X coordinate in sprite
|
||||
var back_y: int = 0 # Arrow tail Y coordinate in sprite
|
||||
var spin_speed: float = 10.0 # Radians per second for spinning projectiles
|
||||
|
||||
func _ready():
|
||||
# Create sprite node
|
||||
@@ -46,6 +52,23 @@ func _load_sprite():
|
||||
sprite.texture = texture
|
||||
sprite.modulate = Color.WHITE # Reset modulate
|
||||
sprite.scale = Vector2(0.5, 0.5) # Scale down projectiles
|
||||
|
||||
# For linear projectiles, offset sprite so it rotates around the midpoint
|
||||
# between front (tip) and back (tail) coordinates
|
||||
if is_linear and front_x > 0 and back_x > 0:
|
||||
# Calculate center point between arrow tip and tail
|
||||
var center_x = (front_x + back_x) / 2.0
|
||||
var center_y = (front_y + back_y) / 2.0
|
||||
|
||||
# Offset the sprite so the center point is at (0,0) in local space
|
||||
sprite.offset = Vector2(-center_x, -center_y)
|
||||
|
||||
# Calculate the arrow's natural angle in the sprite (from back to front)
|
||||
var arrow_angle = Vector2(front_x - back_x, front_y - back_y).angle()
|
||||
|
||||
# Store the arrow's natural angle so we can rotate it correctly
|
||||
# The sprite is oriented at arrow_angle, but we want it to face the velocity direction
|
||||
sprite.rotation = -arrow_angle
|
||||
else:
|
||||
print("[Projectile] Failed to load sprite: ", sprite_key)
|
||||
_use_fallback_sprite()
|
||||
@@ -56,7 +79,14 @@ func _process(delta):
|
||||
# Move projectile based on velocity (client-side prediction)
|
||||
if velocity.length() > 0:
|
||||
position += velocity * delta
|
||||
rotation = velocity.angle()
|
||||
|
||||
# Rotation behavior depends on projectile type
|
||||
if is_linear:
|
||||
# Linear projectiles (arrows) point in direction of travel
|
||||
rotation = velocity.angle()
|
||||
else:
|
||||
# Spinning projectiles rotate continuously
|
||||
rotation += spin_speed * delta
|
||||
|
||||
func initialize(data: Dictionary):
|
||||
projectile_id = data.get("id", -1)
|
||||
@@ -70,12 +100,17 @@ func initialize(data: Dictionary):
|
||||
velocity.y = data.get("vy", 0)
|
||||
|
||||
sprite_key = data.get("sprite", "")
|
||||
is_linear = data.get("isLinear", false)
|
||||
front_x = data.get("frontX", 0)
|
||||
front_y = data.get("frontY", 0)
|
||||
back_x = data.get("backX", 0)
|
||||
back_y = data.get("backY", 0)
|
||||
|
||||
# Set rotation based on initial velocity
|
||||
if velocity.length() > 0:
|
||||
# Set rotation based on initial velocity (for linear projectiles)
|
||||
if velocity.length() > 0 and is_linear:
|
||||
rotation = velocity.angle()
|
||||
|
||||
# Load sprite after initialization
|
||||
_load_sprite()
|
||||
|
||||
print("[Projectile] Initialized projectile ", projectile_id, " at (", position.x, ", ", position.y, ") with velocity (", velocity.x, ", ", velocity.y, ")")
|
||||
print("[Projectile] Initialized projectile ", projectile_id, " at (", position.x, ", ", position.y, ") with velocity (", velocity.x, ", ", velocity.y, "), linear=", is_linear)
|
||||
|
||||
Reference in New Issue
Block a user