init
This commit is contained in:
66
scripts/AsteroidManager.gd
Normal file
66
scripts/AsteroidManager.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
extends Node2D
|
||||
|
||||
const ASTEROID = preload("res://scenes/asteroid.tscn")
|
||||
const FUEL_TANK = preload("res://scenes/fuel_tank.tscn")
|
||||
const STAR_FRAGMENT = preload("res://scenes/star_fragment.tscn")
|
||||
|
||||
@onready var rocket: Rocket = %Rocket
|
||||
@onready var spawn_timer = %SpawnTimer
|
||||
|
||||
var noise: Noise
|
||||
@export var delim_value: float = 0.34
|
||||
@export var fuel_value: float = 0.3#-0.58
|
||||
@export var star_rarity: float = 0.5#0.1
|
||||
|
||||
func _ready():
|
||||
noise = FastNoiseLite.new()
|
||||
noise.seed = randi() % 1000000
|
||||
noise.frequency = 0.007
|
||||
|
||||
for pod: SpacePod in DataHandler.spawn_pods():
|
||||
add_child(pod)
|
||||
|
||||
|
||||
func _on_spawn_timer_timeout():
|
||||
spawn_timer.wait_time = 9.5 / max(rocket.velocity.length(), 8)
|
||||
for a in range(-36, 36):
|
||||
var angle = rocket.rotation + (a / 30.0) + (randf() / 25.0)
|
||||
var pos = rocket.position + (Vector2.from_angle(angle) * 420.0)
|
||||
|
||||
var value = noise.get_noise_2d(pos.x, pos.y)
|
||||
if value > delim_value:
|
||||
if _check_spawn_loc(pos, 13):
|
||||
var asteroid_spawn = ASTEROID.instantiate()
|
||||
asteroid_spawn.position = pos
|
||||
add_child(asteroid_spawn)
|
||||
|
||||
if value < fuel_value:
|
||||
var rand_pickup = randf()
|
||||
if _check_spawn_loc(pos, 82):
|
||||
if rand_pickup < star_rarity:
|
||||
var star = STAR_FRAGMENT.instantiate()
|
||||
star.position = pos
|
||||
add_child(star)
|
||||
else:
|
||||
var fuel_spawn = FUEL_TANK.instantiate()
|
||||
fuel_spawn.position = pos
|
||||
add_child(fuel_spawn)
|
||||
|
||||
func _check_spawn_loc(pos: Vector2, radius: int):
|
||||
var shape_rid = PhysicsServer2D.circle_shape_create()
|
||||
|
||||
PhysicsServer2D.shape_set_data(shape_rid, radius)
|
||||
|
||||
var params = PhysicsShapeQueryParameters2D.new()
|
||||
params.shape_rid = shape_rid
|
||||
params.transform = Transform2D(0.0, pos)
|
||||
params.collision_mask = 1
|
||||
|
||||
# Execute physics queries here...
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
var results = space_state.intersect_shape(params)
|
||||
|
||||
# Release the shape when done with physics queries.
|
||||
PhysicsServer2D.free_rid(shape_rid)
|
||||
|
||||
return results.is_empty()
|
||||
42
scripts/SpaceGUI.gd
Normal file
42
scripts/SpaceGUI.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var fuel_gauge = %FuelGauge
|
||||
@onready var eject_pod_level = %EjectPodLevel
|
||||
@onready var eject_indicator_bkgd := $EjectPodLevel/EjectIndicator/Background
|
||||
@onready var cargo_item_container = %CargoItemContainer
|
||||
@onready var no_cargo_placeholder = %NoCargoPlaceholder
|
||||
|
||||
const CARGO_ITEM = preload("res://scenes/cargo_item.tscn")
|
||||
|
||||
var cargo_gui_panels := {}
|
||||
|
||||
func _ready():
|
||||
DataHandler.pickup_item.connect(_on_pickup_item)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
fuel_gauge.value = DataHandler.get_fuel()
|
||||
var percent = DataHandler.get_fuel_percent()
|
||||
var r = min(2 - 2 * percent, 1)
|
||||
var g = min(2.0 * percent, 1)
|
||||
fuel_gauge.get("theme_override_styles/fill").bg_color = Color(r, g, 0.0)
|
||||
|
||||
var eject_percent = DataHandler.eject_fuel_max_percentage()
|
||||
eject_pod_level.position.y = (1.0 - eject_percent) * get_viewport().size.y - 16
|
||||
eject_indicator_bkgd.modulate = Color.GREEN if DataHandler.has_fuel_needed_for_eject() else Color.RED
|
||||
|
||||
func _on_pickup_item():
|
||||
if DataHandler.has_cargo():
|
||||
if cargo_gui_panels.is_empty():
|
||||
no_cargo_placeholder.queue_free()
|
||||
for key in DataHandler.game_data.cargo:
|
||||
var count = DataHandler.game_data.cargo[key]
|
||||
if count > 0:
|
||||
if not cargo_gui_panels.has(key):
|
||||
cargo_gui_panels[key] = CARGO_ITEM.instantiate()
|
||||
cargo_item_container.add_child(cargo_gui_panels[key])
|
||||
cargo_gui_panels[key].init(key, count)
|
||||
else:
|
||||
cargo_gui_panels[key].update_count(count)
|
||||
|
||||
var cargo_gui: Node
|
||||
12
scripts/cargo_item.gd
Normal file
12
scripts/cargo_item.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
extends PanelContainer
|
||||
class_name CargoItem
|
||||
|
||||
@onready var item_texture: TextureRect = %ItemTexture
|
||||
@onready var item_label: Label = %ItemLabel
|
||||
|
||||
func init(type: String, count: int):
|
||||
item_texture.texture = DataHandler.type_to_texture(type)
|
||||
item_label.text = "x%s" % count
|
||||
|
||||
func update_count(count: int):
|
||||
item_label.text = "x%s" % count
|
||||
16
scripts/configuration_menu.gd
Normal file
16
scripts/configuration_menu.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
extends Control
|
||||
class_name ConfigurationMenu
|
||||
|
||||
@onready var modules_container = %ModulesContainer
|
||||
|
||||
const MODULE_SELECTOR = preload("res://scenes/module_selector.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
for child in modules_container.get_children():
|
||||
modules_container.remove_child(child)
|
||||
modules_container.add_spacer(true)
|
||||
modules_container.add_child(MODULE_SELECTOR.instantiate().with_location_data(GameData.ModuleType.ENGINE))
|
||||
for i in DataHandler.get_mid_count():
|
||||
modules_container.add_child(MODULE_SELECTOR.instantiate().with_location_data(GameData.ModuleType.MID, i))
|
||||
modules_container.add_child(MODULE_SELECTOR.instantiate().with_location_data(GameData.ModuleType.COCKPIT))
|
||||
modules_container.add_spacer(false)
|
||||
9
scripts/cost_container.gd
Normal file
9
scripts/cost_container.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends BoxContainer
|
||||
class_name CostContainer
|
||||
|
||||
@onready var resource_texture := $HBoxContainer/ResourceTexture
|
||||
@onready var cost_text_edit := $HBoxContainer/CostTextEdit
|
||||
|
||||
func set_data(tex: Texture, cost: int) -> void:
|
||||
resource_texture.texture = tex
|
||||
cost_text_edit.text = str(cost)
|
||||
135
scripts/data_handler.gd
Normal file
135
scripts/data_handler.gd
Normal file
@@ -0,0 +1,135 @@
|
||||
extends Node
|
||||
|
||||
signal pickup_item
|
||||
|
||||
const ENTITIES = preload("res://assets/entities.png")
|
||||
const SAVE_FILE = "user://misguided_data.tres"
|
||||
const SPACE_POD = preload("res://scenes/space_pod.tscn")
|
||||
|
||||
const type_to_int ={
|
||||
"star": 96,
|
||||
"fuel": 64
|
||||
}
|
||||
|
||||
var game_data: GameData
|
||||
|
||||
var current_rocket: Rocket
|
||||
|
||||
func get_current_rocket_display() -> Array[TextureRect]:
|
||||
var rocket: Array[TextureRect] = []
|
||||
return rocket
|
||||
|
||||
func ready_to_launch() -> bool:
|
||||
return not game_data.modules[GameData.ModuleType.ENGINE].is_empty() and not game_data.modules[GameData.ModuleType.COCKPIT]
|
||||
|
||||
func launch_rocket() -> void:
|
||||
game_data.cargo = {}
|
||||
game_data.fuel = game_data.fuel_max
|
||||
|
||||
func pickup(type: String) -> void:
|
||||
game_data.pickup(type)
|
||||
pickup_item.emit()
|
||||
|
||||
func has_cargo() -> bool:
|
||||
return game_data.has_cargo()
|
||||
|
||||
func type_to_texture(type: String) -> Texture:
|
||||
var texture := AtlasTexture.new()
|
||||
texture.atlas = ENTITIES
|
||||
texture.region = Rect2(type_to_int[type], 0, 32, 32)
|
||||
return texture
|
||||
|
||||
func move_cargo_to_inventory() -> void:
|
||||
game_data.move_cargo_to_inventory()
|
||||
|
||||
func create_cargo_pod(pod_position: Vector2) -> void:
|
||||
game_data.create_cargo_pod(pod_position)
|
||||
|
||||
func save_game_data() -> void:
|
||||
ResourceSaver.save(game_data, SAVE_FILE)
|
||||
|
||||
func load_game_data() -> void:
|
||||
if ResourceLoader.exists(SAVE_FILE):
|
||||
game_data = load(SAVE_FILE)
|
||||
else:
|
||||
game_data = GameData.new()
|
||||
|
||||
func spawn_pods() -> Array[SpacePod]:
|
||||
var pod_nodes: Array[SpacePod] = []
|
||||
for pod: FloatingPodData in game_data.floating_pods:
|
||||
var pod_spawn = SPACE_POD.instantiate()
|
||||
pod_spawn.pod_data = pod
|
||||
pod_spawn.position = pod.position
|
||||
pod_nodes.append(pod_spawn)
|
||||
return pod_nodes
|
||||
|
||||
func retrive_pod(pod_data: FloatingPodData) -> void:
|
||||
for item in pod_data.cargo:
|
||||
game_data.pickup(item, pod_data.cargo[item])
|
||||
var index = game_data.floating_pods.find(pod_data)
|
||||
if index >= 0:
|
||||
game_data.floating_pods.remove_at(index)
|
||||
pickup_item.emit()
|
||||
|
||||
func remove_module(location: GameData.ModuleType, part: String) -> void:
|
||||
print("Module removed %s" % part)
|
||||
|
||||
func add_module(location: GameData.ModuleType, part: Module) -> void:
|
||||
print("Module added %s" % part)
|
||||
|
||||
func initial_velocity() -> Vector2:
|
||||
return Vector2.RIGHT * get_speed() * 0.011
|
||||
|
||||
func has_fuel() -> bool:
|
||||
return game_data.fuel > 0
|
||||
|
||||
func add_fuel(amount: float, apply_efficiency: bool = false) -> void:
|
||||
game_data.fuel += amount if not apply_efficiency else amount * game_data.fuel_efficiency
|
||||
|
||||
func get_fuel() -> float:
|
||||
return game_data.fuel
|
||||
|
||||
func get_fuel_percent() -> float:
|
||||
return game_data.fuel / game_data.fuel_max
|
||||
|
||||
func get_speed() -> float:
|
||||
return game_data.SPEED
|
||||
|
||||
func get_maneuverability() -> float:
|
||||
return 0.01
|
||||
|
||||
func has_fuel_needed_for_eject() -> bool:
|
||||
return eject_fuel_percentage() >= 1.0
|
||||
|
||||
func eject_fuel_percentage() -> float:
|
||||
return game_data.fuel / fuel_needed_for_eject()
|
||||
|
||||
func eject_fuel_max_percentage() -> float:
|
||||
return fuel_needed_for_eject() / game_data.fuel_max
|
||||
|
||||
func fuel_needed_for_eject() -> float:
|
||||
return max(current_rocket.position.length() / 160.0, 10.0)
|
||||
|
||||
func get_available_upgrades() -> Array[Upgrade]:
|
||||
return game_data.upgrades.filter(func(upgd: Upgrade) -> bool: return not upgd.purchased)
|
||||
|
||||
func purchase_upgrade(upgrade: Upgrade) -> bool:
|
||||
upgrade.purchased = not upgrade.purchased
|
||||
if not has_upgrade_cost(upgrade): return false
|
||||
var index = game_data.upgrades.find(upgrade)
|
||||
if index < 0: return false
|
||||
#TODO finsh this
|
||||
print(game_data.upgrades[index].purchased)
|
||||
return true
|
||||
|
||||
func has_upgrade_cost(upgrade: Upgrade) -> bool:
|
||||
for item in upgrade.cost:
|
||||
if not game_data.inventory.has(item) or game_data.inventory[item] < upgrade.cost[item]:
|
||||
return false
|
||||
return true
|
||||
|
||||
func get_modules_for_location(location: GameData.ModuleType) -> Array:
|
||||
return game_data.modules[location]
|
||||
|
||||
func get_mid_count() -> int:
|
||||
return game_data.mid_module_limit
|
||||
5
scripts/floating_pod_data.gd
Normal file
5
scripts/floating_pod_data.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name FloatingPodData
|
||||
|
||||
@export var position: Vector2
|
||||
@export var cargo: Dictionary = {}
|
||||
7
scripts/fuel_tank.gd
Normal file
7
scripts/fuel_tank.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Pickup
|
||||
class_name FuelTank
|
||||
|
||||
func pickup(rocket: Rocket):
|
||||
if not is_queued_for_deletion():
|
||||
DataHandler.pickup('fuel')
|
||||
super(rocket)
|
||||
58
scripts/game_data.gd
Normal file
58
scripts/game_data.gd
Normal file
@@ -0,0 +1,58 @@
|
||||
class_name GameData
|
||||
extends Resource
|
||||
|
||||
@export var SPEED: float = 2900.0
|
||||
@export var ENGINE_SPEED: float = 1900.0
|
||||
@export var fuel: float = 100
|
||||
@export var fuel_max: float = 100
|
||||
@export var engine_speed_modifier: float = 1.0
|
||||
@export var fuel_efficiency: float = 1.0
|
||||
@export var engine_maneuverability_modifier: float = 1.0
|
||||
|
||||
@export var cargo: Dictionary = {}
|
||||
@export var inventory: Dictionary = {}
|
||||
@export var upgrades: Array[Upgrade] = [FirstUpgrade.new()]
|
||||
@export var mid_module_limit: int = 0
|
||||
@export var modules: Dictionary = {
|
||||
0: [],
|
||||
1: [],
|
||||
2: []
|
||||
}
|
||||
@export var floating_pods: Array[FloatingPodData] = []
|
||||
|
||||
enum ModuleType {
|
||||
ENGINE,
|
||||
MID,
|
||||
COCKPIT
|
||||
}
|
||||
|
||||
func get_active_rocket_modules() -> Array[Module]:
|
||||
var _modules: Array[Module] = []
|
||||
return _modules
|
||||
|
||||
static func get_module_type_name(_type: ModuleType) -> String:
|
||||
return ModuleType.keys()[_type]
|
||||
|
||||
func pickup(type: String, amount: int = 1) -> void:
|
||||
if not cargo.has(type):
|
||||
cargo[type] = 0
|
||||
cargo[type] += amount
|
||||
|
||||
func has_cargo() -> bool:
|
||||
var cargo_size: int = 0
|
||||
for item: int in cargo.values():
|
||||
cargo_size += item
|
||||
return cargo_size > 0
|
||||
|
||||
func move_cargo_to_inventory() -> void:
|
||||
for item: String in cargo:
|
||||
if not inventory.has(item):
|
||||
inventory[item] = 0
|
||||
inventory[item] += cargo[item]
|
||||
|
||||
func create_cargo_pod(pod_position: Vector2) -> void:
|
||||
if not cargo.is_empty():
|
||||
var pod: FloatingPodData = FloatingPodData.new()
|
||||
pod.position = pod_position
|
||||
pod.cargo = cargo
|
||||
floating_pods.append(pod)
|
||||
14
scripts/inventory_menu.gd
Normal file
14
scripts/inventory_menu.gd
Normal file
@@ -0,0 +1,14 @@
|
||||
extends Control
|
||||
|
||||
const CARGO_ITEM = preload("res://scenes/cargo_item.tscn")
|
||||
|
||||
@onready var inventory_container = %InventoryContainer
|
||||
|
||||
func _ready():
|
||||
for child in inventory_container.get_children():
|
||||
inventory_container.remove_child(child)
|
||||
for item in DataHandler.game_data.inventory:
|
||||
var grid_item = CARGO_ITEM.instantiate()
|
||||
inventory_container.add_child(grid_item)
|
||||
grid_item.init(item, DataHandler.game_data.inventory[item])
|
||||
|
||||
58
scripts/launch_menu.gd
Normal file
58
scripts/launch_menu.gd
Normal file
@@ -0,0 +1,58 @@
|
||||
extends Control
|
||||
|
||||
const UPGRADES_MENU = preload("res://scenes/upgrades_menu.tscn")
|
||||
const CONFIGURATION_MENU = preload("res://scenes/configuration_menu.tscn")
|
||||
const INVENTORY_MENU = preload("res://scenes/inventory_menu.tscn")
|
||||
|
||||
@onready var menu_root = %MenuRoot
|
||||
@onready var rocket_display_container = %RocketDisplayContainer
|
||||
@onready var configuration_button = $MenuRoot/RightMenu/ButtonContainer/ConfigurationButton
|
||||
@onready var launch_button = $MenuRoot/RightMenu/ButtonContainer/LaunchButton
|
||||
|
||||
var upgrades_menu: Node
|
||||
var configuration_menu: Node
|
||||
var inventory_menu: Node
|
||||
|
||||
func _ready():
|
||||
upgrades_menu = UPGRADES_MENU.instantiate()
|
||||
upgrades_menu.get_node("MarginContainer/VBoxContainer/HeaderContainer/ReturnButton").connect("pressed", _on_upgrades_return_button_pressed)
|
||||
|
||||
configuration_menu = CONFIGURATION_MENU.instantiate()
|
||||
configuration_menu.get_node("MarginContainer/VBoxContainer/HBoxContainer/ReturnButton").connect("pressed", _on_configuration_return_button_pressed)
|
||||
|
||||
inventory_menu = INVENTORY_MENU.instantiate()
|
||||
inventory_menu.get_node("MarginContainer/VBoxContainer/HBoxContainer/ReturnButton").connect("pressed", _on_inventory_return_button_pressed)
|
||||
|
||||
DataHandler.load_game_data()
|
||||
|
||||
if not DataHandler.ready_to_launch():
|
||||
configuration_button.disabled = true
|
||||
launch_button.disabled = true
|
||||
|
||||
func _on_launch_button_pressed():
|
||||
DataHandler.launch_rocket()
|
||||
get_tree().change_scene_to_file("res://scenes/space.tscn")
|
||||
|
||||
func _on_upgrades_return_button_pressed():
|
||||
remove_child(upgrades_menu)
|
||||
menu_root.visible = true
|
||||
|
||||
func _on_configuration_return_button_pressed():
|
||||
remove_child(configuration_menu)
|
||||
menu_root.visible = true
|
||||
|
||||
func _on_inventory_return_button_pressed():
|
||||
remove_child(inventory_menu)
|
||||
menu_root.visible = true
|
||||
|
||||
func _on_upgrades_button_pressed():
|
||||
add_child(upgrades_menu)
|
||||
menu_root.visible = false
|
||||
|
||||
func _on_configuration_button_pressed():
|
||||
add_child(configuration_menu)
|
||||
menu_root.visible = false
|
||||
|
||||
func _on_inventory_button_pressed():
|
||||
add_child(inventory_menu)
|
||||
menu_root.visible = false
|
||||
18
scripts/module_selector.gd
Normal file
18
scripts/module_selector.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends VBoxContainer
|
||||
class_name ModuleSelector
|
||||
|
||||
@onready var location_label = %LocationLabel
|
||||
@onready var module_selector_option = %ModuleSelectorOption
|
||||
@onready var module_texture = %ModuleTexture
|
||||
@onready var description_label = %DescriptionLabel
|
||||
|
||||
var _location: GameData.ModuleType
|
||||
var modules_list: Array
|
||||
|
||||
func with_location_data(location: GameData.ModuleType, _mid_index: int = 0) -> ModuleSelector:
|
||||
_location = location
|
||||
return self
|
||||
|
||||
func _ready():
|
||||
modules_list = DataHandler.get_modules_for_location(_location)
|
||||
location_label.text = GameData.get_module_type_name(_location)
|
||||
13
scripts/modules/module.gd
Normal file
13
scripts/modules/module.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
extends Resource
|
||||
class_name Module
|
||||
|
||||
@export var name: String = "Base Module"
|
||||
@export var description: String = "Base Module Description"
|
||||
@export var texture: Texture
|
||||
@export var tier: int = -1
|
||||
@export var location: GameData.ModuleType
|
||||
@export var active: int = -1
|
||||
|
||||
@export var base_fuel_max: int = 10
|
||||
@export var base_speed: float = 2900.0
|
||||
@export var base_maneuverability: float = 0.01
|
||||
6
scripts/modules/standard_cockpit_module.gd
Normal file
6
scripts/modules/standard_cockpit_module.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends Module
|
||||
class_name StandardCockpitModule
|
||||
|
||||
func _init():
|
||||
name = "Standard Cockpit"
|
||||
location = GameData.ModuleType.COCKPIT
|
||||
6
scripts/modules/standard_engine_module.gd
Normal file
6
scripts/modules/standard_engine_module.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends Module
|
||||
class_name StandardEngineModule
|
||||
|
||||
func _init():
|
||||
name = "Standard Engine"
|
||||
location = GameData.ModuleType.ENGINE
|
||||
6
scripts/pickup.gd
Normal file
6
scripts/pickup.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends CharacterBody2D
|
||||
class_name Pickup
|
||||
|
||||
func pickup(rocket: Rocket):
|
||||
if not is_queued_for_deletion():
|
||||
queue_free()
|
||||
74
scripts/rocket.gd
Normal file
74
scripts/rocket.gd
Normal file
@@ -0,0 +1,74 @@
|
||||
extends CharacterBody2D
|
||||
class_name Rocket
|
||||
|
||||
@onready var camera := %Camera2D
|
||||
@onready var sprite := %Sprite2D
|
||||
@onready var gpu_particles_2d_middle := $GPUParticles2DMiddle
|
||||
@onready var gpu_particles_2d_top := $GPUParticles2DTop
|
||||
@onready var gpu_particles_2d_bottom := $GPUParticles2DBottom
|
||||
|
||||
var is_ejecting = false
|
||||
|
||||
func _ready() -> void:
|
||||
DataHandler.current_rocket = self
|
||||
#velocity = DataHandler.initial_velocity()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("eject"):
|
||||
_handle_eject()
|
||||
|
||||
var move_stick: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
if DataHandler.has_fuel() and move_stick:
|
||||
var new_velocity := velocity.lerp(move_stick * delta * DataHandler.get_speed(), DataHandler.get_maneuverability())
|
||||
var velocity_change := velocity - new_velocity
|
||||
velocity = new_velocity
|
||||
DataHandler.add_fuel(velocity_change.length() / -5.0, true)
|
||||
rotation = velocity.angle()
|
||||
_set_particles(velocity_change.length())
|
||||
else:
|
||||
_stop_particles()
|
||||
|
||||
var collisions := move_and_slide()
|
||||
if collisions:
|
||||
for i in get_slide_collision_count():
|
||||
var collision := get_slide_collision(i)
|
||||
var collider := collision.get_collider()
|
||||
if collider.is_in_group("pickups"):
|
||||
collider.pickup(self)
|
||||
else:
|
||||
if DataHandler.has_fuel():
|
||||
DataHandler.add_fuel(-5 * delta)
|
||||
else:
|
||||
_handle_eject()
|
||||
|
||||
|
||||
#fuel -= velocity.length() / 900.0
|
||||
|
||||
func _stop_particles() -> void:
|
||||
gpu_particles_2d_bottom.emitting = false
|
||||
gpu_particles_2d_middle.emitting = false
|
||||
gpu_particles_2d_top.emitting = false
|
||||
|
||||
func _set_particles(intensity: float) -> void:
|
||||
gpu_particles_2d_bottom.emitting = true
|
||||
gpu_particles_2d_middle.emitting = true
|
||||
gpu_particles_2d_top.emitting = true
|
||||
|
||||
gpu_particles_2d_bottom.lifetime = 5.0 * intensity
|
||||
gpu_particles_2d_middle.lifetime = 6.0 * intensity
|
||||
gpu_particles_2d_top.lifetime = 5.0 * intensity
|
||||
|
||||
func _handle_eject() -> void:
|
||||
if not is_ejecting:
|
||||
is_ejecting = true
|
||||
if DataHandler.has_fuel_needed_for_eject():
|
||||
DataHandler.move_cargo_to_inventory()
|
||||
else:
|
||||
var eject_percent = DataHandler.eject_fuel_percentage()
|
||||
var pod_position = position * (1 - eject_percent)
|
||||
DataHandler.create_cargo_pod(pod_position)
|
||||
|
||||
DataHandler.save_game_data()
|
||||
get_tree().change_scene_to_file("res://scenes/launch_menu.tscn")
|
||||
15
scripts/rocket_texture.gd
Normal file
15
scripts/rocket_texture.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends CanvasItem
|
||||
class_name RocketTexture
|
||||
|
||||
@export var cockpit_tex: Texture
|
||||
@export var engine_tex: Texture
|
||||
|
||||
func _draw():
|
||||
cockpit_tex.draw()
|
||||
engine_tex.draw()
|
||||
|
||||
func _get_height():
|
||||
return cockpit_tex.get_height()
|
||||
|
||||
func _get_width():
|
||||
return cockpit_tex.get_width() + engine_tex.get_width()
|
||||
9
scripts/space_pod.gd
Normal file
9
scripts/space_pod.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends Pickup
|
||||
class_name SpacePod
|
||||
|
||||
var pod_data: FloatingPodData
|
||||
|
||||
func pickup(rocket: Rocket):
|
||||
if not is_queued_for_deletion():
|
||||
DataHandler.retrive_pod(pod_data)
|
||||
super(rocket)
|
||||
7
scripts/star_fragment.gd
Normal file
7
scripts/star_fragment.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Pickup
|
||||
class_name StarFragment
|
||||
|
||||
func pickup(rocket: Rocket):
|
||||
if not is_queued_for_deletion():
|
||||
DataHandler.pickup("star")
|
||||
super(rocket)
|
||||
19
scripts/upgrades/engine_maneuverability_upgrade.gd
Normal file
19
scripts/upgrades/engine_maneuverability_upgrade.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Upgrade
|
||||
class_name EngineManeuverabilityUpgrade
|
||||
|
||||
@export var modifier := 1.8
|
||||
|
||||
func _init(tier: int = 1):
|
||||
if tier < 5:
|
||||
unlocks.append(EngineManeuverabilityUpgrade.new(tier + 1))
|
||||
self.tier = tier
|
||||
name = "Engine Maneuverability Increase - Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Increases the turning speed of your rocket"
|
||||
cost = {
|
||||
"star": (tier) * 15 - 5
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
DataHandler.game_data.engine_maneuverability_modifier *= modifier
|
||||
return true
|
||||
20
scripts/upgrades/engine_speed_upgrade.gd
Normal file
20
scripts/upgrades/engine_speed_upgrade.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends Upgrade
|
||||
class_name EngineSpeedUpgrade
|
||||
|
||||
@export var modifier := 1.2
|
||||
|
||||
func _init(tier: int = 1):
|
||||
if tier < 5:
|
||||
unlocks.append(EngineSpeedUpgrade.new(tier + 1))
|
||||
self.tier = tier
|
||||
name = "Engine Speed Increase - Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Increases the top speed of your rocket"
|
||||
cost = {
|
||||
"fuel": (tier) * 10 - 5,
|
||||
"star": tier * 5 + 10
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
DataHandler.game_data.engine_speed_modifier *= modifier
|
||||
return true
|
||||
8
scripts/upgrades/first_upgrade.gd
Normal file
8
scripts/upgrades/first_upgrade.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
extends Upgrade
|
||||
class_name FirstUpgrade
|
||||
|
||||
func _init():
|
||||
name = "First Upgrade"
|
||||
description = "Buy this upgrade to unlock the six initial upgrades"
|
||||
cost = {}
|
||||
unlocks = [StandardCockpitUpgrade.new(), StandardEngineUpgrade.new(), FuelEfficiencyUpgrade.new(), FuelCapacityUpgrade.new(), EngineSpeedUpgrade.new(), EngineManeuverabilityUpgrade.new()]
|
||||
19
scripts/upgrades/fuel_capacity_upgrade.gd
Normal file
19
scripts/upgrades/fuel_capacity_upgrade.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Upgrade
|
||||
class_name FuelCapacityUpgrade
|
||||
|
||||
@export var size_increase := 40
|
||||
|
||||
func _init(tier: int = 1):
|
||||
if tier < 5:
|
||||
unlocks.append(FuelCapacityUpgrade.new(tier + 1))
|
||||
self.tier = tier
|
||||
name = "Fuel Capacity Increase - Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Increases the maximum amount of fuel your rocket can hold"
|
||||
cost = {
|
||||
"fuel": (tier) * 20 - 5
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
DataHandler.game_data.fuel_max += size_increase
|
||||
return true
|
||||
20
scripts/upgrades/fuel_efficiency_upgrade.gd
Normal file
20
scripts/upgrades/fuel_efficiency_upgrade.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends Upgrade
|
||||
class_name FuelEfficiencyUpgrade
|
||||
|
||||
@export var modifier := 0.95
|
||||
|
||||
func _init(tier: int = 1):
|
||||
if tier < 5:
|
||||
unlocks.append(FuelEfficiencyUpgrade.new(tier + 1))
|
||||
self.tier = tier
|
||||
name = "Fuel Efficiency Increase - Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Increases the efficiency of fuel use for your rocket"
|
||||
cost = {
|
||||
"fuel": (tier) * 15 - 5,
|
||||
"star": (tier) * 5 + 5
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
DataHandler.game_data.fuel_efficiency *= modifier
|
||||
return true
|
||||
25
scripts/upgrades/standard_cockpit_upgrade.gd
Normal file
25
scripts/upgrades/standard_cockpit_upgrade.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Upgrade
|
||||
class_name StandardCockpitUpgrade
|
||||
|
||||
var module: StandardCockpitModule
|
||||
|
||||
func _init(tier: int = 1, module: StandardCockpitModule = null):
|
||||
if module == null:
|
||||
self.module = StandardCockpitModule.new()
|
||||
else:
|
||||
self.module = module
|
||||
if tier < 5:
|
||||
unlocks.append(StandardCockpitUpgrade.new(tier + 1, module))
|
||||
self.tier = tier
|
||||
name = "Standard Cockpit Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Standard Cockpit with no specialties, no strengths, no weakness."
|
||||
cost = {
|
||||
"star": (tier - 1) * 10
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
if tier == 1:
|
||||
DataHandler.add_module(GameData.ModuleType.COCKPIT, module)
|
||||
module.tier = tier
|
||||
return true
|
||||
25
scripts/upgrades/standard_engine_upgrade.gd
Normal file
25
scripts/upgrades/standard_engine_upgrade.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Upgrade
|
||||
class_name StandardEngineUpgrade
|
||||
|
||||
var module: StandardEngineModule
|
||||
|
||||
func _init(tier: int = 1, module: StandardEngineModule = null):
|
||||
if module == null:
|
||||
self.module = StandardEngineModule.new()
|
||||
else:
|
||||
self.module = module
|
||||
if tier < 5:
|
||||
unlocks.append(StandardEngineUpgrade.new(tier + 1))
|
||||
self.tier = tier
|
||||
name = "Standard Engine Tier %s" % ['I','II','III','IV','V'][tier - 1]
|
||||
description = "Standard Engine with no specialties, all around engine"
|
||||
cost = {
|
||||
"star": (tier - 1) * 10
|
||||
}
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if not super(): return false
|
||||
if tier == 1:
|
||||
DataHandler.add_module(GameData.ModuleType.ENGINE, module)
|
||||
module.tier = tier
|
||||
return true
|
||||
17
scripts/upgrades/upgrade.gd
Normal file
17
scripts/upgrades/upgrade.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Resource
|
||||
class_name Upgrade
|
||||
|
||||
@export var name: String = "Base Upgrade"
|
||||
@export var description: String = "Base Description"
|
||||
@export var unlocks: Array[Upgrade]
|
||||
@export var cost: Dictionary = {
|
||||
"star": 1
|
||||
}
|
||||
@export var purchased: bool = false
|
||||
@export var tier: int = -1
|
||||
|
||||
func activate_upgrade() -> bool:
|
||||
if DataHandler.has_upgrade_cost(self): return false
|
||||
purchased = true
|
||||
DataHandler.game_data.upgrades.append_array(unlocks)
|
||||
return true
|
||||
43
scripts/upgrades_menu.gd
Normal file
43
scripts/upgrades_menu.gd
Normal file
@@ -0,0 +1,43 @@
|
||||
extends Control
|
||||
|
||||
const COST_CONTAINER = preload("res://scenes/cost_container.tscn")
|
||||
|
||||
@onready var upgrades_list = %UpgradesList
|
||||
@onready var upgrade_title_label = %UpgradeTitleLabel
|
||||
@onready var desciption_label = %DesciptionLabel
|
||||
@onready var cost_container = %CostContainer
|
||||
@onready var buy_button = %BuyButton
|
||||
|
||||
var available_upgrades: Array[Upgrade]
|
||||
|
||||
func _ready():
|
||||
upgrade_title_label.text = "<- Select an Upgrade"
|
||||
desciption_label.text = ""
|
||||
for child in cost_container.get_children():
|
||||
cost_container.remove_child(child)
|
||||
buy_button.disabled = true
|
||||
upgrades_list.clear()
|
||||
available_upgrades = DataHandler.get_available_upgrades()
|
||||
for upgd in available_upgrades:
|
||||
upgrades_list.add_item(upgd.name)
|
||||
|
||||
|
||||
func _on_upgrades_list_item_selected(index):
|
||||
var upgd: Upgrade = available_upgrades[index]
|
||||
upgrade_title_label.text = upgd.name
|
||||
desciption_label.text = upgd.description
|
||||
for child in cost_container.get_children():
|
||||
cost_container.remove_child(child)
|
||||
for cost in upgd.cost:
|
||||
var cost_row: CostContainer = COST_CONTAINER.instantiate()
|
||||
cost_container.add_child(cost_row)
|
||||
cost_row.set_data(DataHandler.type_to_texture(cost), upgd.cost[cost])
|
||||
if DataHandler.has_upgrade_cost(upgd):
|
||||
buy_button.disabled = false
|
||||
|
||||
|
||||
func _on_buy_button_pressed():
|
||||
var selected = upgrades_list.get_selected_items()[0]
|
||||
var upgd: Upgrade = available_upgrades[selected]
|
||||
if upgd.activate_upgrade():
|
||||
_ready()
|
||||
Reference in New Issue
Block a user