A little folders cleanup
This commit is contained in:
parent
997e3c0982
commit
545da7be1f
90 changed files with 68 additions and 1661 deletions
11
scripts/Star System/faction.gd
Normal file
11
scripts/Star System/faction.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
class_name FactionNode
|
||||
|
||||
## Faction that is represented with this node
|
||||
@export var faction: Game.Faction
|
||||
|
||||
func _ready():
|
||||
for child in get_children():
|
||||
if "faction" in child:
|
||||
child.faction = faction
|
||||
15
scripts/Star System/nebula.gd
Normal file
15
scripts/Star System/nebula.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends ColorRect
|
||||
|
||||
## 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):
|
||||
if tracked_node != null:
|
||||
material.set_shader_parameter("offset", tracked_node.global_position)
|
||||
11
scripts/Star System/projectile_container.gd
Normal file
11
scripts/Star System/projectile_container.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
class_name ProjectileContainer
|
||||
|
||||
static var instance : ProjectileContainer
|
||||
|
||||
func _ready():
|
||||
instance = self
|
||||
|
||||
func _exit_tree():
|
||||
instance = null
|
||||
11
scripts/Star System/star.gd
Normal file
11
scripts/Star System/star.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends AnimatedSprite2D
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
var size : float = randf_range(0.5, 2)
|
||||
frame = randi_range(0, 7)
|
||||
scale = Vector2(size, size)
|
||||
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.pick_random()
|
||||
modulate.a = randf_range(0.5, 1)
|
||||
65
scripts/Star System/star_system.gd
Normal file
65
scripts/Star System/star_system.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
extends Node
|
||||
|
||||
class_name StarSystem
|
||||
|
||||
@onready var fact_player = $FactionPlayer
|
||||
@onready var fact_peaceful = $FactionPeaceful
|
||||
@onready var fact_neutral = $FactionNeutral
|
||||
@onready var fact_aggressive = $FactionAggressive
|
||||
|
||||
## Width of the system. Limits stars generation and camera bounds
|
||||
@export var width: int = 8192
|
||||
## Height of the system. Limits stars generation and camera bounds
|
||||
@export var height: int = 8192
|
||||
|
||||
## Pause controller packed scene
|
||||
@export var pause_controller_scene: PackedScene
|
||||
|
||||
## Node which is colliding with mouse
|
||||
var targeted_node: Node2D = null
|
||||
|
||||
## Player ship reference. May be null.
|
||||
var player_ship: PlayerShip
|
||||
## Pause controller reference
|
||||
var pause_controller: Control
|
||||
|
||||
func _ready():
|
||||
player_ship = get_node_or_null("FactionPlayer/PlayerShip")
|
||||
|
||||
pause_controller = pause_controller_scene.instantiate()
|
||||
|
||||
if player_ship != null:
|
||||
# adjust player ship camera if player ship exists
|
||||
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
|
||||
# add pause controller child to the gui
|
||||
player_ship.colorable_gui.add_child(pause_controller)
|
||||
else:
|
||||
# or add it to root node lol
|
||||
add_child(pause_controller)
|
||||
|
||||
|
||||
pause_controller.visible = false
|
||||
|
||||
## Pause the game. Remember to unpause it when switching scenes!
|
||||
func pause():
|
||||
get_tree().paused = true
|
||||
pause_controller.visible = true
|
||||
|
||||
## Unpause the game.
|
||||
func unpause():
|
||||
get_tree().paused = false
|
||||
pause_controller.visible = false
|
||||
|
||||
func _process(_delta):
|
||||
# pausing
|
||||
if Input.is_action_just_released("pause"):
|
||||
unpause() if get_tree().paused else pause()
|
||||
|
||||
func set_targeted_node(node):
|
||||
targeted_node = node
|
||||
|
||||
func clear_targeted_node():
|
||||
targeted_node = null
|
||||
25
scripts/Star System/stars_generator.gd
Normal file
25
scripts/Star System/stars_generator.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
extends Node
|
||||
|
||||
## 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: = 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue