cops only shoot characters on the same screen as them (fixes issue #79)

This commit is contained in:
pennyrigate 2023-04-13 11:12:42 -04:00
parent 3e51a5062f
commit 8ac962d855

View file

@ -44,29 +44,30 @@ func _physics_process(delta):
# check for player in raycast # check for player in raycast
var collider = shoot_cast.get_collider() var collider = shoot_cast.get_collider()
if collider != null && (collider.is_in_group("player") or collider.is_in_group("msx")): if collider != null && (collider.is_in_group("player") or collider.is_in_group("msx")):
# kill player and enter shooting state temporarily if Game.get_sector(global_position) == Game.get_sector(collider.global_position):
collider.get_parent().die() # kill player and enter shooting state temporarily
# play sound collider.get_parent().die()
Audio.play_sound(Audio.a_die_robot, Audio.ac_boss) # play sound
# muzzle flash Audio.play_sound(Audio.a_die_robot, Audio.ac_boss)
muzzle_flash.emitting = true # muzzle flash
shooting = true muzzle_flash.emitting = true
get_tree().create_timer(0.05, false).connect("timeout", self, "_stop_shoot") shooting = true
sprite.play("shoot") get_tree().create_timer(0.05, false).connect("timeout", self, "_stop_shoot")
# check other raycast to find collision passing through player sprite.play("shoot")
graphics_cast.force_raycast_update() # check other raycast to find collision passing through player
var hit_position = graphics_cast.to_global(Vector2(256.0, 0.0)) graphics_cast.force_raycast_update()
if graphics_cast.is_colliding(): var hit_position = graphics_cast.to_global(Vector2(256.0, 0.0))
hit_position = graphics_cast.get_collision_point() if graphics_cast.is_colliding():
# set line point to point of collision hit_position = graphics_cast.get_collision_point()
var hit_x = shoot_line.to_local(hit_position).x # set line point to point of collision
shoot_line.points[1].x = hit_x var hit_x = shoot_line.to_local(hit_position).x
# shoot_line.visible = true shoot_line.points[1].x = hit_x
# get_tree().create_timer(0.05, false).connect("timeout", shoot_line, "set_visible", [false], CONNECT_DEFERRED) # shoot_line.visible = true
# move and play sparks # get_tree().create_timer(0.05, false).connect("timeout", shoot_line, "set_visible", [false], CONNECT_DEFERRED)
sparks.global_position = hit_position # move and play sparks
sparks.emitting = true sparks.global_position = hit_position
return sparks.emitting = true
return
# if there aren't turns, walk around # if there aren't turns, walk around
if turns == 0: if turns == 0: