added bomb
This commit is contained in:
@@ -470,6 +470,11 @@ func on_released(by_player):
|
||||
print(name, " released by ", by_player.name)
|
||||
|
||||
func on_thrown(by_player, force: Vector2):
|
||||
# Special handling for bombs - convert to projectile when thrown
|
||||
if object_type == "Bomb":
|
||||
_convert_to_bomb_projectile(by_player, force)
|
||||
return
|
||||
|
||||
# Only allow throwing if object is liftable
|
||||
if not is_liftable:
|
||||
return
|
||||
@@ -490,6 +495,46 @@ func on_thrown(by_player, force: Vector2):
|
||||
|
||||
print(name, " thrown with velocity ", throw_velocity)
|
||||
|
||||
func _convert_to_bomb_projectile(by_player, force: Vector2):
|
||||
# Convert bomb object to projectile bomb when thrown
|
||||
var attack_bomb_scene = load("res://scenes/attack_bomb.tscn")
|
||||
if not attack_bomb_scene:
|
||||
push_error("ERROR: Could not load attack_bomb scene!")
|
||||
return
|
||||
|
||||
# Only authority can spawn bombs
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
# Store current position before freeing
|
||||
var current_pos = global_position
|
||||
|
||||
# Spawn bomb projectile at current position
|
||||
var bomb = attack_bomb_scene.instantiate()
|
||||
get_parent().add_child(bomb)
|
||||
bomb.global_position = current_pos # Use current position, not target
|
||||
|
||||
# Set multiplayer authority
|
||||
if multiplayer.has_multiplayer_peer():
|
||||
bomb.set_multiplayer_authority(by_player.get_multiplayer_authority())
|
||||
|
||||
# Setup bomb with throw physics (pass force as throw_velocity)
|
||||
# The bomb will use throw_velocity for movement
|
||||
bomb.setup(current_pos, by_player, force, true) # true = is_thrown, force is throw_velocity
|
||||
|
||||
# Make sure bomb sprite is visible
|
||||
if bomb.has_node("Sprite2D"):
|
||||
bomb.get_node("Sprite2D").visible = true
|
||||
|
||||
# Sync bomb throw to other clients
|
||||
if multiplayer.has_multiplayer_peer() and by_player.is_multiplayer_authority() and by_player.has_method("_rpc_to_ready_peers") and by_player.is_inside_tree():
|
||||
by_player._rpc_to_ready_peers("_sync_throw_bomb", [current_pos, force])
|
||||
|
||||
# Remove the interactable object
|
||||
queue_free()
|
||||
|
||||
print("Bomb object converted to projectile and thrown!")
|
||||
|
||||
@rpc("authority", "unreliable")
|
||||
func _sync_box_state(pos: Vector2, vel: Vector2, z_pos: float, z_vel: float, airborne: bool):
|
||||
# Only update on clients (server already has correct state)
|
||||
@@ -663,8 +708,23 @@ func setup_pushable_high_box():
|
||||
|
||||
if sprite:
|
||||
sprite.frame = bottom_frames[index]
|
||||
if sprite_above:
|
||||
sprite_above.frame = top_frames[index]
|
||||
if sprite_above:
|
||||
sprite_above.frame = top_frames[index]
|
||||
|
||||
func setup_bomb():
|
||||
object_type = "Bomb"
|
||||
is_grabbable = true
|
||||
can_be_pushed = false
|
||||
is_destroyable = false # Bombs don't break, they explode
|
||||
is_liftable = true
|
||||
weight = 0.5 # Light weight for easy throwing
|
||||
|
||||
# Set bomb sprite (frame 199 from items_n_shit.png)
|
||||
if sprite:
|
||||
sprite.texture = load("res://assets/gfx/pickups/items_n_shit.png")
|
||||
sprite.hframes = 20
|
||||
sprite.vframes = 14
|
||||
sprite.frame = 199
|
||||
|
||||
func _open_chest(by_player: Node = null):
|
||||
if is_chest_opened:
|
||||
|
||||
Reference in New Issue
Block a user