Advertisement
Guest User

Gun.gd

a guest
Jun 18th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1.           @@ -0,0 +1,34 @@
  2.         1 +extends Weapon
  3.         2 +
  4.         3 +func _ready():
  5.         4 + fire_rate = 1       #fire rate (pause between shots)
  6.         5 + clip_size = 6       #clip size
  7.         6 + reload_rate = 2     #reload time
  8.         7 + weapon_damage = 50  #base damage of any weapon
  9.         8 +
  10.         9 + current_ammo = 5
  11.        10 + can_fire = true             #bool for if weapon can be fired
  12.        11 + reloading = false           #checks if reloading
  13.        12 +
  14.        13 +func process():
  15.        14 + raycast.cast_to = 1000 #doesnt work yet!
  16.        15 +
  17.        16 +func fire():
  18.        17 + print("Fired Gun")
  19.        18 + can_fire = false
  20.        19 + current_ammo -= 1            #reduce clip size
  21.        20 + check_colission()
  22.        21 + $"/root/Level01/Player/weapon/shotgun/shotgun_shot".play()
  23.        22 +
  24.        23 + $"/root/Level01/Player/weapon/shotgun/Sprite".play("shot")
  25.        24 + yield(get_tree().create_timer(fire_rate), "timeout") #wait till timeout of fire_rate
  26.        25 + #$shotgun/Sprite.stop()     #doesnt work yet
  27.        26 + can_fire = true             #after fire_rate pause, can_fire again
  28.        27 +
  29.        28 +func reload():
  30.        29 + print("Reloading Gun")
  31.        30 + reloading = true
  32.        31 + yield(get_tree().create_timer(reload_rate), "timeout")
  33.        32 + current_ammo = clip_size    #fill ammo
  34.        33 + reloading = false           #reloading done
  35.        34 + print("Reload Complete")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement