Rewriting ships: Added some player interface and started rewriting star system

This commit is contained in:
2ndbeam 2024-04-30 16:22:55 +03:00
commit 4172b336c1
20 changed files with 300 additions and 139 deletions

View file

@ -16,6 +16,11 @@ run/main_scene="res://scenes/MainMenu.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"
[debug]
gdscript/warnings/shadowed_variable=0
gdscript/warnings/integer_division=0
[display]
window/size/viewport_width=1280

View file

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://scripts/menu/MainMenu.gd" id="1_2wax0"]
[ext_resource type="Shader" uid="uid://f6lhks6rp5jw" path="res://shaders/testicles.tres" id="1_on8wy"]
[ext_resource type="Gradient" uid="uid://c6bcjydbwm5id" path="res://scenes/SpaceGradient.tres" id="2_7racd"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/StarsController.tscn" id="4_g7254"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/Star Systems/Required Scenes/StarsController.tscn" id="4_g7254"]
[ext_resource type="Script" path="res://scripts/menu/MainMenuButton.gd" id="5_q6x10"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_rtgkw"]

View file

@ -1,13 +1,156 @@
[gd_scene load_steps=4 format=3 uid="uid://dok3i8u5t1ka4"]
[gd_scene load_steps=12 format=3 uid="uid://dok3i8u5t1ka4"]
[ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"]
[ext_resource type="Script" path="res://scripts/Ship/player_ship.gd" id="2_oqdd7"]
[ext_resource type="Script" path="res://scripts/Ship/player_input_controller.gd" id="3_0e84a"]
[ext_resource type="PackedScene" uid="uid://ryy1tdrxmjav" path="res://scenes/Ships/Modules/Weapons/weapon.tscn" id="4_fy1be"]
[ext_resource type="Script" path="res://scripts/Ship/player_camera.gd" id="5_rclap"]
[sub_resource type="GDScript" id="GDScript_ry4sc"]
resource_name = "money_counter"
script/source = "extends Label
## Text with placeholder
@onready var unformatted_text: String = text
## Shortcut to get_parent().get_parent()
@onready var ship: PlayerShip = get_parent().get_parent()
func _process(_delta):
text = unformatted_text % ship.money
"
[sub_resource type="GDScript" id="GDScript_vko7a"]
resource_name = "velocity_counter"
script/source = "extends Label
## Text with placeholder
@onready var unformatted_text: String = text
## Shortcut to get_parent().get_parent()
@onready var ship: PlayerShip = get_parent().get_parent()
func _process(_delta):
text = unformatted_text % ship.hull.scalar_velocity
"
[sub_resource type="GDScript" id="GDScript_uoaip"]
resource_name = "health_counter"
script/source = "extends Label
## Text with placeholder
@onready var unformatted_text: String = text
## Shortcut to get_parent().get_parent()
@onready var ship: PlayerShip = get_parent().get_parent()
func _process(_delta):
text = unformatted_text.format([ship.hull.hp, ship.hull.max_hp])
"
[sub_resource type="GDScript" id="GDScript_q1sx2"]
resource_name = "shield_counter"
script/source = "extends Label
## Text with placeholder
@onready var unformatted_text: String = text
## Shortcut to get_parent().get_parent()
@onready var ship: PlayerShip = get_parent().get_parent()
func _process(_delta):
text = unformatted_text.format([ship.shield.capacity, ship.shield.max_capacity])
"
[sub_resource type="Theme" id="Theme_d8vjy"]
default_font_size = 48
[sub_resource type="GDScript" id="GDScript_6uw1d"]
resource_name = "pause_controller"
script/source = "extends Control
# TODO: implement save
## Resumes game
func _on_resume_button_up():
get_tree().current_scene.unpause()
## Saves profile and exits game
func _on_exit_button_up():
get_tree().current_scene.unpause()
get_tree().change_scene_to_file(\"res://scenes/MainMenu.tscn\")
#Game.profile_save(get_tree().current_scene)
"
[node name="PlayerShip" instance=ExtResource("1_6x7bu")]
script = ExtResource("2_oqdd7")
[node name="InputController" type="Node2D" parent="." index="0"]
script = ExtResource("3_0e84a")
[node name="Weapon" parent="Weapons" index="0" instance=ExtResource("4_fy1be")]
action_id = "primary"
[node name="ColorableGUI" type="CanvasLayer" parent="." index="5"]
[node name="Money" type="Label" parent="ColorableGUI" index="0"]
offset_left = 7.0
offset_top = 611.0
offset_right = 92.0
offset_bottom = 634.0
text = "Money: %d"
script = SubResource("GDScript_ry4sc")
[node name="Velocity" type="Label" parent="ColorableGUI" index="1"]
offset_left = 7.0
offset_top = 688.0
offset_right = 137.0
offset_bottom = 711.0
text = "Velocity: %d px/s"
script = SubResource("GDScript_vko7a")
[node name="Health" type="Label" parent="ColorableGUI" index="2"]
offset_left = 7.0
offset_top = 663.0
offset_right = 168.0
offset_bottom = 686.0
text = "Health: {0} / {1} units"
script = SubResource("GDScript_uoaip")
[node name="Shield" type="Label" parent="ColorableGUI" index="3"]
offset_left = 8.0
offset_top = 638.0
offset_right = 164.0
offset_bottom = 661.0
text = "Shield: {0} / {1} units"
script = SubResource("GDScript_q1sx2")
[node name="PauseController" type="Control" parent="ColorableGUI" index="4"]
process_mode = 2
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
theme = SubResource("Theme_d8vjy")
script = SubResource("GDScript_6uw1d")
[node name="Resume" type="Button" parent="ColorableGUI/PauseController" index="0"]
layout_mode = 0
offset_left = 444.0
offset_top = 254.0
offset_right = 779.0
offset_bottom = 329.0
text = "Resume game"
[node name="Exit" type="Button" parent="ColorableGUI/PauseController" index="1"]
layout_mode = 0
offset_left = 449.0
offset_top = 357.0
offset_right = 763.0
offset_bottom = 432.0
text = "Save and exit"
[node name="NonColorableGUI" type="CanvasLayer" parent="." index="6"]
[node name="Camera" type="Camera2D" parent="." index="7"]
zoom = Vector2(0.5, 0.5)
script = ExtResource("5_rclap")
[connection signal="button_up" from="ColorableGUI/PauseController/Resume" to="ColorableGUI/PauseController" method="_on_resume_button_up"]
[connection signal="button_up" from="ColorableGUI/PauseController/Exit" to="ColorableGUI/PauseController" method="_on_exit_button_up"]

View file

@ -1,8 +1,8 @@
[gd_scene load_steps=31 format=3 uid="uid://14k35mkjwi5i"]
[ext_resource type="PackedScene" uid="uid://ccrs28h3b2tfy" path="res://scenes/MainShip.tscn" id="1_6fvpc"]
[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/Spaceold.gd" id="1_ppaw3"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/Star Systems/Required 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/Base.tscn" id="5_bjt5p"]
[ext_resource type="PackedScene" uid="uid://523dme3h6d6c" path="res://scenes/npcships/NPCShipDefault.tscn" id="6_67746"]

View file

@ -1,13 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://dpggye27ln436"]
[ext_resource type="Script" path="res://scripts/misc/StarsGeneration.gd" id="1_rcdwc"]
[ext_resource type="Script" path="res://scripts/misc/stars_generator.gd" id="1_uxmpu"]
[ext_resource type="PackedScene" uid="uid://kyuhwil8vq7n" path="res://scenes/Star.tscn" id="2_ypr5c"]
[node name="Stars" type="ParallaxBackground"]
process_mode = 1
layer = -5
scroll_ignore_camera_zoom = true
script = ExtResource("1_rcdwc")
script = ExtResource("1_uxmpu")
star = ExtResource("2_ypr5c")
[node name="CloseStars" type="ParallaxLayer" parent="."]

View file

@ -0,0 +1,29 @@
[gd_scene load_steps=6 format=3 uid="uid://bsnrcw64qr2hr"]
[ext_resource type="Script" path="res://scripts/star_system.gd" id="1_xx8w2"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/Star Systems/Required Scenes/StarsController.tscn" id="2_iqrn0"]
[ext_resource type="Script" path="res://scripts/misc/ProjectilesContainer.gd" id="3_h5cm3"]
[ext_resource type="Material" uid="uid://bawhivm5cr2w" path="res://shaders/materials/nebula_shader.tres" id="4_o0ld7"]
[ext_resource type="Script" path="res://scripts/nebula.gd" id="5_la84n"]
[node name="StarSystem" type="Node"]
script = ExtResource("1_xx8w2")
width = 1280
height = 720
[node name="Stars" parent="." instance=ExtResource("2_iqrn0")]
[node name="ProjectileContainer" type="Node" parent="."]
script = ExtResource("3_h5cm3")
[node name="Background" type="CanvasLayer" parent="."]
[node name="Nebula" type="ColorRect" parent="Background"]
material = ExtResource("4_o0ld7")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("5_la84n")
color_background = Color(0.36, 0.18612, 0.1116, 1)

View file

@ -1,95 +1,11 @@
[gd_scene load_steps=6 format=3 uid="uid://ckdttdkoo1t0s"]
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="1_b1l1c"]
[ext_resource type="Script" path="res://scripts/star_system.gd" id="1_du5mm"]
[ext_resource type="Shader" path="res://shaders/ship.gdshader" id="2_15op6"]
[ext_resource type="Script" path="res://scripts/misc/ProjectilesContainer.gd" id="3_amh71"]
[sub_resource type="GDScript" id="GDScript_6w8qb"]
resource_name = "gogo"
script/source = "extends Node2D
@onready var items = $Items
@onready var verified = $\"Verified Items\"
# Called when the node enters the scene tree for the first time.
func _ready():
var dir = DirAccess.open(\"res://items\")
var files = dir.get_files()
var text = \"Items:\\n\"
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Hulls:\\n\"
dir = DirAccess.open(\"res://scenes/hulls\")
files = dir.get_files()
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Engines:\\n\"
dir = DirAccess.open(\"res://scenes/engines\")
files = dir.get_files()
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Shields:\\n\"
dir = DirAccess.open(\"res://scenes/shields\")
files = dir.get_files()
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Weapons:\\n\"
dir = DirAccess.open(\"res://scenes/weapons/presets\")
files = dir.get_files()
for file in files:
text += \"{file}\\n\".format({'file': file})
items.text = text
fetch_modules()
func fetch_modules():
var dir = DirAccess.open(\"res://items\")
var files = dir.get_files()
var text = \"Items:\\n\"
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Verified Hulls:\\n\"
dir = DirAccess.open(\"res://scenes/hulls\")
var modules = dir.get_files()
files = check_for_item(modules)
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Verified Engines:\\n\"
dir = DirAccess.open(\"res://scenes/engines\")
modules = dir.get_files()
files = check_for_item(modules)
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Verified Shields:\\n\"
dir = DirAccess.open(\"res://scenes/shields\")
modules = dir.get_files()
files = check_for_item(modules)
for file in files:
text += \"{file}\\n\".format({'file': file})
text += \"Verified Weapons:\\n\"
dir = DirAccess.open(\"res://scenes/weapons/presets\")
modules = dir.get_files()
files = check_for_item(modules)
for file in files:
text += \"{file}\\n\".format({'file': file})
verified.text = text
func check_for_item(modules : Array[String]) -> Array[String]:
var returnable : Array[String] = []
for module in modules:
var itm = module.split('.', true, 1)[0]
if Game.get_item(itm).name != Game.DEFAULT_ITEM.name:
returnable.append(itm)
return returnable
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_action_just_released(\"pause\"):
get_tree().change_scene_to_file(\"res://scenes/MainMenu.tscn\")
"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_m15k8"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ogy53"]
resource_local_to_scene = true
resource_name = "Shield Material"
shader = ExtResource("2_15op6")
@ -100,25 +16,10 @@ shader_parameter/max_distance = 20.0
shader_parameter/bublic_size = 20.0
[node name="Debug" type="Node2D"]
script = SubResource("GDScript_6w8qb")
[node name="Items" type="Label" parent="."]
offset_right = 640.0
offset_bottom = 720.0
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 2
[node name="Verified Items" type="Label" parent="."]
offset_left = 640.0
offset_right = 1280.0
offset_bottom = 720.0
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 2
script = ExtResource("1_du5mm")
[node name="PlayerShip" parent="." instance=ExtResource("1_b1l1c")]
material = SubResource("ShaderMaterial_m15k8")
material = SubResource("ShaderMaterial_ogy53")
position = Vector2(608, 352)
scale = Vector2(0.5, 0.5)

View file

@ -28,6 +28,9 @@ class_name Hull
else:
ship.destroyed.emit()
## Length of linear_velocity vector
var scalar_velocity: float = 0.0
## Adds amount to ammunition, returns true if it was successful
func add_ammunition(which: String, value: float) -> bool:
if ammunition[which] + value < 0:
@ -41,3 +44,4 @@ func add_ammunition(which: String, value: float) -> bool:
func _physics_process(_delta):
ship.position = position
ship.rotation = rotation
scalar_velocity = linear_velocity.length()

View file

@ -0,0 +1,16 @@
extends Camera2D
## Desired value of zoom
@export var normal_zoom: float = 0.4
## Value of hull's scalar_velocity where zoom will be equal to normal_zoom
@export var normal_zoom_velocity: float = 200.0
## Maximum value of zoom
@export var max_zoom: float = 0.5
## Shortcut to get_parent()
@onready var ship: PlayerShip = get_parent()
func _process(_delta):
var scalar_velocity = ship.hull.scalar_velocity
zoom = Vector2(1, 1) * normal_zoom * (normal_zoom_velocity / (scalar_velocity + 1))
if zoom.x > max_zoom:
zoom = Vector2(1, 1) * max_zoom

View file

@ -12,3 +12,4 @@ func _physics_process(_delta) -> void:
weapon.shoot_request = Input.get_action_strength("shootprimary")
"secondary":
weapon.shoot_request = Input.get_action_strength("shootsecondary")

View file

@ -0,0 +1,9 @@
extends Ship
class_name PlayerShip
## Player camera reference
@onready var camera = $Camera
## Currency variable
var money: float = 1000.0

View file

@ -2,8 +2,6 @@ extends Node2D
class_name Ship
# TODO: add weapons
## Emits when hull hp reaches zero.
signal destroyed
@ -15,24 +13,28 @@ signal destroyed
@onready var shield: Shield = $Shield
## Reference to weapons node
@onready var weapons: Node2D = $Weapons
## Node beginning position
@onready var spawn_position: Vector2 = global_position
## Faction which this ship belongs to
var faction : Game.Faction = Game.Faction.Player
func _ready() -> void:
hull.global_position += global_position
hull.global_position = global_position
destroyed.connect(destroy)
## Reset all required variables
func destroy() -> void:
hull.hp = hull.max_hp
hull.global_position = spawn_position
shield.capacity = shield.max_capacity
## Swaps old hull with the new one
func change_hull(new_hull_id: String) -> void:
var hull_holder: Node = hull.get_parent()
var new_hull: Hull = Game.get_module(new_hull_id, 'hull').instantiate()
var old_hull: Hull = hull
add_child(new_hull)
hull_holder.add_child(new_hull)
hull = new_hull
hull.hp = old_hull.hp
get_tree().create_timer(0.05).timeout.connect(old_hull.queue_free)

View file

@ -1,4 +1,4 @@
extends Node2D
extends Node
class_name ProjectileContainer
@ -6,3 +6,6 @@ static var instance : ProjectileContainer
func _ready():
instance = self
func _exit_tree():
instance = null

View file

@ -1,18 +0,0 @@
extends Node
@export var star : PackedScene
@export var stars_amount = 1000
@export var compress_space_amount = 0.5
func _ready():
var compress_multiplier = 1-compress_space_amount
var map_width_halved = get_tree().current_scene.map_width * compress_multiplier
var map_height_halved = get_tree().current_scene.map_height * compress_multiplier
for i in range(stars_amount):
var star_inst = star.instantiate()
var x = randi_range(-map_width_halved, map_width_halved)
var y = randi_range(-map_height_halved, map_height_halved)
var distance = randi_range(0,get_child_count()-1)
get_children()[distance].add_child(star_inst)
star_inst.position = Vector2(x, y)

View file

@ -0,0 +1,28 @@
extends Node
# TODO: this just doesn't work
## Star scene
@export var star : PackedScene
## Affects how many stars will be generated and places on whole system
@export var stars_amount = 1000
## Affects how much space on borders of the star system will be empty
@export_range(0, 1) var compress_space_amount = 0.1
## Shortcut to get_parent()
@onready var star_system: StarSystem = get_parent()
func _ready():
var compress_multiplier = 1.0 - compress_space_amount
var parallax_layers = get_children()
var width_halved = star_system.width / 2
var height_halved = star_system.height / 2
for i in range(stars_amount):
var star_inst = star.instantiate()
var x = randi_range(-width_halved, width_halved) * compress_multiplier
var y = randi_range(-height_halved, height_halved) * compress_multiplier
# Decides parallax layer which star belongs to
var distance = randi_range(0, get_child_count() - 1)
parallax_layers[distance].add_child(star_inst)
var position = Vector2(x, y)
star_inst.position = position
print(position)

View file

@ -1,11 +1,15 @@
extends ColorRect
@onready var ship = get_tree().current_scene.get_node("MainShip")
@onready var space = get_tree().current_scene
## Node which will change offset. If null, offset is constant
@export var tracked_node: Node2D
## Shortcut to get_parent()
@onready var star_system = get_parent()
## Color of nebula.
@export var color_background: Color
func _ready():
material.set_shader_parameter("nebula_color", color_background)
func _physics_process(_delta):
material.set_shader_parameter("offset",ship.global_position)
func _on_space_updated_colors():
material.set_shader_parameter("nebula_color",space.color_background)
if tracked_node != null:
material.set_shader_parameter("offset", tracked_node.global_position)

View file

@ -8,3 +8,4 @@ func _ready():
speed_scale = randf_range(0, 2)
var Colors = [Color.LIGHT_BLUE, Color.WHITE, Color.LIGHT_GOLDENROD, Color.YELLOW, Color.ORANGE, Color.ORANGE_RED, Color.RED]
modulate = Colors[randi_range(0, 6)]
print("Star born at",global_position)

17
scripts/star_system.gd Normal file
View file

@ -0,0 +1,17 @@
extends Node
class_name StarSystem
@export var width: int = 8192
@export var height: int = 8192
var player_ship: PlayerShip
func _ready():
player_ship = get_node_or_null("PlayerShip")
if player_ship != null:
player_ship.camera.limit_left = -width / 2
player_ship.camera.limit_right = -width / 2
player_ship.camera.limit_top = -height / 2
player_ship.camera.limit_bottom = -height / 2

View file

@ -0,0 +1,16 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://bawhivm5cr2w"]
[ext_resource type="Shader" path="res://shaders/nebula.gdshader" id="1_gp8q1"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_n2xxx"]
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_lcrcg"]
seamless = true
noise = SubResource("FastNoiseLite_n2xxx")
[resource]
shader = ExtResource("1_gp8q1")
shader_parameter/divisor = 10000.0
shader_parameter/offset = Vector2(0, 0)
shader_parameter/nebula_color = Color(0.0666667, 0.0666667, 0.188235, 1)
shader_parameter/noise_texture = SubResource("NoiseTexture2D_lcrcg")