extends Node3D @onready var player1: CharacterBody3D = $Player1 @onready var camera: Camera3D = $Camera3D @onready var level: Node3D = $Level @onready var world_coloring_viewport: SubViewport = $WorldColoringViewport @onready var world_coloring_player1_texture_rect: TextureRect = $WorldColoringViewport/Player1TextureRect @onready var world_coloring_player1_sprite: Sprite2D = $WorldColoringViewport/Player1Sprite @onready var world_coloring_player1_bomb_sprite: Sprite2D = $WorldColoringViewport/Player1BombSprite var camera_offset: Vector3; var world_coloring_material: ShaderMaterial # Called when the node enters the scene tree for the first time. func _ready(): camera_offset = camera.global_position - player1.global_position world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres") world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture()) world_coloring_player1_sprite.modulate = player1.color world_coloring_player1_bomb_sprite.modulate = player1.color player1.connect("bomb_triggered", player_bomb_triggered) apply_world_coloring_recursive(level) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): camera.global_position = player1.global_position + camera_offset pass func _physics_process(_delta): world_coloring_player1_sprite.global_position = player_position_to_world_coloring_position(player1.global_position) world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture()) func player_position_to_world_coloring_position(player_position: Vector3): var result = Vector2 (player_position.x * 10 + 500, player_position.z * 10 + 500) return result; func apply_world_coloring_recursive (node): for child in node.get_children(): var mesh_instance := child as MeshInstance3D if mesh_instance: assign_world_coloring_pass(mesh_instance) apply_world_coloring_recursive(child) func assign_world_coloring_pass(mesh_instance: MeshInstance3D) -> void: var material = mesh_instance.get_active_material(0) if not material: return material.next_pass = world_coloring_material func player_bomb_triggered(player): world_coloring_player1_bomb_sprite.global_position = player_position_to_world_coloring_position(player.global_position) world_coloring_player1_bomb_sprite.visible = true