Advertisement
Guest User

Untitled

a guest
Jun 5th, 2021
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Area2D
  2. class_name Player
  3.  
  4. signal spawn_laser(location)
  5.  
  6. onready var muzzle = $Muzzle
  7.  
  8. var speed = 300
  9.  
  10. var input_vector = Vector2.ZERO
  11.  
  12. var hp = 3
  13.  
  14. func _physics_process(delta):
  15. input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
  16. input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
  17.  
  18. global_position += input_vector * speed * delta
  19.  
  20. if Input.is_action_just_pressed("shoot"):
  21. shoot_laser()
  22.  
  23. func take_damage(damage):
  24. hp -= damage
  25. if hp <= 0:
  26. queue_free()
  27.  
  28.  
  29. func _on_Player_area_entered(area):
  30. if area.is_in_group("enemies"):
  31. area.take_damage(1)
  32.  
  33. func shoot_laser():
  34. emit_signal("spawn_laser", muzzle.global_position)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement