96 lines
3.6 KiB
GDScript
96 lines
3.6 KiB
GDScript
extends Node2D
|
|
|
|
class DeploymentController extends "res://scripts/game/weapon_controller.gd":
|
|
var launch_direction := Vector2.RIGHT
|
|
func _aim_direction_from(_origin: Vector2) -> Vector2: return launch_direction
|
|
|
|
var _ship: CharacterBody2D
|
|
var _inventory: ShipInventory
|
|
var _controller: Node
|
|
var _status: Label
|
|
var _automatic := true
|
|
var _next_deployment := 1.5
|
|
var _deployed := 0
|
|
|
|
func _ready() -> void:
|
|
GameState.start_new_run()
|
|
var game := preload("res://scenes/game/game.tscn").instantiate()
|
|
add_child(game)
|
|
game.set_physics_process(false)
|
|
_ship = game.player
|
|
_ship.set_physics_process(false)
|
|
_ship.get_node("WeaponController").set_physics_process(false)
|
|
_ship.get_node("ExtensionSystems").set_physics_process(false)
|
|
for enemy in get_tree().get_nodes_in_group("enemies"): enemy.queue_free()
|
|
_ship.position = Vector2(0,1500)
|
|
_ship.rotation = PI*0.5
|
|
_ship.get_node("Camera2D").reset_smoothing()
|
|
_inventory = _ship.get_node("ShipInventory")
|
|
var item := ItemInstance.new()
|
|
item.definition = preload("res://resources/items/external_turret.tres")
|
|
_inventory.weapon_slots[0] = item
|
|
_inventory.ammunition = 150
|
|
_inventory.inventory_changed.emit()
|
|
_controller = DeploymentController.new()
|
|
_ship.add_child(_controller)
|
|
_controller.set_physics_process(false)
|
|
var target := preload("res://scenes/game/enemy_ship.tscn").instantiate()
|
|
target.position = _ship.position+Vector2(430,0)
|
|
game.add_child(target)
|
|
target.set_physics_process(false)
|
|
target.max_hull = 1000000.0
|
|
target.hull = target.max_hull
|
|
target.max_shields = 0.0
|
|
target.shields = 0.0
|
|
target._player = _ship
|
|
target.get_node("Sprite2D").texture = preload("res://assets/Ships/Spaceship_0.png")
|
|
target.get_node("Sprite2D").scale = Vector2.ONE*0.18
|
|
target.get_node("Sprite2D").rotation = -PI*0.5
|
|
var overlay := CanvasLayer.new()
|
|
overlay.layer = 100
|
|
add_child(overlay)
|
|
var panel := PanelContainer.new()
|
|
panel.position = Vector2(350,90)
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("07131eec")
|
|
style.border_color = Color("70dfff")
|
|
style.set_border_width_all(1)
|
|
style.set_content_margin_all(14)
|
|
panel.add_theme_stylebox_override("panel",style)
|
|
overlay.add_child(panel)
|
|
_status = Label.new()
|
|
_status.add_theme_font_size_override("font_size",16)
|
|
panel.add_child(_status)
|
|
_update_status()
|
|
print("EXTERNAL_TURRET_LIVE_DEMO: running — SPACE toggles deployment, ESC closes demo")
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not is_instance_valid(_controller): return
|
|
_controller._shot_timers[0] = maxf(0.0,_controller._shot_timers[0]-delta)
|
|
_next_deployment = maxf(0.0,_next_deployment-delta)
|
|
if not _automatic or _next_deployment > 0.0: return
|
|
if _deployed < 3:
|
|
_controller.launch_direction = Vector2.RIGHT.rotated([-1.2,0.0,1.2][_deployed])
|
|
if _controller.try_deploy_turret(0):
|
|
_deployed += 1
|
|
_next_deployment = 1.2
|
|
_update_status()
|
|
elif get_tree().get_nodes_in_group("player_external_turrets").is_empty():
|
|
_deployed = 0
|
|
_inventory.ammunition = 150
|
|
_inventory.ammunition_changed.emit()
|
|
_next_deployment = 2.0
|
|
_update_status()
|
|
|
|
func _unhandled_key_input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed and not event.echo:
|
|
if event.keycode == KEY_SPACE:
|
|
_automatic = not _automatic
|
|
_update_status()
|
|
get_viewport().set_input_as_handled()
|
|
elif event.keycode == KEY_ESCAPE:
|
|
get_tree().quit()
|
|
|
|
func _update_status() -> void:
|
|
_status.text = "DZIAŁKA ZEWNĘTRZNE · %s\nWypuszczone: %d / 3 · 50 amunicji na działko\nKażde oddaje 50 strzałów i znika · pokaz powtarza się\nSPACJA: włącz/wyłącz wypuszczanie · ESC: zamknij pokaz" % ["POKAZ" if _automatic else "WSTRZYMANE",_deployed]
|