New items + base typing + price generation + new menu template

This commit is contained in:
gotfishmakesticks 2023-11-13 13:38:43 +03:00
commit 50be4a0bb2
20 changed files with 408 additions and 37 deletions

12
items/energy_cell.tres Normal file
View file

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="Item" load_steps=2 format=3 uid="uid://16xqvcrmuga6"]
[ext_resource type="Script" path="res://scripts/item.gd" id="1_wdaj0"]
[resource]
script = ExtResource("1_wdaj0")
name = "Energy Cell"
description = ""
min_price = 1.0
max_price = 20.0
weight = 1.0
type = 0

12
items/food_supplies.tres Normal file
View file

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="Item" load_steps=2 format=3 uid="uid://ca8cpmd1aluut"]
[ext_resource type="Script" path="res://scripts/item.gd" id="1_gmqal"]
[resource]
script = ExtResource("1_gmqal")
name = "Food Supplies"
description = ""
min_price = 10.0
max_price = 100.0
weight = 10.0
type = 0

12
items/raw_materials.tres Normal file
View file

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="Item" load_steps=2 format=3 uid="uid://dlnl6w416qylo"]
[ext_resource type="Script" path="res://scripts/item.gd" id="1_l7wcw"]
[resource]
script = ExtResource("1_l7wcw")
name = "Raw Materials"
description = ""
min_price = 10.0
max_price = 50.0
weight = 5.0
type = 0

View file

@ -10,7 +10,7 @@ name = "Test Item"
description = "This is an debug item"
min_price = 10.0
max_price = 100.0
stack_size = 5
weight = 10.0
icon = ExtResource("1_e5k7o")
image = ExtResource("2_l1qse")
type = 0

12
items/water_barrel.tres Normal file
View file

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="Item" load_steps=2 format=3 uid="uid://b4jy8uknltolk"]
[ext_resource type="Script" path="res://scripts/item.gd" id="1_w7v0g"]
[resource]
script = ExtResource("1_w7v0g")
name = "Water Barrel"
description = ""
min_price = 5.0
max_price = 30.0
weight = 10.0
type = 0

View file

@ -1,24 +1,24 @@
[gd_scene load_steps=7 format=3 uid="uid://dbtrc26016xov"]
[ext_resource type="Texture2D" uid="uid://deabc107bimdb" path="res://sprites/space station 1.png" id="1_3ssyj"]
[ext_resource type="Script" path="res://scripts/misc/StarterBase.gd" id="1_5xhqy"]
[ext_resource type="Script" path="res://scripts/misc/BaseCollider.gd" id="2_18w83"]
[ext_resource type="Script" path="res://scripts/misc/StarterBaseMenu.gd" id="2_53766"]
[ext_resource type="PackedScene" uid="uid://dj8iw5305ujrc" path="res://scenes/menus/StarterBaseMenu.tscn" id="4_jlcsy"]
[ext_resource type="Script" path="res://scripts/misc/BaseNPCRotator.gd" id="5_kecih"]
[ext_resource type="Script" path="res://scripts/objects/Base.gd" id="1_bmrsb"]
[ext_resource type="Texture2D" uid="uid://deabc107bimdb" path="res://sprites/space station 1.png" id="2_tvpq1"]
[ext_resource type="Script" path="res://scripts/misc/BaseCollider.gd" id="3_vluwu"]
[ext_resource type="Script" path="res://scripts/misc/BaseMenuOpen.gd" id="4_ftno6"]
[ext_resource type="PackedScene" uid="uid://bdwk0dqcx0xhp" path="res://scenes/menus/BaseMenu.tscn" id="5_mhbys"]
[ext_resource type="Script" path="res://scripts/misc/BaseNPCRotator.gd" id="6_qn4dn"]
[node name="StarterBase" type="Node2D"]
[node name="Base" type="Node2D"]
process_mode = 1
script = ExtResource("1_5xhqy")
script = ExtResource("1_bmrsb")
[node name="Sprite" type="Sprite2D" parent="."]
rotation = -1.5708
texture = ExtResource("1_3ssyj")
texture = ExtResource("2_tvpq1")
[node name="BaseCollider" type="StaticBody2D" parent="."]
collision_layer = 2
collision_mask = 5
script = ExtResource("2_18w83")
script = ExtResource("3_vluwu")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BaseCollider"]
polygon = PackedVector2Array(129, -32, 129, 32, 256, 63, 225, 192, 192, 225, 67, 256, -67, 256, -192, 225, -225, 192, -256, 67, -256, -67, -225, -192, -192, -225, -67, -256, 67, -256, 192, -225, 225, -192, 256, -67, 256, -63)
@ -31,8 +31,8 @@ polygon = PackedVector2Array(129, -32, 129, 32, 256, 63, 256, 61, 131, 30, 131,
[node name="MenuCollider" type="Area2D" parent="."]
collision_layer = 8
script = ExtResource("2_53766")
menu = ExtResource("4_jlcsy")
script = ExtResource("4_ftno6")
menu = ExtResource("5_mhbys")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="MenuCollider"]
polygon = PackedVector2Array(129, 32, 256, 63, 256, -63, 129, -32)
@ -46,7 +46,7 @@ polygon = PackedVector2Array(129, 32, 256, 63, 256, -63, 129, -32)
[node name="NPCRotator" type="Area2D" parent="."]
collision_layer = 16
monitorable = false
script = ExtResource("5_kecih")
script = ExtResource("6_qn4dn")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="NPCRotator"]
polygon = PackedVector2Array(129, -32, 129, 32, 257, 63, 226, 193, 192, 226, 67, 257, -67, 257, -193, 226, -226, 193, -257, 67, -257, -67, -226, -193, -193, -226, -67, -257, 67, -257, 193, -226, 226, -193, 257, -67, 257, -63)

View file

@ -4,7 +4,7 @@
[ext_resource type="Script" path="res://scripts/Space.gd" id="1_ppaw3"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/StarsController.tscn" id="3_jbyyq"]
[ext_resource type="Script" path="res://scripts/misc/ProjectilesContainer.gd" id="4_dtv2c"]
[ext_resource type="PackedScene" uid="uid://dbtrc26016xov" path="res://scenes/StarterBase.tscn" id="5_bjt5p"]
[ext_resource type="PackedScene" uid="uid://dbtrc26016xov" path="res://scenes/Base.tscn" id="5_bjt5p"]
[ext_resource type="PackedScene" uid="uid://523dme3h6d6c" path="res://scenes/npcships/NPCShipDefault.tscn" id="6_67746"]
[ext_resource type="Script" path="res://scripts/misc/FactionRecoloring.gd" id="7_w8i61"]
[ext_resource type="Shader" uid="uid://f6lhks6rp5jw" path="res://testicles.tres" id="9_h8ucp"]
@ -37,13 +37,10 @@ script = ExtResource("1_ppaw3")
process_mode = 1
script = ExtResource("4_dtv2c")
[node name="StarterBase" parent="." instance=ExtResource("5_bjt5p")]
position = Vector2(208, 5)
rotation = -3.14159
[node name="EnemyFaction" type="Node2D" parent="."]
process_mode = 1
script = ExtResource("7_w8i61")
faction = true
[node name="DefaultShip" parent="EnemyFaction" instance=ExtResource("6_67746")]
position = Vector2(-600, 930)
@ -88,3 +85,25 @@ offset_left = -4096.0
offset_top = -4096.0
offset_right = 4096.0
offset_bottom = 4096.0
[node name="Bases" type="Node2D" parent="."]
script = ExtResource("7_w8i61")
[node name="Base" parent="Bases" instance=ExtResource("5_bjt5p")]
position = Vector2(-434, -343)
rotation = 0.660397
[node name="Base2" parent="Bases" instance=ExtResource("5_bjt5p")]
position = Vector2(429, -368)
rotation = 2.41284
type = 1
[node name="Base3" parent="Bases" instance=ExtResource("5_bjt5p")]
position = Vector2(-428, 418)
rotation = -0.826175
type = 3
[node name="Base4" parent="Bases" instance=ExtResource("5_bjt5p")]
position = Vector2(386, 432)
rotation = -2.31102
type = 2

203
scenes/menus/BaseMenu.tscn Normal file
View file

@ -0,0 +1,203 @@
[gd_scene load_steps=4 format=3 uid="uid://bdwk0dqcx0xhp"]
[ext_resource type="Texture2D" uid="uid://db4euprxhape0" path="res://sprites/9s.png" id="1_vb0tn"]
[ext_resource type="Script" path="res://scripts/menu/CloseMenuButton.gd" id="2_ld3o5"]
[ext_resource type="Script" path="res://scripts/menu/OpenMenuButton.gd" id="3_63o1s"]
[node name="BaseMenu" type="Control"]
process_mode = 1
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MainMenu" type="NinePatchRect" parent="."]
layout_mode = 0
offset_left = 320.0
offset_top = 40.0
offset_right = 960.0
offset_bottom = 680.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="MainMenu"]
layout_mode = 0
offset_right = 640.0
offset_bottom = 64.0
text = "{BaseType} Station"
horizontal_alignment = 1
vertical_alignment = 1
[node name="TradingMenuGoto" type="Button" parent="MainMenu"]
layout_mode = 0
offset_left = 1.0
offset_top = 64.0
offset_right = 639.0
offset_bottom = 192.0
text = "Buy / Sell goods"
script = ExtResource("3_63o1s")
[node name="QuestMenuGoto" type="Button" parent="MainMenu"]
layout_mode = 0
offset_left = 1.0
offset_top = 192.0
offset_right = 639.0
offset_bottom = 320.0
text = "Take / Pass the quest"
script = ExtResource("3_63o1s")
[node name="EquipmentMenuGoto" type="Button" parent="MainMenu"]
layout_mode = 0
offset_left = 1.0
offset_top = 320.0
offset_right = 639.0
offset_bottom = 448.0
text = "Change your equipment"
script = ExtResource("3_63o1s")
[node name="InfoMenuGoto" type="Button" parent="MainMenu"]
layout_mode = 0
offset_left = 1.0
offset_top = 448.0
offset_right = 639.0
offset_bottom = 576.0
text = "About this station"
script = ExtResource("3_63o1s")
[node name="Footer" type="Label" parent="MainMenu"]
offset_top = 576.0
offset_right = 640.0
offset_bottom = 640.0
text = "Fly off base to exit this menu."
horizontal_alignment = 1
vertical_alignment = 1
[node name="TradingMenu" type="NinePatchRect" parent="."]
visible = false
layout_mode = 0
offset_left = 320.0
offset_top = 40.0
offset_right = 960.0
offset_bottom = 680.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="TradingMenu"]
layout_mode = 0
offset_right = 640.0
offset_bottom = 64.0
text = "Trading Menu"
horizontal_alignment = 1
vertical_alignment = 1
[node name="CloseButton" type="Button" parent="TradingMenu"]
layout_mode = 0
offset_left = 600.0
offset_top = 1.0
offset_right = 639.0
offset_bottom = 40.0
text = "X"
script = ExtResource("2_ld3o5")
[node name="QuestMenu" type="NinePatchRect" parent="."]
visible = false
layout_mode = 0
offset_left = 320.0
offset_top = 40.0
offset_right = 960.0
offset_bottom = 680.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="QuestMenu"]
layout_mode = 0
offset_right = 640.0
offset_bottom = 64.0
text = "Quest Menu"
horizontal_alignment = 1
vertical_alignment = 1
[node name="CloseButton" type="Button" parent="QuestMenu"]
layout_mode = 0
offset_left = 600.0
offset_top = 1.0
offset_right = 639.0
offset_bottom = 40.0
text = "X"
script = ExtResource("2_ld3o5")
[node name="EquipmentMenu" type="NinePatchRect" parent="."]
visible = false
layout_mode = 0
offset_left = 320.0
offset_top = 40.0
offset_right = 960.0
offset_bottom = 680.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="EquipmentMenu"]
layout_mode = 0
offset_right = 640.0
offset_bottom = 64.0
text = "Equipment Menu"
horizontal_alignment = 1
vertical_alignment = 1
[node name="CloseButton" type="Button" parent="EquipmentMenu"]
layout_mode = 0
offset_left = 600.0
offset_top = 1.0
offset_right = 639.0
offset_bottom = 40.0
text = "X"
script = ExtResource("2_ld3o5")
[node name="InfoMenu" type="NinePatchRect" parent="."]
visible = false
layout_mode = 0
offset_left = 320.0
offset_top = 40.0
offset_right = 960.0
offset_bottom = 680.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="InfoMenu"]
layout_mode = 0
offset_right = 640.0
offset_bottom = 64.0
text = "Information Menu"
horizontal_alignment = 1
vertical_alignment = 1
[node name="CloseButton" type="Button" parent="InfoMenu"]
layout_mode = 0
offset_left = 600.0
offset_top = 1.0
offset_right = 639.0
offset_bottom = 40.0
text = "X"
script = ExtResource("2_ld3o5")

View file

@ -13,7 +13,7 @@ var color_enemy
@export var map_width = 8192
@export var map_height = 8192
@onready var ship = $MainShip
@onready var base = $StarterBase
@onready var bases = $Bases
@onready var enemy_faction = $EnemyFaction
func _ready():
@ -63,22 +63,29 @@ func _process(_delta):
pause()
func pause():
var menu = get_node_or_null("MainShip/GUI/BaseMenu")
if menu != null:
menu.visible = false
get_tree().paused = true
ship.pause_controller.visible = true
func unpause():
get_tree().paused = false
ship.pause_controller.visible = false
var menu = get_node_or_null("MainShip/GUI/BaseMenu")
if menu != null:
menu.visible = true
func recolor():
color_player = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
color_base = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
color_enemy = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
ship.modulate = color_player
base.modulate = color_base
bases.modulate = color_base
enemy_faction.modulate = color_enemy
enemy_faction.changeitemscolor()
bases.changeitemscolor()
ship.changeinterfacecolor()
var menu = get_node_or_null("MainShip/GUI/StarterBaseMenu")
if menu != null:
menu.modulate = base.modulate
menu.modulate = bases.modulate

View file

@ -4,6 +4,7 @@ class_name Game
enum ITEM_TYPE {VALUABLE, WEAPON, MODULE, AMMUNITION}
enum AMMO_TYPE {NULL, LASER_ENERGY, ROCKETS}
enum BASE_TYPE {POWER, MINING, FOOD, TRADING, MODULE}
const DEFAULT_ITEM = preload("res://items/test_item.tres")
const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")

View file

@ -6,7 +6,7 @@ class_name Item
@export var description : String
@export var min_price : float
@export var max_price : float
@export var stack_size : int
@export var weight : float
@export var icon : Texture
@export var image : Texture
@export var type : Game.ITEM_TYPE

3
scripts/menu/BaseMenu.gd Normal file
View file

@ -0,0 +1,3 @@
extends Control
var base

View file

@ -0,0 +1,10 @@
extends BaseButton
@onready var main_menu = $"../../MainMenu"
func _ready():
button_up.connect(close)
func close():
get_parent().visible = false
main_menu.visible = true

View file

@ -19,7 +19,8 @@ func _ready():
change_menu(0)
else:
change_menu(5)
profile_status.text = "Current profile: [{profile}]".format({"profile": Game.profile.profile_meta['meta']['profile_name']})
var format = {"profile": Game.profile.profile_meta['meta']['profile_name']}
profile_status.text = "Current profile: [{profile}]".format(format)
func change_menu(id):
input.visible = false

View file

@ -0,0 +1,23 @@
extends BaseButton
@onready var trading_menu = $"../../TradingMenu"
@onready var quest_menu = $"../../QuestMenu"
@onready var equipment_menu = $"../../EquipmentMenu"
@onready var info_menu = $"../../InfoMenu"
func _ready():
button_up.connect(open)
func open():
var menu
match name:
"TradingMenuGoto":
menu = trading_menu
"QuestMenuGoto":
menu = quest_menu
"EquipmentMenuGoto":
menu = equipment_menu
"InfoMenuGoto":
menu = info_menu
menu.visible = true
get_parent().visible = false

View file

@ -15,6 +15,7 @@ func _on_body_entered(body):
menu_inst = menu.instantiate()
body.find_child("GUI").add_child(menu_inst)
menu_inst.modulate = get_parent().modulate
menu_inst.base = get_parent()
func _on_body_exited(body):
if body is MainShip:

View file

@ -1,8 +1,11 @@
extends Node2D
@export var faction : bool
func changeitemscolor():
var items = get_children()
var ship = get_tree().current_scene.get_node("MainShip")
var ship = get_tree().current_scene.ship
for item in items:
item.modulate = modulate
if faction:
ship.minimap.add_marker(item, "hostile")

View file

@ -1,7 +0,0 @@
extends Node2D
@onready var menu = $MenuCollider
@onready var ship = get_tree().current_scene.get_node("MainShip")
func _ready():
ship.minimap.add_marker(self, "base")

55
scripts/objects/Base.gd Normal file
View file

@ -0,0 +1,55 @@
extends Node2D
@export var type : Game.BASE_TYPE
@onready var menu : Area2D = $MenuCollider
@onready var ship : MainShip = get_tree().current_scene.get_node("MainShip")
var want_to_sell : Array[Item] = []
var want_to_buy : Array[Item] = []
var sell_prices : Array[float] = []
var buy_prices : Array[float] = []
func _ready():
ship.minimap.add_marker(self, "base")
match type:
Game.BASE_TYPE.POWER:
want_to_sell.append(Game.get_item("Energy Cell"))
want_to_buy.append(Game.get_item("Raw Materials"))
want_to_buy.append(Game.get_item("Water Barrel"))
want_to_buy.append(Game.get_item("Food Supplies"))
Game.BASE_TYPE.MINING:
want_to_sell.append(Game.get_item("Raw Materials"))
want_to_sell.append(Game.get_item("Water Barrel"))
want_to_buy.append(Game.get_item("Energy Cell"))
want_to_buy.append(Game.get_item("Food Supplies"))
Game.BASE_TYPE.FOOD:
want_to_sell.append(Game.get_item("Food Supplies"))
want_to_buy.append(Game.get_item("Water Barrel"))
want_to_buy.append(Game.get_item("Energy Cell"))
want_to_buy.append(Game.get_item("Raw Materials"))
Game.BASE_TYPE.TRADING:
want_to_sell.append(Game.get_item("Food Supplies"))
want_to_sell.append(Game.get_item("Water Barrel"))
want_to_sell.append(Game.get_item("Energy Cell"))
want_to_sell.append(Game.get_item("Raw Materials"))
want_to_buy.append(Game.get_item("Food Supplies"))
want_to_buy.append(Game.get_item("Water Barrel"))
want_to_buy.append(Game.get_item("Energy Cell"))
want_to_buy.append(Game.get_item("Raw Materials"))
update_prices()
func update_prices():
sell_prices = []
buy_prices = []
var price : float
for item in want_to_sell:
price = randi_range(item.min_price * 100, item.max_price * 100) / 100
sell_prices.append(price)
for item in want_to_buy:
if type != Game.BASE_TYPE.TRADING:
price = randi_range((item.max_price + item.min_price) / 2 * 100, item.max_price * 100) / 100
else:
price = randi_range(item.min_price * 100, (item.max_price + item.min_price) / 2 * 100) / 100
buy_prices.append(price)
print(sell_prices, buy_prices)

View file

@ -2,12 +2,14 @@ extends Node2D
class_name Hull
@export var max_hp : int = 30
@export var max_fuel : int = 1000
@onready var hp = max_hp
@export var max_hp : float = 30
@export var max_fuel : float = 1000
@export var max_weight : float = 100
@onready var hp : float = max_hp
@onready var fuel : float = max_fuel
var weight : float = 0
var ammunition = {
"n/a" : 0,
"Laser Energy" : 100,
@ -19,3 +21,5 @@ var max_ammunition = {
"Laser Energy" : 100,
"Rockets" : 20
}
var cargo = {}