Advertisement
WarrenBrandt

Code1

Nov 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. extends Area2D
  2. const MOVE_SPEED = 300
  3.  
  4. const SCREEN_WIDTH = 1920
  5.  
  6. const SCREEN_HEIGHT = 1080
  7.  
  8. var can_shoot = true
  9.  
  10. var shot_scene = preload("res://scenes/shot.tscn")
  11. var explosion_scene = preload("res://Scenes/player_explosion.tscn")
  12.  
  13. signal destroyed
  14.  
  15. func _process(delta):
  16.  
  17. if Input.is_key_pressed(KEY_SPACE) and can_shoot:
  18. var stage_node = get_parent()
  19. can_shoot = false
  20. get_node("reload_timer").start()
  21.  
  22. var shot_instance = shot_scene.instance()
  23. shot_instance.position = position
  24. stage_node.add_child(shot_instance)
  25.  
  26. var input_dir = Vector2()
  27.  
  28. if Input.is_key_pressed(KEY_UP):
  29. input_dir.y -= 1.0
  30.  
  31. if Input.is_key_pressed(KEY_DOWN):
  32. input_dir.y += 1.0
  33.  
  34. if Input.is_key_pressed(KEY_LEFT):
  35. input_dir.x -= 1.0
  36. $sprite.play("left")
  37.  
  38. elif Input.is_key_pressed(KEY_RIGHT):
  39. input_dir.x += 1.0
  40. $sprite.play("right")
  41.  
  42. else:
  43. $sprite.play("neutral")
  44.  
  45. position += (delta * MOVE_SPEED) * input_dir
  46. $engine.emitting = true
  47.  
  48. if position.x < 0.0:
  49. position.x = 0.0
  50. elif position.x > SCREEN_WIDTH:
  51. position.x = SCREEN_WIDTH
  52.  
  53. if position.y < 0.0:
  54. position.y = 0.0
  55. elif position.y > SCREEN_HEIGHT:
  56. position.y = SCREEN_HEIGHT
  57.  
  58. func _on_reload_timer_timeout():
  59. can_shoot = true
  60.  
  61. func _on_player_area_entered(area):
  62. if area.is_in_group("asteroid"):
  63. queue_free()
  64. var stage_node = get_parent()
  65. var explosion_instance = explosion_scene.instance()
  66. explosion_instance.position = position
  67. stage_node.add_child(explosion_instance)
  68. emit_signal("destroyed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement