Skip to content

Commit

Permalink
trying to make remove gun
Browse files Browse the repository at this point in the history
  • Loading branch information
megarubber committed Apr 19, 2022
1 parent 8e1b710 commit d102948
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
23 changes: 21 additions & 2 deletions guns/Gun.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions levels/Level1.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
17 changes: 10 additions & 7 deletions player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit d102948

Please sign in to comment.