Advertisement
Kitomas

godot rocket game scripts

May 23rd, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. //"project_boost_2025-05-22\landing_pad.gd":
  4. class_name LandingPad
  5. extends CSGBox3D
  6.  
  7. @export_file('*.tscn') var path_of_next_level: String
  8.  
  9.  
  10.  
  11. func _ready() -> void:
  12.     assert(path_of_next_level != '',
  13.            'Path of next level is empty!')
  14.  
  15.     assert(ResourceLoader.exists(path_of_next_level),
  16.            '"%s" doesn\'t exist!' % path_of_next_level)
  17.        
  18.        
  19.        
  20.        
  21.        
  22. /******************************************************************************/
  23. /******************************************************************************/
  24. //"project_boost_2025-05-22\launch_pad.gd":
  25. class_name LaunchPad
  26. extends CSGBox3D
  27.  
  28. @onready var player_scene = preload("res://scene_objects/player.tscn")
  29.  
  30.  
  31.  
  32. # The launch pad automatically spawns a Player object on top of it!
  33. func _ready() -> void:
  34.     var player: Player = player_scene.instantiate()
  35.  
  36.     player.position = $".".global_position
  37.     player.position.y += size.y/2 + player.collider_size.y/2
  38.     get_tree().current_scene.add_child.call_deferred(player)
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /******************************************************************************/
  45. /******************************************************************************/
  46. //"project_boost_2025-05-22\obstacle.gd":
  47. class_name Obstacle
  48. extends CSGBox3D
  49.  
  50. # Beige-ish by default
  51. @export var color: Color = Color(0.76, 0.57, 0.40)
  52.  
  53.  
  54.  
  55. func _ready() -> void:
  56.     material.albedo_color = color
  57.  
  58.  
  59.  
  60.  
  61.  
  62. /******************************************************************************/
  63. /******************************************************************************/
  64. //"project_boost_2025-05-22\player.gd":
  65. class_name Player
  66. extends RigidBody3D
  67.  
  68.  
  69.  
  70. @export_range(0, 10000, 100, "or_greater") var velocity_thrust: float = 1000.0
  71. @export_range(0, 2000, 10, "or_greater") var velocity_rotation: float =  200.0
  72.  
  73. # TBD: Figure out how to auto-detect collider size during object initialization
  74. var collider_size: Vector3 = Vector3(2.0, 2.0, 2.0) # (2 meters at 1x scale)
  75.  
  76. var is_losing_or_winning: bool
  77.  
  78.  
  79.  
  80.  
  81.  
  82. func _ready():
  83.     is_losing_or_winning = false
  84.  
  85.  
  86.  
  87. func _process(delta: float) -> void:
  88.     if Input.is_action_pressed("rocket_thrust"):
  89.         apply_central_force(basis.y * delta*velocity_thrust);
  90.  
  91.     # elif is not used in order to cancel out the action if both are pressed
  92.     if Input.is_action_pressed("rocket_lturn"):
  93.         apply_torque(Vector3(0,0, delta*velocity_rotation))
  94.  
  95.     if Input.is_action_pressed("rocket_rturn"):
  96.         apply_torque(Vector3(0,0, -delta*velocity_rotation))
  97.  
  98.  
  99.  
  100.  
  101.  
  102. func _on_body_entered(body: Node) -> void:
  103.     var groups: Array = body.get_groups()
  104.  
  105.     if "Crash" in groups:
  106.         crash_sequence()
  107.  
  108.     elif "Goal" in groups:
  109.         complete_level(body.path_of_next_level)
  110.  
  111.  
  112.  
  113.  
  114.  
  115. func crash_sequence() -> void:
  116.     if is_losing_or_winning: return
  117.     is_losing_or_winning = true
  118.  
  119.     print("You Fail It! Your Skill Is Not Enough!")
  120.     await get_tree().create_timer(1.0).timeout
  121.     get_tree().reload_current_scene()
  122.  
  123.  
  124.  
  125. func complete_level(next_level_file: String) -> void:
  126.     if is_losing_or_winning: return
  127.     is_losing_or_winning = true
  128.  
  129.     print("You're Winner!")
  130.     await get_tree().create_timer(1.0).timeout
  131.     get_tree().change_scene_to_file(next_level_file)
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement