Added base template (uninteractive yet)

This commit is contained in:
2ndbeam 2024-05-01 12:55:32 +03:00
commit 2d4eb92751
8 changed files with 100 additions and 17 deletions

View file

@ -17,6 +17,8 @@ class_name Hull
"Laser Energy": 100.0,
"Rockets": 10,
}
## How much speed should ship have before collision to take damage
@export var velocity_collision_treshold: float = 200.0
## Current ammunition. Change this with set_ammunition
@onready var ammunition: Dictionary = max_ammunition.duplicate()
@ -31,6 +33,9 @@ class_name Hull
## Length of linear_velocity vector
var scalar_velocity: float = 0.0
func _ready():
body_entered.connect(_on_body_entered)
## Adds amount to ammunition, returns true if it was successful
func add_ammunition(which: String, value: float) -> bool:
if ammunition[which] + value < 0:
@ -44,3 +49,10 @@ func _physics_process(_delta):
ship.position = position
ship.rotation = rotation
scalar_velocity = linear_velocity.length()
func _on_body_entered(_body):
if scalar_velocity >= velocity_collision_treshold:
ship.shield.deal_damage(20.0 * (scalar_velocity / velocity_collision_treshold))
func warp_to_position(location: Vector2):
position = location

View file

@ -21,13 +21,18 @@ var faction : Game.Faction = Game.Faction.Player
func _ready() -> void:
hull.global_position = global_position
destroyed.connect(destroy)
destroyed.connect(destroy_timeout)
func destroy_timeout():
get_tree().create_timer(0.02).timeout.connect(destroy)
## Reset all required variables
func destroy() -> void:
hull.hp = hull.max_hp
hull.global_position = spawn_position
hull.linear_velocity = Vector2.ZERO
hull.angular_velocity = 0.0
shield.capacity = shield.max_capacity
hull.warp_to_position(spawn_position)
## Swaps old hull with the new one
func change_hull(new_hull_id: String) -> void: