Fog of war
This commit is contained in:
@@ -6,6 +6,7 @@ extends Node2D
|
|||||||
@onready var tile_map: TileMapLayer = %TerrainLayer
|
@onready var tile_map: TileMapLayer = %TerrainLayer
|
||||||
@onready var highlight_map: GridOverlay = %OverlayLayer
|
@onready var highlight_map: GridOverlay = %OverlayLayer
|
||||||
@onready var wall_renderer: WallRenderer = %WallRenderer
|
@onready var wall_renderer: WallRenderer = %WallRenderer
|
||||||
|
@onready var fog_renderer: FogRenderer = %FogRenderer
|
||||||
|
|
||||||
const TILE_SIZE := 100.0
|
const TILE_SIZE := 100.0
|
||||||
const SOURCE_ID: int = 0
|
const SOURCE_ID: int = 0
|
||||||
@@ -90,6 +91,7 @@ func apply_layout(layout: MapLayout) -> void:
|
|||||||
map_layout.initialize()
|
map_layout.initialize()
|
||||||
load_from_layout()
|
load_from_layout()
|
||||||
draw_room_walls()
|
draw_room_walls()
|
||||||
|
draw_fog()
|
||||||
|
|
||||||
|
|
||||||
func is_tile_passable(from: Vector2i, to: Vector2i) -> bool:
|
func is_tile_passable(from: Vector2i, to: Vector2i) -> bool:
|
||||||
@@ -112,6 +114,12 @@ func draw_room_walls() -> void:
|
|||||||
wall_renderer.draw_walls_for_layout(map_layout)
|
wall_renderer.draw_walls_for_layout(map_layout)
|
||||||
|
|
||||||
|
|
||||||
|
func draw_fog() -> void:
|
||||||
|
if not map_layout:
|
||||||
|
return
|
||||||
|
fog_renderer.draw_fog_for_layout(map_layout)
|
||||||
|
|
||||||
|
|
||||||
func get_map_rect() -> Rect2:
|
func get_map_rect() -> Rect2:
|
||||||
if not map_layout:
|
if not map_layout:
|
||||||
return Rect2()
|
return Rect2()
|
||||||
|
|||||||
43
nodes/fog_renderer.gd
Normal file
43
nodes/fog_renderer.gd
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
class_name FogRenderer
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
## Renders a fog/cave texture over every tile inside the map's bounding rect
|
||||||
|
## that is not part of any room. Future: drive visibility from map state.
|
||||||
|
|
||||||
|
const TILE_SIZE := 100.0
|
||||||
|
const FOG_RECT := Rect2(53, 53, 100, 100)
|
||||||
|
|
||||||
|
@export var atlas_texture: Texture2D
|
||||||
|
|
||||||
|
|
||||||
|
func draw_fog_for_layout(map_layout: MapLayout) -> void:
|
||||||
|
_clear()
|
||||||
|
if not map_layout or not atlas_texture:
|
||||||
|
return
|
||||||
|
for y in map_layout.size.y:
|
||||||
|
for x in map_layout.size.x:
|
||||||
|
var tile := Vector2i(x, y)
|
||||||
|
if map_layout.is_tile_valid(tile):
|
||||||
|
continue
|
||||||
|
_create_fog_sprite(Vector2(tile) * TILE_SIZE)
|
||||||
|
|
||||||
|
|
||||||
|
func _clear() -> void:
|
||||||
|
for child in get_children():
|
||||||
|
child.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func _create_fog_sprite(pos: Vector2) -> void:
|
||||||
|
var atlas := AtlasTexture.new()
|
||||||
|
atlas.atlas = atlas_texture
|
||||||
|
atlas.region = FOG_RECT
|
||||||
|
|
||||||
|
var sprite := Sprite2D.new()
|
||||||
|
sprite.texture = atlas
|
||||||
|
sprite.centered = false
|
||||||
|
sprite.position = pos
|
||||||
|
sprite.scale = Vector2(
|
||||||
|
TILE_SIZE / FOG_RECT.size.x,
|
||||||
|
TILE_SIZE / FOG_RECT.size.y,
|
||||||
|
)
|
||||||
|
add_child(sprite)
|
||||||
1
nodes/fog_renderer.gd.uid
Normal file
1
nodes/fog_renderer.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://d1d1nbetdvynk
|
||||||
@@ -11,24 +11,24 @@ func _ready() -> void:
|
|||||||
var room_a := Room.new()
|
var room_a := Room.new()
|
||||||
room_a.id = 0
|
room_a.id = 0
|
||||||
room_a.tiles = [
|
room_a.tiles = [
|
||||||
Vector2i(0, 0), Vector2i(1, 0), Vector2i(2, 0),
|
Vector2i(2, 2), Vector2i(3, 2), Vector2i(4, 2),
|
||||||
Vector2i(0, 1), Vector2i(1, 1), Vector2i(2, 1),
|
Vector2i(2, 3), Vector2i(3, 3), Vector2i(4, 3),
|
||||||
Vector2i(0, 2), Vector2i(1, 2), Vector2i(2, 2),
|
Vector2i(2, 4), Vector2i(3, 4), Vector2i(4, 4),
|
||||||
]
|
]
|
||||||
|
|
||||||
var room_b := Room.new()
|
var room_b := Room.new()
|
||||||
room_b.id = 1
|
room_b.id = 1
|
||||||
room_b.tiles = [
|
room_b.tiles = [
|
||||||
Vector2i(3, 0), Vector2i(4, 0), Vector2i(5, 0),
|
Vector2i(5, 2), Vector2i(6, 2), Vector2i(7, 2),
|
||||||
Vector2i(3, 1), Vector2i(4, 1), Vector2i(5, 1),
|
Vector2i(5, 3), Vector2i(6, 3), Vector2i(7, 3),
|
||||||
Vector2i(3, 2), Vector2i(4, 2), Vector2i(5, 2),
|
Vector2i(5, 4), Vector2i(6, 4), Vector2i(7, 4),
|
||||||
]
|
]
|
||||||
|
|
||||||
var layout := MapLayout.new()
|
var layout := MapLayout.new()
|
||||||
layout.rooms = [room_a, room_b]
|
layout.rooms = [room_a, room_b]
|
||||||
# Opening between (2,1) in room_a and (3,1) in room_b
|
# Opening between (4,3) in room_a and (5,3) in room_b
|
||||||
layout.openings = [Vector2i(2, 1), Vector2i(3, 1)]
|
layout.openings = [Vector2i(4, 3), Vector2i(5, 3)]
|
||||||
layout.size = Vector2i(6, 3)
|
layout.size = Vector2i(10, 7)
|
||||||
|
|
||||||
combat_map.apply_layout(layout)
|
combat_map.apply_layout(layout)
|
||||||
camera.set_map_bounds(combat_map.get_map_rect())
|
camera.set_map_bounds(combat_map.get_map_rect())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://65rmoynep5hy" path="res://assets/sprites/MP000A.BMP" id="6_muxvo"]
|
[ext_resource type="Texture2D" uid="uid://65rmoynep5hy" path="res://assets/sprites/MP000A.BMP" id="6_muxvo"]
|
||||||
[ext_resource type="Script" path="res://nodes/wall_renderer.gd" id="7_wallr"]
|
[ext_resource type="Script" path="res://nodes/wall_renderer.gd" id="7_wallr"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b20mhn7ca5xyo" path="res://assets/sprites/aux_terrain.BMP" id="8_auxtr"]
|
[ext_resource type="Texture2D" uid="uid://b20mhn7ca5xyo" path="res://assets/sprites/aux_terrain.BMP" id="8_auxtr"]
|
||||||
|
[ext_resource type="Script" path="res://nodes/fog_renderer.gd" id="9_fogrn"]
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_vcj5e"]
|
[sub_resource type="Resource" id="Resource_vcj5e"]
|
||||||
script = ExtResource("2_8rn0j")
|
script = ExtResource("2_8rn0j")
|
||||||
@@ -86,6 +87,11 @@ offset = Vector2(50, 50)
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
tile_set = SubResource("TileSet_e2u25")
|
tile_set = SubResource("TileSet_e2u25")
|
||||||
|
|
||||||
|
[node name="FogRenderer" type="Node2D" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("9_fogrn")
|
||||||
|
atlas_texture = ExtResource("8_auxtr")
|
||||||
|
|
||||||
[node name="WallRenderer" type="Node2D" parent="."]
|
[node name="WallRenderer" type="Node2D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
z_index = 1
|
z_index = 1
|
||||||
|
|||||||
BIN
reference_images/Screenshot 2026-04-07 075123.png
Normal file
BIN
reference_images/Screenshot 2026-04-07 075123.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
40
reference_images/Screenshot 2026-04-07 075123.png.import
Normal file
40
reference_images/Screenshot 2026-04-07 075123.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://d4fwfh0cyj3bd"
|
||||||
|
path="res://.godot/imported/Screenshot 2026-04-07 075123.png-98f6527da5d69103c0f83722dd6ba790.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://reference_images/Screenshot 2026-04-07 075123.png"
|
||||||
|
dest_files=["res://.godot/imported/Screenshot 2026-04-07 075123.png-98f6527da5d69103c0f83722dd6ba790.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
@@ -90,14 +90,14 @@ func _pressed() -> void:
|
|||||||
player_unit.info_template = UnitInfo.new()
|
player_unit.info_template = UnitInfo.new()
|
||||||
player_unit.info_template.name = \"Putit\"
|
player_unit.info_template.name = \"Putit\"
|
||||||
player_unit.allegiance_template = PLAYER_ALLEGIANCE
|
player_unit.allegiance_template = PLAYER_ALLEGIANCE
|
||||||
combat_map.deploy_unit(player_unit, Vector2i(2, 2))
|
combat_map.deploy_unit(player_unit, Vector2i(3, 3))
|
||||||
|
|
||||||
var enemy_unit: Unit = UNIT_SCENE.instantiate()
|
var enemy_unit: Unit = UNIT_SCENE.instantiate()
|
||||||
enemy_unit.stat_template = UnitStats.new(50)
|
enemy_unit.stat_template = UnitStats.new(50)
|
||||||
enemy_unit.info_template = UnitInfo.new()
|
enemy_unit.info_template = UnitInfo.new()
|
||||||
enemy_unit.info_template.name = \"Putit\"
|
enemy_unit.info_template.name = \"Putit\"
|
||||||
enemy_unit.allegiance_template = ENEMY_ALLEGIANCE
|
enemy_unit.allegiance_template = ENEMY_ALLEGIANCE
|
||||||
combat_map.deploy_unit(enemy_unit, Vector2i(2, 1))
|
combat_map.deploy_unit(enemy_unit, Vector2i(6, 3))
|
||||||
|
|
||||||
var tree := get_tree()
|
var tree := get_tree()
|
||||||
var root := tree.root
|
var root := tree.root
|
||||||
|
|||||||
Reference in New Issue
Block a user