grass cleanup, camera cleanup, animation test

This commit is contained in:
Daniel Kauss Serna 2026-02-08 14:03:18 +01:00
parent 561135b63a
commit b12c193636
13 changed files with 35136 additions and 44782 deletions

BIN
assets/angel_wing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dul78gwc33opl"
path="res://.godot/imported/angel_wing.png-77e1715c176150a4ce141601bda1699c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/angel_wing.png"
dest_files=["res://.godot/imported/angel_wing.png-77e1715c176150a4ce141601bda1699c.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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 788 B

Before After
Before After

BIN
assets/sword.aseprite Normal file

Binary file not shown.

BIN
assets/sword.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

40
assets/sword.png.import Normal file
View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bm5kuegf6pa6l"
path="res://.godot/imported/sword.png-95f2475a1c94b517c0dc8c8a23b270ed.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sword.png"
dest_files=["res://.godot/imported/sword.png-95f2475a1c94b517c0dc8c8a23b270ed.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

BIN
assets/teleport_anim.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bgdjxa0bv2wsh"
path="res://.godot/imported/teleport_anim.png-4645fac2558a0dffbe2787e3cd097b1e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/teleport_anim.png"
dest_files=["res://.godot/imported/teleport_anim.png-4645fac2558a0dffbe2787e3cd097b1e.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

View file

@ -117,8 +117,6 @@ func _dir_to_target():
func _physics_process(delta : float): func _physics_process(delta : float):
var target_dist = navigation_agent.target_position.distance_to(global_position) var target_dist = navigation_agent.target_position.distance_to(global_position)
#if (target_dist > 300):
#charge = 0
if (target_dist > aproach_range): if (target_dist > aproach_range):
velocity += global_position.direction_to(_dir_to_target()) * movement_speed velocity += global_position.direction_to(_dir_to_target()) * movement_speed
sprite.flip_h = velocity.x > 0 sprite.flip_h = velocity.x > 0

View file

@ -2,20 +2,31 @@
class_name GrassMultiMesh extends MultiMeshInstance2D class_name GrassMultiMesh extends MultiMeshInstance2D
@export_group("Visuals") @export_group("Visuals")
@export var texture_sheet : Texture2D @export var texture_sheet : Texture2D:
set(value):
texture_sheet = value
texture = value
@export var blade_size : Vector2 = Vector2(16, 16) @export var blade_size : Vector2 = Vector2(16, 16)
@export var texture_sheet_size : Vector2 = Vector2(64, 16) @export var texture_sheet_size : Vector2 = Vector2(64, 16)
@export var grass_tint : Color @export var grass_tint : Color = Color.WHITE:
set(value):
grass_tint = value
material.set_shader_parameter("modulate", grass_tint)
@export_group("Editor") @export_group("Editor")
@export var editing : bool = false @export var editing : bool = false:
set(value):
editing = value
notify_property_list_changed()
@export var brush_radius : float = 50.0 @export var brush_radius : float = 50.0
@export var brush_density : int = 5 @export var brush_density : int = 5
@export var grass_data : Array[Dictionary] = [] @export_storage var grass_data : Array[Dictionary] = []
enum GrassState {NORMAL = 0, CUT = 1} enum GrassState {NORMAL = 0, CUT = 1}
var _blade_half_height: float
func _ready() -> void: func _ready() -> void:
if not multimesh: if not multimesh:
multimesh = MultiMesh.new() multimesh = MultiMesh.new()
@ -25,56 +36,63 @@ func _ready() -> void:
multimesh.mesh = _create_mesh_rect() multimesh.mesh = _create_mesh_rect()
if not material:
material = ShaderMaterial.new()
if ResourceLoader.exists("res://shaders/grass_shader.gdshader"):
material.shader = load("res://shaders/grass_shader.gdshader")
if material is ShaderMaterial: if material is ShaderMaterial:
material.set_shader_parameter("frame_size", blade_size) material.set_shader_parameter("frame_size", blade_size)
material.set_shader_parameter("sheet_size", texture_sheet_size) material.set_shader_parameter("sheet_size", texture_sheet_size)
material.set_shader_parameter("modulate", grass_tint)
if material.get_shader_parameter("noise_tex") == null:
var noise = FastNoiseLite.new()
noise.frequency = 0.005
var noise_tex = NoiseTexture2D.new()
noise_tex.noise = noise
noise_tex.seamless = true
material.set_shader_parameter("noise_tex", noise_tex)
if texture_sheet:
texture = texture_sheet
_blade_half_height = blade_size.y / 2.0
_rebuild_multimesh() _rebuild_multimesh()
func _process(_delta): func _process(_delta):
# move_grass_away(%Player.global_position, 25)
if editing and Engine.is_editor_hint(): if editing and Engine.is_editor_hint():
queue_redraw()
if Input.is_key_pressed(KEY_K): if Input.is_key_pressed(KEY_K):
_brush_paint() _brush_paint()
if Input.is_key_pressed(KEY_E): elif Input.is_key_pressed(KEY_E):
_brush_erase() _brush_erase()
queue_redraw()
func cut_grass_at(pos: Vector2, radius: float):
_interact_with_grass(pos, radius, GrassState.CUT)
func move_grass_away(pos: Vector2, radius: float): func interact_with_grass(global_target_pos: Vector2, rect_size: Vector2, new_state: int):
var half = radius / 2 if global_position.distance_squared_to(global_target_pos) > 500 * 500:
var local_target = to_local(pos) return
for i in range(multimesh.instance_count):
var t = multimesh.get_instance_transform_2d(i)
var dist = t.origin.distance_squared_to(local_target)
if dist < half * half:
var custom_data = multimesh.get_instance_custom_data(i)
custom_data.r = (t.origin.x - local_target.x) * 2
multimesh.set_instance_custom_data(i, custom_data)
elif dist < radius * radius:
var custom_data = multimesh.get_instance_custom_data(i)
custom_data.r = grass_data[i]["rot"]
multimesh.set_instance_custom_data(i, custom_data)
func _interact_with_grass(global_target_pos: Vector2, radius: float, new_state: int):
var local_target = to_local(global_target_pos) var local_target = to_local(global_target_pos)
var half_w = rect_size.x * 0.5
var half_h = rect_size.y * 0.5
var left = local_target.x - half_w
var right = local_target.x + half_w
var top = local_target.y - half_h
var bottom = local_target.y + half_h
for i in range(multimesh.instance_count): for i in range(multimesh.instance_count):
var t = multimesh.get_instance_transform_2d(i) var t_origin = multimesh.get_instance_transform_2d(i).origin
if t_origin.x > left and t_origin.x < right and t_origin.y > top and t_origin.y < bottom:
if t.origin.distance_squared_to(local_target) < radius * radius:
var custom_data = multimesh.get_instance_custom_data(i) var custom_data = multimesh.get_instance_custom_data(i)
if int(custom_data.b) == new_state: if int(custom_data.b) == new_state:
continue continue
custom_data.b = float(new_state) custom_data.b = float(new_state)
multimesh.set_instance_custom_data(i, custom_data) multimesh.set_instance_custom_data(i, custom_data)
grass_data[i]["state"] = new_state grass_data[i]["state"] = new_state
@ -85,14 +103,13 @@ func _create_mesh_rect() -> QuadMesh:
func _rebuild_multimesh() -> void: func _rebuild_multimesh() -> void:
multimesh.instance_count = grass_data.size() multimesh.instance_count = grass_data.size()
var pivot_offset = Vector2(0, -blade_size.y / 2.0) var pivot_offset = Vector2(0, -_blade_half_height)
for i in range(grass_data.size()): for i in range(grass_data.size()):
var d = grass_data[i] var d = grass_data[i]
var xform = Transform2D().translated(d.pos).rotated(d.get("rot", 0.0)).translated(pivot_offset) var xform = Transform2D().translated(d.pos).rotated(d.get("rot", 0.0)).translated(pivot_offset)
multimesh.set_instance_transform_2d(i, xform) multimesh.set_instance_transform_2d(i, xform)
multimesh.set_instance_color(i, grass_tint)
var custom = Color( var custom = Color(
randf(), randf(),
@ -103,10 +120,11 @@ func _rebuild_multimesh() -> void:
multimesh.set_instance_custom_data(i, custom) multimesh.set_instance_custom_data(i, custom)
func _brush_paint() -> void: func _brush_paint() -> void:
var s = Time.get_ticks_msec()
print(s)
seed(s)
var mouse_pos = get_local_mouse_position() var mouse_pos = get_local_mouse_position()
var columns = int(texture_sheet_size.x / blade_size.x)
if columns == 0: columns = 1
for i in range(brush_density): for i in range(brush_density):
var angle = randf() * TAU var angle = randf() * TAU
var rad = sqrt(randf()) * brush_radius var rad = sqrt(randf()) * brush_radius
@ -114,9 +132,9 @@ func _brush_paint() -> void:
var new_blade = { var new_blade = {
"pos": pos, "pos": pos,
"tex_idx": int((randf() ** (1.0/3.0)) * 8), "tex_idx": randi() % columns,
"state": GrassState.NORMAL, "state": GrassState.NORMAL,
"rot": randf_range(-0.1, 0.1) "rot": 0# randf_range(-0.2, 0.2)
} }
grass_data.append(new_blade) grass_data.append(new_blade)
@ -124,8 +142,10 @@ func _brush_paint() -> void:
func _brush_erase() -> void: func _brush_erase() -> void:
var mouse_pos = get_local_mouse_position() var mouse_pos = get_local_mouse_position()
var r_sq = brush_radius * brush_radius
for i in range(grass_data.size() - 1, -1, -1): for i in range(grass_data.size() - 1, -1, -1):
if grass_data[i].pos.distance_to(mouse_pos) < brush_radius: if grass_data[i].pos.distance_squared_to(mouse_pos) < r_sq:
grass_data.remove_at(i) grass_data.remove_at(i)
_rebuild_multimesh() _rebuild_multimesh()

View file

@ -7,47 +7,39 @@ func _ready():
rect.modulate.a = 0 rect.modulate.a = 0
log_display.text = "" log_display.text = ""
log_display.visible = false log_display.visible = false
# Ensure the rect doesn't block clicks while invisible
rect.mouse_filter = Control.MOUSE_FILTER_IGNORE rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
## Combined function to handle both success and error transitions
func change_scene(target_path: String, is_error: bool = false): func change_scene(target_path: String, is_error: bool = false):
rect.mouse_filter = Control.MOUSE_FILTER_STOP rect.mouse_filter = Control.MOUSE_FILTER_STOP
# Set color based on status
if is_error: if is_error:
rect.color = Color.CRIMSON rect.color = Color.CRIMSON
else: else:
rect.color = Color.from_string("#364388", Color.BLUE) rect.color = Color.from_string("#364388", Color.BLUE)
# Fade In
var tween_in = create_tween() var tween_in = create_tween()
await tween_in.tween_property(rect, "modulate:a", 1.0, 0.3).finished await tween_in.tween_property(rect, "modulate:a", 1.0, 0.3).finished
# Display Log
log_display.visible = true log_display.visible = true
var log_file = "res://hex.txt" if is_error else "res://log.txt" var log_file = "res://hex.txt" if is_error else "res://log.txt"
await display_log_file(log_file) display_log_file(log_file)
await get_tree().create_timer(0.5).timeout await get_tree().create_timer(0.5).timeout
# Change Scene
var error = get_tree().change_scene_to_file(target_path) var error = get_tree().change_scene_to_file(target_path)
if error != OK: if error != OK:
push_error("Failed to load scene: " + target_path) push_error("Failed to load scene: " + target_path)
# Cleanup and Fade Out
log_display.visible = false log_display.visible = false
log_display.text = "" log_display.text = ""
var tween_out = create_tween() var tween_out = create_tween()
await tween_out.tween_property(rect, "modulate:a", 0.0, 0.5).finished tween_out.tween_property(rect, "modulate:a", 0.0, 0.5)
rect.mouse_filter = Control.MOUSE_FILTER_IGNORE rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
func display_log_file(file_path: String): func display_log_file(file_path: String):
if not FileAccess.file_exists(file_path): if not FileAccess.file_exists(file_path):
log_display.add_text("ERROR: " + file_path + " not found in build.\n") log_display.add_text("ERROR: " + file_path + " not found in build.\n")
# Check Project -> Export -> Resources -> Filters to include non-resource files
return return
var file = FileAccess.open(file_path, FileAccess.READ) var file = FileAccess.open(file_path, FileAccess.READ)
@ -55,13 +47,11 @@ func display_log_file(file_path: String):
log_display.add_text("ERROR: Could not open file.\n") log_display.add_text("ERROR: Could not open file.\n")
return return
# Reading line by line for that "hacker" effect
while not file.eof_reached(): while not file.eof_reached():
var line = file.get_line() var line = file.get_line()
if line.strip_edges() == "": continue # Skip empty lines if desired if line.strip_edges() == "": continue
log_display.add_text(line + "\n") log_display.add_text(line + "\n")
# Auto-scroll to bottom
log_display.scroll_to_line(log_display.get_line_count()) log_display.scroll_to_line(log_display.get_line_count())
var delay = 0#randf_range(0.0001, 0.00015) var delay = 0#randf_range(0.0001, 0.00015)

View file

@ -3,37 +3,38 @@ shader_type canvas_item;
uniform float wind_speed = 1.0; uniform float wind_speed = 1.0;
uniform float wind_strength = 10.0; uniform float wind_strength = 10.0;
uniform sampler2D noise_tex : repeat_enable; uniform sampler2D noise_tex : repeat_enable;
uniform vec2 frame_size = vec2(16.0, 16.0); uniform vec2 frame_size = vec2(16.0, 32.0);
uniform vec2 sheet_size = vec2(64.0, 16.0); uniform vec2 sheet_size = vec2(64.0, 32.0);
uniform vec4 modulate : source_color = vec4(1.);
void vertex() { void vertex() {
float rnd_offset = INSTANCE_CUSTOM.r; float rnd_offset = INSTANCE_CUSTOM.r;
float tex_idx = INSTANCE_CUSTOM.g; float tex_idx = INSTANCE_CUSTOM.g;
float state = INSTANCE_CUSTOM.b; float state = INSTANCE_CUSTOM.b;
if (state < 0.5) { if (state < 0.5) {
vec2 world_pos = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy; vec2 world_pos = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
float noise = texture(noise_tex, world_pos * 0.005 + vec2(TIME * wind_speed * 0.1)).r; float noise = texture(noise_tex, world_pos * 0.005 + vec2(TIME * wind_speed * 0.1)).r;
if (VERTEX.y < 0.0) { if (VERTEX.y < 0.0) {
VERTEX.x += sin(TIME * wind_speed) * (wind_strength * noise) + rnd_offset; VERTEX.x += sin(TIME * wind_speed) * (wind_strength * noise) + rnd_offset;
} }
} }
if (state > 0.5) { if (state > 0.5) {
VERTEX.y *= 0.2; VERTEX.y *= 0.2;
VERTEX.y += 5.0; VERTEX.y += 5.0;
} }
float columns = sheet_size.x / frame_size.x; float columns = sheet_size.x / frame_size.x;
float col_idx = mod(tex_idx, columns); float col_idx = mod(tex_idx, columns);
UV.x = (UV.x / columns) + (col_idx / columns); UV.x = (UV.x / columns) + (col_idx / columns);
} }
void fragment() { void fragment() {
vec2 uv = vec2(UV.x, 1.0 - UV.y); vec2 uv = vec2(UV.x, 1. - UV.y);
vec4 col = texture(TEXTURE, uv); vec4 col = texture(TEXTURE, uv);
vec3 glow_col = col.xyz * 2.; COLOR = col * modulate;
COLOR = vec4(glow_col, col.w);
} }

79615
stage1.tscn

File diff suppressed because one or more lines are too long