Equipment menu

This commit is contained in:
gotfishmakesticks 2024-01-13 10:58:44 +03:00
commit bef15301cb
28 changed files with 809 additions and 48 deletions

View file

@ -10,6 +10,15 @@ var want_to_buy : Array[Item] = []
var sell_prices : Array[float] = []
var buy_prices : Array[float] = []
var available_hulls : Array[String] = []
var available_engines : Array[String] = []
var available_shields : Array[String] = []
var available_weapons : Array[String] = []
var hulls_prices : Dictionary
var engines_prices : Dictionary
var shields_prices : Dictionary
var weapons_prices : Dictionary
var quest : Quest = Quest.new()
const available_quests : Array[Quest.TYPE]= [Quest.TYPE.ELIMINATION, Quest.TYPE.DELIVERY]
const restrictions_foreach_type : Dictionary = {
@ -18,6 +27,7 @@ const restrictions_foreach_type : Dictionary = {
}
func _ready():
fetch_modules()
randomize()
ship.minimap.add_marker(self, "base")
match type:
@ -57,16 +67,32 @@ func update_prices():
var price : float
for item in want_to_sell:
if type != Game.BASE_TYPE.TRADING:
price = randi_range(item.min_price, item.max_price * 100) / 100.0
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
else:
price = randi_range((item.max_price + item.min_price) / 2 * 100, item.max_price * 100) / 100.0
sell_prices.append(price)
for item in want_to_buy:
if type != Game.BASE_TYPE.TRADING:
price = randi_range(item.min_price, item.max_price * 100) / 100.0
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
else:
price = randi_range(item.min_price * 100, (item.max_price + item.min_price) / 2 * 100) / 100.0
buy_prices.append(price)
for hull in available_hulls:
var item = Game.get_item(hull)
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
hulls_prices[hull] = price
for engine in available_engines:
var item = Game.get_item(engine)
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
engines_prices[engine] = price
for shield in available_shields:
var item = Game.get_item(shield)
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
shields_prices[shield] = price
for weapon in available_weapons:
var item = Game.get_item(weapon)
price = randi_range(item.min_price * 100, item.max_price * 100) / 100.0
weapons_prices[weapon] = price
func generate_quest():
var difficulty : float = randi_range(100, 300) / 100.0
@ -98,3 +124,33 @@ func generate_quest():
reward_multiplier += 0.5
reward_money *= reward_multiplier
quest.create(quest_type, progress_max, reward_money, restrictions, data)
## Loads all available modules in memory
func fetch_modules():
available_hulls.clear()
var dir = DirAccess.open("res://scenes/hulls")
var modules = dir.get_files()
available_hulls = check_for_item(modules)
available_engines.clear()
dir = DirAccess.open("res://scenes/engines")
modules = dir.get_files()
available_engines = check_for_item(modules)
available_shields.clear()
dir = DirAccess.open("res://scenes/shields")
modules = dir.get_files()
available_shields = check_for_item(modules)
available_weapons.clear()
dir = DirAccess.open("res://scenes/weapons/presets")
modules = dir.get_files()
available_weapons = check_for_item(modules)
func check_for_item(modules : Array[String]) -> Array[String]:
var returnable : Array[String] = []
for module in modules:
var itm = module.trim_suffix(".tscn")
if Game.get_item(itm).name != Game.DEFAULT_ITEM.name:
returnable.append(itm)
return returnable

View file

@ -5,6 +5,7 @@ class_name Hull
@export var max_hp : float = 30
@export var max_fuel : float = 1000
@export var max_weight : float = 100
@export var id : String = "starterhull"
@onready var hp : float = max_hp
@onready var fuel : float = max_fuel

View file

@ -17,6 +17,11 @@ var money : float = 1000
var quest : Quest = Quest.new()
var quest_completed : bool = false
var hulls : Array[String] = ["starterhull"]
var engines : Array[String] = ["starterengine"]
var shields : Array[String] = ["startershield"]
var weapons : Array[String] = ["SingleLaserMk1"]
signal destroyed
func _ready():
@ -24,9 +29,6 @@ func _ready():
quest.quest_ended.connect(kill_quest)
quest.quest_failed.connect(kill_quest)
destroyed.connect(quest._restriction_no_deaths)
secondary_slot.add_child(Game.get_weapon("SingleRocketMk1").instantiate())
#quest.create(Quest.TYPE.ELIMINATION, 2, 200)
func _process(_delta):
@ -64,3 +66,40 @@ func enemy_destroyed(_enemy):
return
if quest.type == quest.TYPE.ELIMINATION:
quest.do_progress()
func change_hull(new):
var new_hull = Game.get_module(new, 'hull').instantiate()
var old_hull = hull
add_child(new_hull)
hull = new_hull
hull.hp = old_hull.hp
hull.fuel = old_hull.fuel
get_tree().create_timer(0.05).timeout.connect(old_hull.queue_free)
func change_engine(new):
var new_engine = Game.get_module(new, 'engine').instantiate()
var old_engine = engine
add_child(new_engine)
engine = new_engine
get_tree().create_timer(0.05).timeout.connect(old_engine.queue_free)
func change_shield(new):
var new_shield = Game.get_module(new, 'shield').instantiate()
var old_shield = shield
add_child(shield)
shield = new_shield
get_tree().create_timer(0.05).timeout.connect(old_shield.queue_free)
func change_primary_weapon(new):
var weapon = Game.get_weapon(new).instantiate()
if primary_slot.get_child_count() > 0:
for child in primary_slot.get_children():
child.queue_free()
primary_slot.add_child(weapon)
func change_secondary_weapon(new):
var weapon = Game.get_weapon(new).instantiate()
if secondary_slot.get_child_count() > 0:
for child in secondary_slot.get_children():
child.queue_free()
secondary_slot.add_child(weapon)

View file

@ -7,6 +7,7 @@ class_name Shield
@export var recharge_timer : Timer
@export var laser_timer : Timer
@export var laser_charge_rate : float = 20
@export var id : String = "startershield"
@onready var ship = get_parent()
@onready var capacity : float = max_capacity
var can_recharge : bool = false

View file

@ -7,17 +7,28 @@ class_name ShipEngine
@export var acceleration : float = 50
@export var fuel_consumption : float = 100
@export var rotation_speed : int = 90
@export var id : String = "starterengine"
@onready var ship = get_parent()
@onready var hull = $"../Hull"
var hull
var speed = 0
var min_speed = max_speed / -4
var turbo_enabled = false
var alternative_movement = false
var destination_angle : float
var destination_difference : float
var rdy = false
func _ready():
get_tree().create_timer(0.05).timeout.connect(is_rdy)
func is_rdy():
rdy = true
hull = ship.hull
func _physics_process(delta):
if !rdy:
return
hull = ship.hull
var turbo_input = Input.get_action_raw_strength("turbo")
var acceleration_input = Input.get_axis("deccelerate", "accelerate") if ship is MainShip else 1.0
var rotation_input = Input.get_axis("rotateleft","rotateright")

View file

@ -9,7 +9,7 @@ class_name Weapon
@export var shoot_timer : Timer
@export var shoot_action : String = ""
@export var spawner_points : Array[Node2D]
var id : String = "SingleLaserMk1"
@export var id : String = "SingleLaserMk1"
@onready var ship = $"../.."
@onready var slot = $".."