Rewriting ships: Added some player interface and started rewriting star system
This commit is contained in:
parent
6957169ba5
commit
4172b336c1
20 changed files with 300 additions and 139 deletions
|
|
@ -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()
|
||||
|
|
|
|||
16
scripts/Ship/player_camera.gd
Normal file
16
scripts/Ship/player_camera.gd
Normal 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
|
||||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
9
scripts/Ship/player_ship.gd
Normal file
9
scripts/Ship/player_ship.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
extends Ship
|
||||
|
||||
class_name PlayerShip
|
||||
|
||||
## Player camera reference
|
||||
@onready var camera = $Camera
|
||||
|
||||
## Currency variable
|
||||
var money: float = 1000.0
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
28
scripts/misc/stars_generator.gd
Normal file
28
scripts/misc/stars_generator.gd
Normal 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)
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
17
scripts/star_system.gd
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue