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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue