Advertisement
CodeTortoise

blue_laser.gd

Jan 3rd, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1.  
  2. extends RigidBody2D
  3.  
  4. var name = 'blue_laser'
  5.  
  6. var laser_speed = 1
  7.  
  8.  
  9. var laser_pos
  10. var sound
  11. var score = 0
  12.  
  13. func _ready():
  14.     set_fixed_process(true)
  15.     sound = get_node("SamplePlayer2D")
  16.     sound.play("laser1")
  17.    
  18. func _fixed_process(delta):
  19.     apply_impulse(Vector2(0,0), Vector2(0,-1) * laser_speed)
  20.     laser_pos = self.get_pos()
  21.  
  22.     if laser_pos.y < 0:
  23.         free()
  24.         print ("laser free")
  25.  
  26. func _integrate_forces(state):
  27.     var count = state.get_contact_count()
  28.     if count > 0:
  29.         print("count " + str(count))
  30.         var collider = state.get_contact_collider_object(0)
  31.         print(collider)
  32.         if collider.get_name() != 'Player':
  33.             update_score()
  34.             print('freeing: ' + collider.get_name())
  35.             collider.hide()
  36.             collider.queue_free()
  37.             hide()
  38.             queue_free()
  39.  
  40.  
  41. func update_score():
  42.     print("update score called")
  43.     score += 100
  44.     print(score)
  45.     get_parent().get_node("Score").set_text("Score: " + str(score))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement