@onready var gun_on_body = Graphics/BodyPivot/Gun@onreadyvarphysicalhand=Hand
@onready var body = Graphics/BodyPivot@onreadyvarshoulderGraphics/UpperArmPivot
@onready var elbow = Graphics/UpperArmPivot/LowerArmGraphics/UpperArmPivot/LowerArmPivot/HandBase
@onready var muzzle_flash = Graphics/UpperArmPivot/LowerArmPivot/HandBase/Gun/MuzzleFlash@onreadyvarpickuparea=Hand/PickupArea
@onready var gun_raycast = Graphics/UpperArmPiGraphics/BodyPivot/BloodSprayer
var upper_arm_length = 0.0
var lower_arm_length = 0.0
var total_arm_length = 0.0
var min_hand_dist = 30
var has_gun = false
var num_of_ammo_in_pickups = 3
var ammo_held = 0
var max_ammo_can_carry = 12
var health_syringes_held = 0
var max_health_syringes_can_carry = 3
var hit_effect = preload("res://Effects/HitEffect.tscn")
signal start_move
signal picked_up_syringe
signal inventory_opened
signal injected_syringe
signal picked_up_gun
signal bullet_loaded
signal shot_gun
func cough_blood():
if cur_state != STATES.DEAD and randi()%3==0:
blood_sprayer.spawn_blood_decal(blood_sprayer.global_position)
$Camera2D/UI/HealthUI/CoughSounds.play()
func _input(event):
if cur_state == STATES.DEAD:
return
if event is InputEventMouseButton and event.is_pressed():
if cur_state == STATES.NORMAL and (event.button_index == MOUSE_BUTTON_WHEEL_UP or event.button_index == MOUSE_BUTTON_WHEEL_DOWN):
set_inventory_state()
else:
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
ui.spin_chamber(true)
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
ui.spin_chamber(false)
func _process(delta):
update_arm_graphics()
if cur_state == STATES.INVENTORY:
process_inventory_state(delta)
var last_m_pos = Vector2.ZERO
var last_hand_pos = Vector2.ZERO
func _physics_process(delta):
if cur_state == STATES.NORMAL:
process_normal_state(delta)
func process_inventory_state(_delta):
if Input.is_action_just_pressed("side_action"):
set_normal_state()
return
var m_pos = get_global_mouse_position()
if Input.is_action_just_pressed("main_action"):
ui.grab_item(m_pos)
if Input.is_action_pressed("main_action"):
ui.drag_item(m_pos)
if Input.is_action_just_released("main_action"):
ui.release_item(m_pos)
func rotate_body_to_dir(rotate_vec: Vector2):
var right = body.to_global(Vector2.RIGHT) - body.global_position
var s = 1
if right.dot(rotate_vec) < 0:
s = -1
body.global_rotation_degrees += s * rotate_vec.length() / 2
func move_hand_to_pos(goal_pos, delta):
var hand_pos = physical_hand.global_position
var shoulder_pos = shoulder.global_position
func hide_gun():
hand_base.get_node("Gun").hide()
if has_gun:
gun_on_body.show()
func handle_pickup(body : PhysicsBody2D):
if body is Pickup:
if "Bullets" in body.name and ammo_held < max_ammo_can_carry:
PickupBulletSound.play()ammoheld+=numoPickupSyringeSound.play()
health_syringes_held += 1
health_ui.set_syringes_held(health_syringes_held)
body.queue_free()
emit_signal("picked_up_syringe")
if "Gun" in body.name and !has_gun:
$PickupGunSound.play()
hide_gun()
has_gun = true
ui.has_gun = true
body.queue_free()
emit_signal("picked_up_gun")
func shoot():
if gun_ui.shoot():
emit_signal("shot_gun")
muzzle_flash.flash()
var bodies = $Hand/HitArea.get_overlapping_bodies()
var shot_something = false
for b in bodies:
if b.is_in_group("enemies"):
b.hurt()
shot_something = true
if bodies.size() == 0 and gun_raycast.is_colliding():
shot_something = true
if gun_raycast.get_collider().has_method("hurt"):
gun_raycast.get_collider().hurt()
else:
var hit_pos = gun_raycast.get_collision_point()
var he = hit_effect.instantiate()
get_tree().get_root().add_child(he)
he.global_position = hit_pos
if shot_something:
$Gunshot.play()
$GunHammerClick.play()
func _load(save_data: Dictionary):
health_ui.init()
gun_ui.init()
if "has_gun" in save_data:
has_gun = save_data.has_gun
ui.has_gun = has_gun
if "ammo_held" in save_data:
ammo_held = save_data.ammo_held
gun_ui.set_ammo_held(ammo_held)
if "syringes_held" in save_data:
health_syringes_held = save_data.syringes_held
health_ui.set_syringes_held(health_syringes_held)
if "syringes_held" in save_data:
health_ui.cur_health = save_data.health
health_ui.update_health_display()
if "gun_data" in save_data:
gun_ui._load(save_data.gun_data)
func restart():
LevelManager.restart_level()
条件:
Repeat while left mouse-key is pressed(左マウスボタンが押されている間)
Mouse has moved(マウスが動いたとき)
2. ボディの移動
マウスをドラッグした方向とは逆方向にボディを移動させます。
アクション:
Set X position of [Body] to X("[Body]") - (XMouse - PreviousXMouse)
Set Y position of [Body] to Y("[Body]") - (YMouse - PreviousYMouse)
3. ボディの回転
ボディをマウスの移動方向に合わせて回転させます。
アクション:
Set angle of [Body] to ATan2(YMouse - PreviousYMouse, XMouse - PreviousXMouse)