Implement weather system and developer console features. Added functionality for setting weather conditions, temperature, and wind speed through a new developer console. Enhanced the vault scene to display current weather, temperature, and wind information, and updated game clock to allow time manipulation. Improved cloud rendering and introduced a new climate management system for seasonal temperature adjustments.

This commit is contained in:
Leonid Pershin
2026-08-11 11:37:56 +03:00
parent a81747781d
commit 3b886ab3ab
14 changed files with 928 additions and 63 deletions
+80 -20
View File
@@ -12,8 +12,17 @@ extends Node2D
const MOUNTAINS := preload("res://background/PNG/Flat/pointy_mountains.png")
const HILLS_FAR := preload("res://background/PNG/Flat/hills2.png")
const HILLS_NEAR := preload("res://background/PNG/Flat/hills1.png")
const CLOUDS_HIGH := preload("res://background/PNG/Flat/clouds1.png")
const CLOUDS_LOW := preload("res://background/PNG/Flat/clouds2.png")
## Облака — отдельными клубами, а не сплошной лентой: у ленты прямоугольник
## обрезает текстуру, и на небе видно горизонтальный шов, который вдобавок
## едет вместе с ветром.
const CLOUD_PATHS := [
"res://background/PNG/Flat/cloud1.png", "res://background/PNG/Flat/cloud2.png",
"res://background/PNG/Flat/cloud3.png", "res://background/PNG/Flat/cloud4.png",
"res://background/PNG/Flat/cloud5.png", "res://background/PNG/Flat/cloud6.png",
"res://background/PNG/Flat/cloud7.png", "res://background/PNG/Flat/cloud8.png",
"res://background/PNG/Flat/cloud9.png",
]
const CLOUD_COUNT := 30
## Ближний план берём из основного набора: там деревья и трава уже цветные.
## Набор Flat — бледные силуэты, он идёт на дальние слои, которые всё равно
@@ -36,6 +45,8 @@ const HILLS_NEAR_TONE := Color("#5d8248")
const LEFT := -1600.0
const RIGHT := 2900.0
## Сколько крайних столбцов текстуры отбрасываем на стыке плиток.
const EDGE_INSET := 1.0
const SCENERY_SEED := 20120401
## Полоса дёрна на уровне земли.
@@ -57,15 +68,19 @@ var time_scale := 1.0
var _trees: Array[Dictionary] = []
var _grass: Array[Dictionary] = []
var _cloud_puffs: Array[Dictionary] = []
var _drops: Array[Vector2] = []
var _drift := 0.0
var _fall := 0.0
func _ready() -> void:
# Плиточная заливка широких полос требует повтора текстуры на узле.
texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED
# Повтор выключен намеренно: полосы мы кладём плитками сами, а с включённым
# повтором фильтрация на краю кадра подмешивает противоположный край
# текстуры — по небу шла тонкая линия во всю ширину.
texture_repeat = CanvasItem.TEXTURE_REPEAT_DISABLED
_scatter_scenery()
_scatter_clouds()
_scatter_drops()
@@ -116,10 +131,28 @@ func _draw_band(
texture: Texture2D, tone: Color, scale: float, distance: float, parallax: float,
light: Color, haze: Color, view: Rect2
) -> void:
var size := Vector2(texture.get_size()) * scale
var tint := (tone * light).lerp(haze, distance)
var offset := view.get_center().x * (1.0 - parallax)
var rect := Rect2(Vector2(LEFT + offset, -size.y), Vector2(RIGHT - LEFT, size.y))
draw_texture_rect(texture, rect, true, (tone * light).lerp(haze, distance))
var texture_size := Vector2(texture.get_size())
# Плитку кладём вручную: draw_texture_rect(tile = true) повторяет текстуру
# в натуральную величину и по обеим осям сразу, из-за чего масштаб
# превращался в лишние ряды с полосой на стыке.
#
# Крайние столбцы пикселей у этих текстур полупрозрачные (сглаживание).
# Встык они складываются дважды и дают вертикальную линию, поэтому берём
# область с отступом в пиксель с каждой стороны и ещё на пиксель
# перекрываем соседние плитки.
var source := Rect2(
Vector2(EDGE_INSET, 0.0), Vector2(texture_size.x - EDGE_INSET * 2.0, texture_size.y)
)
var tile := Vector2(source.size.x * scale, texture_size.y * scale)
var step := tile.x - 1.0
var x := LEFT + fposmod(offset, step) - step
while x < RIGHT:
draw_texture_rect_region(texture, Rect2(Vector2(x, -tile.y), tile), source, tint)
x += step
func _draw_turf(light: Color) -> void:
@@ -146,21 +179,28 @@ func _draw_clouds(view: Rect2, light: Color) -> void:
if clouds <= 0.02:
return
# Полосы держим выше линии горизонта: их нижний край не должен наезжать
# на землю, поэтому высота и масштаб подобраны в паре.
_draw_cloud_band(CLOUDS_HIGH, 1.4, -900.0, 0.35, 0.75, view, light)
_draw_cloud_band(CLOUDS_LOW, 1.6, -620.0, 0.6, 1.0, view, light)
var span := RIGHT - LEFT
var density := clampf(clouds, 0.0, 1.0)
# Чем плотнее облачность, тем свинцовее облака.
var tint := light.lerp(light * Color("#8ea3b8"), density)
for cloud: Dictionary in _cloud_puffs:
# У каждого облака свой порог: облачность прибавляет их числом, а не
# только непрозрачностью, иначе пасмурно выглядит как ясно, но мутнее.
var threshold: float = cloud["threshold"]
if density <= threshold:
continue
var alpha := clampf((density - threshold) * 5.0, 0.0, 1.0) * 0.9
func _draw_cloud_band(
texture: Texture2D, scale: float, height: float, parallax: float,
weight: float, view: Rect2, light: Color
) -> void:
var size := Vector2(texture.get_size()) * scale
var offset := view.get_center().x * (1.0 - parallax) - _drift * parallax
var rect := Rect2(Vector2(LEFT + offset, height), Vector2(RIGHT - LEFT, size.y))
var alpha := clampf(clouds * weight, 0.0, 1.0)
draw_texture_rect(texture, rect, true, Color(light, alpha))
var depth: float = cloud["depth"]
var texture: Texture2D = cloud["texture"]
var size := Vector2(texture.get_size()) * float(cloud["scale"])
var offset := view.get_center().x * (1.0 - depth) - _drift * depth
var x := LEFT + fposmod(float(cloud["x"]) + offset - LEFT, span)
draw_texture_rect(
texture, Rect2(Vector2(x, float(cloud["y"])), size), false, Color(tint, alpha)
)
## Дымка у горизонта: чем гуще, тем сильнее пейзаж растворяется в небе.
@@ -241,6 +281,26 @@ func _scatter_scenery() -> void:
})
func _scatter_clouds() -> void:
var rng := RandomNumberGenerator.new()
rng.seed = SCENERY_SEED + 3
var textures: Array[Texture2D] = []
for path: String in CLOUD_PATHS:
textures.append(load(path) as Texture2D)
for index in CLOUD_COUNT:
_cloud_puffs.append({
"texture": textures[rng.randi_range(0, textures.size() - 1)],
"x": rng.randf_range(LEFT, RIGHT),
"y": rng.randf_range(-1020.0, -430.0),
"scale": rng.randf_range(1.3, 3.4),
# Ближние облака едут быстрее дальних.
"depth": rng.randf_range(0.25, 0.75),
"threshold": rng.randf_range(0.0, 0.9),
})
func _scatter_drops() -> void:
var rng := RandomNumberGenerator.new()
rng.seed = SCENERY_SEED + 7