52 lines
2.1 KiB
GDScript
52 lines
2.1 KiB
GDScript
extends Node2D
|
|
|
|
const PLAYER := preload("res://scenes/game/player_ship.tscn")
|
|
const ENEMY := preload("res://scenes/game/enemy_ship.tscn")
|
|
const BALANCE := preload("res://scripts/captain/captain_balance.gd")
|
|
|
|
func _ready() -> void:
|
|
GameState.start_new_run()
|
|
GameState.system_level = 4
|
|
var ship := PLAYER.instantiate() as CharacterBody2D
|
|
ship.name = "PlayerShip"
|
|
add_child(ship)
|
|
ship.set_physics_process(false)
|
|
ship.get_node("WeaponController").set_physics_process(false)
|
|
ship.set("credits_multiplier", 1.5)
|
|
var inventory := ship.get_node("ShipInventory") as ShipInventory
|
|
assert(inventory.ammunition == 50)
|
|
var enemy := ENEMY.instantiate() as CharacterBody2D
|
|
enemy.position = Vector2(700, 0)
|
|
add_child(enemy)
|
|
enemy.set_physics_process(false)
|
|
enemy.set("_player", ship)
|
|
enemy.call("apply_level_settings", 4, 2)
|
|
var expected := roundi(BALANCE.KILL_CREDITS[2] * 1.15 * 1.5)
|
|
enemy.call("take_damage", 10.0 * (float(enemy.get("max_hull")) + float(enemy.get("max_shields"))))
|
|
assert(GameState.captain.credits == 0)
|
|
assert(GameState.captain.level > 1 or GameState.captain.experience > 0)
|
|
await get_tree().process_frame
|
|
var pickups := get_tree().get_nodes_in_group("credit_pickups")
|
|
assert(pickups.size() == 1)
|
|
var pickup := pickups[0] as Node2D
|
|
pickup.set_physics_process(false)
|
|
assert(pickup.get("amount") == expected)
|
|
pickup.call("_physics_process", 0.1)
|
|
assert(GameState.captain.credits == 0)
|
|
# Credits can be collected even when cargo is full.
|
|
var item := ItemInstance.new()
|
|
item.definition = preload("res://resources/items/plasma_cannon.tres")
|
|
inventory.cargo.fill(item)
|
|
ship.position = pickup.position
|
|
pickup.call("_physics_process", 0.1)
|
|
assert(GameState.captain.credits == expected)
|
|
pickup.call("_physics_process", 0.1)
|
|
assert(GameState.captain.credits == expected)
|
|
var found_popup := false
|
|
for child in get_children():
|
|
if child is Label and child.text == "+%d KREDYTÓW" % expected:
|
|
found_popup = true
|
|
assert(found_popup)
|
|
print("CREDIT_PICKUP_TEST: PASS (drop, deferred credits, XP, gear bonus, proximity, full cargo, popup, single collection)")
|
|
get_tree().quit()
|