Advertisement
Guest User

Untitled

a guest
Feb 10th, 2023
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | Source Code | 0 0
  1. extends Node2D
  2.  
  3. var time = 1.0
  4. var speed = 10
  5. var distance_from_center = 15
  6.  
  7. const GUNBULLET = preload("res://gun_bullet.tscn")
  8.  
  9. onready var sprite = $Sprite
  10.  
  11. func shoot_bullet():
  12. if Input.is_action_pressed("shoot") and !Input.is_action_pressed("laser"):
  13. var gunbullet = GUNBULLET.instance()
  14. get_parent().add_child(gunbullet)
  15. gunbullet.position = sprite.global_position
  16. func shoot_laser():
  17. if Input.is_action_pressed("laser") and !Input.is_action_pressed("shoot"):
  18. sprite.position.x = 8
  19. sprite.position.y = -16
  20. func layering():
  21. if sprite.position.y <= 0:
  22. set_z_index(-1)
  23. if sprite.position.y >= 0:
  24. set_z_index(0)
  25.  
  26. func _physics_process(delta):
  27. time += delta
  28. var angle = speed * time
  29. var rotation = Vector2(cos(angle), sin(angle)/3)
  30. sprite.position = rotation * distance_from_center
  31. func _process(delta):
  32. shoot_bullet()
  33. shoot_laser()
  34. layering()
  35. #print(sprite.global_position)
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement