From d10294811218bd675124172f6dd9ba5d20f29d54 Mon Sep 17 00:00:00 2001 From: Guilherme Samuel Date: Tue, 19 Apr 2022 12:53:44 -0300 Subject: [PATCH] trying to make remove gun --- guns/Gun.gd | 23 +++++++++++++++++++++-- levels/Level1.tscn | 5 +++++ player/Player.gd | 17 ++++++++++------- project.godot | 5 +++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/guns/Gun.gd b/guns/Gun.gd index 46a7882..5b25119 100644 --- a/guns/Gun.gd +++ b/guns/Gun.gd @@ -14,6 +14,7 @@ var gun_pos_flip_true = Vector2(4, -88) var p_knock_side = -1 var changing = false var impulse_strength = 2 +var previous_gun = 0 # Bullet Referecing var bullet = preload("res://others/bullet/BulletBase.tscn") @@ -52,6 +53,20 @@ func add_gun_at_inventory(which_gun) -> void: Global.inventory_guns[0] = Global.inventory_guns[1] Global.inventory_guns[1] = which_gun +func remove_gun() -> void: + if len(Global.inventory_guns) > 0: + if len(Global.inventory_guns) < 2: + hands.visible = true + visible = false + previous_gun = Global.inventory_guns[0] + player.dropping_gun(NO_GUN) + gun_type = NO_GUN + Global.inventory_guns.clear() + else: + previous_gun = Global.inventory_guns[1] + change_gun() + Global.inventory_guns.remove(1) + func change_gun() -> void: if len(Global.inventory_guns) >= 2: sound_effect_4.play() @@ -150,11 +165,15 @@ func shoot_spread(): can_fire = false func _input(event) -> void: - if event.is_action_pressed("ui_change") && !player.lifebar.getDeath(): - change_gun() + if !player.lifebar.getDeath(): + if event.is_action_pressed("ui_change"): + change_gun() + if event.is_action_pressed("ui_remove"): + remove_gun() func _physics_process(_delta: float) -> void: flame.global_position = muzzle.global_position + print(previous_gun) if !player.lifebar.getDeath(): if gun_type != NO_GUN: position += velocity diff --git a/levels/Level1.tscn b/levels/Level1.tscn index 087c60c..77d99b8 100644 --- a/levels/Level1.tscn +++ b/levels/Level1.tscn @@ -2160,6 +2160,11 @@ type = 2 position = Vector2( 1725, -17 ) scale = Vector2( 2.5, 2.5 ) +[node name="PickupGun5" parent="Guns" instance=ExtResource( 52 )] +position = Vector2( 1890, -17 ) +scale = Vector2( 2.5, 2.5 ) +type = 4 + [node name="PickupGun2" parent="Guns" instance=ExtResource( 52 )] position = Vector2( 6171, -874 ) scale = Vector2( 2.5, 2.5 ) diff --git a/player/Player.gd b/player/Player.gd index 9aec02c..b5667de 100644 --- a/player/Player.gd +++ b/player/Player.gd @@ -142,12 +142,7 @@ func death() -> void: anim.play("dead") if !wings.visible: if gun.gun_type < 5: - var g = drop_gun.instance() - g.global_position = gun.position - g.apply_central_impulse(Vector2.UP * 200) - add_child(g) - g = get_node("DropGun") - g.sprite.texture = g.gun_textures[gun.gun_type] + dropping_gun(gun.gun_type) death_sound_effect.play() Global.play_music("res://audio/music/death-theme.ogg") Global.life -= 1 @@ -156,7 +151,15 @@ func death() -> void: ring.visible = true deactivate_all_colliders() Global.is_playing = false - + +func dropping_gun(which_gun) -> void: + var g = drop_gun.instance() + g.global_position = gun.position + g.apply_central_impulse(Vector2.UP * 200) + add_child(g) + g = get_node("DropGun") + g.sprite.texture = g.gun_textures[which_gun] + func deactivate_all_colliders() -> void: drop.monitorable = false drop.monitoring = false diff --git a/project.godot b/project.godot index 41622eb..4a99f37 100644 --- a/project.godot +++ b/project.godot @@ -76,6 +76,11 @@ ui_change={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +ui_remove={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [layer_names]