97 lines
3.6 KiB
GDScript
97 lines
3.6 KiB
GDScript
extends Node2D
|
|
|
|
var _ship: CharacterBody2D
|
|
var _game: Node2D
|
|
var _status: Label
|
|
var _time := 0.0
|
|
var _activated := false
|
|
var _shots := 0
|
|
var _next_shot := 4.0
|
|
var _paused := false
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
GameState.start_new_run()
|
|
_game = preload("res://scenes/game/game.tscn").instantiate()
|
|
_game.process_mode = Node.PROCESS_MODE_PAUSABLE
|
|
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 = 0.0
|
|
_ship.get_node("Camera2D").reset_smoothing()
|
|
_ship.max_energy = 100.0
|
|
_ship.max_shields = 100.0
|
|
_ship.max_hull = 100.0
|
|
_ship.absorption = Vector3.ZERO
|
|
var item := ItemInstance.new()
|
|
item.definition = preload("res://resources/items/auxiliary_shield.tres")
|
|
_ship.get_node("ShipInventory").extension_slots[0] = item
|
|
_ship.get_node("ShipInventory").inventory_changed.emit()
|
|
var overlay := CanvasLayer.new()
|
|
overlay.layer = 100
|
|
add_child(overlay)
|
|
var panel := PanelContainer.new()
|
|
panel.position = Vector2(320,80)
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("100a21ed")
|
|
style.border_color = Color("ba8cff")
|
|
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)
|
|
_reset_cycle()
|
|
print("AUXILIARY_SHIELD_LIVE_DEMO: running — activation, 8 incoming shots, repeating cycle; SPACE pause, ESC close")
|
|
|
|
func _reset_cycle() -> void:
|
|
for bullet in get_tree().get_nodes_in_group("auxiliary_demo_bullets"): bullet.queue_free()
|
|
_time = 0.0
|
|
_shots = 0
|
|
_next_shot = 4.0
|
|
_activated = false
|
|
_ship.get_node("ExtensionSystems").reset_combat_state()
|
|
_ship.energy = 100.0
|
|
_ship.shields = 100.0
|
|
_ship.hull = 100.0
|
|
_ship._update_shield_visual()
|
|
_update_status()
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if _paused or not is_instance_valid(_ship): return
|
|
_time += delta
|
|
if _time >= 2.0 and not _activated:
|
|
_activated = _ship.activate_ability(0)
|
|
if _activated and _time >= _next_shot and _shots < 8:
|
|
var bullet := preload("res://scenes/game/weapon_projectile.tscn").instantiate()
|
|
bullet.enemy_shot = true
|
|
bullet.collision_mask = 2
|
|
var origin := _ship.global_position+Vector2(400,0)
|
|
bullet.configure(origin,Vector2.LEFT,ItemDefinition.WeaponKind.PLASMA,650.0,10.0,800.0)
|
|
bullet.add_to_group("auxiliary_demo_bullets")
|
|
_game.add_child(bullet)
|
|
_shots += 1
|
|
_next_shot += 0.9
|
|
if _time >= 14.0: _reset_cycle()
|
|
_update_status()
|
|
|
|
func _update_status() -> void:
|
|
var phase := "ZA CHWILĘ AKTYWACJA" if not _activated else ("OSTRZAŁ ZEWNĘTRZNEJ OSŁONY" if _ship.auxiliary_shields > 0.0 else "OSŁONA ZUŻYTA · OBRYWAJĄ ZWYKŁE TARCZE")
|
|
_status.text = "TARCZA ZEWNĘTRZNA · %s\n%s\nEnergia: %.0f / 100 · Osłona: %.0f / 50 · Tarcze: %.0f / 100\nOstrzał: 10 obrażeń / pocisk · pokaz powtarza się\nSPACJA: pauza/wznów · ESC: zamknij pokaz" % ["PAUZA" if _paused else "POKAZ",phase,_ship.energy,_ship.auxiliary_shields,_ship.shields]
|
|
|
|
func _unhandled_key_input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed and not event.echo:
|
|
if event.keycode == KEY_SPACE:
|
|
_paused = not _paused
|
|
get_tree().paused = _paused
|
|
_update_status()
|
|
get_viewport().set_input_as_handled()
|
|
elif event.keycode == KEY_ESCAPE:
|
|
get_tree().quit()
|