ajout d'un terrain infini et la possibilité de planter n'importe où

This commit is contained in:
2025-11-30 16:53:07 +01:00
parent 72ffa0b222
commit 8917a02a7b
63 changed files with 2847 additions and 1190 deletions

1
common/icons/pick.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-pick"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M13 8l-9.383 9.418a2.091 2.091 0 0 0 0 2.967a2.11 2.11 0 0 0 2.976 0l9.407 -9.385" /><path d="M9 3h4.586a1 1 0 0 1 .707 .293l6.414 6.414a1 1 0 0 1 .293 .707v4.586a2 2 0 1 1 -4 0v-3l-5 -5h-3a2 2 0 1 1 0 -4z" /></svg>

After

Width:  |  Height:  |  Size: 514 B

View File

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ds4m14vl7he6v"
path="res://.godot/imported/pick.svg-b8cbf14d632089bea5ad3faa09f4cc83.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://common/icons/pick.svg"
dest_files=["res://.godot/imported/pick.svg-b8cbf14d632089bea5ad3faa09f4cc83.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
svg/scale=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -0,0 +1,69 @@
class_name Math
static func get_chunk_from_pos(coord) -> Vector2i:
return Vector2i(
floori(coord.x / (Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE)),
floori(coord.y / (Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE))
)
static func get_tile_from_pos(coord) -> Vector2i:
return Vector2i(
floori(coord.x / (Planet.TILE_SIZE)),
floori(coord.y / (Planet.TILE_SIZE)),
)
static func get_tiles_in_circle(center: Vector2, radius : float) -> Array[Vector2i]:
var tiles : Array[Vector2i] = []
for x in range(
floori((center.x - radius/2.) / Planet.TILE_SIZE),
ceili((center.x + radius/2.) / Planet.TILE_SIZE),
):
for y in range(
floori((center.y - radius/2.) / Planet.TILE_SIZE),
ceili((center.y + radius/2.) / Planet.TILE_SIZE),
):
if is_tile_on_circle(Vector2i(x,y), center, radius):
tiles.append(Vector2i(x,y))
return tiles
static func is_tile_on_circle(tile_coord : Vector2i, circle_center: Vector2, circle_radius : float) -> bool:
var absolute_tile_pos : Vector2 = tile_coord * Planet.TILE_SIZE
# Loop over tile corners to know if the area collide
var corners : Array[Vector2] = []
for x in [0,1]:
for y in [0,1]:
corners.append(
absolute_tile_pos
+ Vector2.RIGHT * x * Planet.TILE_SIZE
+ Vector2.DOWN * y * Planet.TILE_SIZE
)
# Check if segment touch area
for i in range(4):
var a = corners[i%4]
var b = corners[(i+1)%4]
if segment_intersect_circle(a,b,circle_center,circle_radius):
return true
return false
# Stolen here https://stackoverflow.com/questions/1073336/circle-line-segment-collision-detection-algorithm
static func segment_intersect_circle(
a : Vector2,
b : Vector2,
c : Vector2,
radius: float
) -> bool:
var a_circle = c - a
var b_a = b - a
var proj_point = proj(a_circle,b_a) + a
return proj_point.distance_to(c) < radius
static func proj(a : Vector2,b : Vector2) -> Vector2:
var k = a.dot(b) / b.dot(b)
return Vector2(k * b.x, k * b.y)

View File

@@ -0,0 +1 @@
uid://b8i5lkk4md657

View File

@@ -0,0 +1,29 @@
shader_type canvas_item;
uniform sampler2D red_overlay_tex: repeat_enable, filter_nearest;
uniform sampler2D green_overlay_tex: repeat_enable, filter_nearest;
uniform sampler2D blue_overlay_tex: repeat_enable, filter_nearest;
uniform float scale = 0.006944444; // calculated by 1/texture size e.g. 1/144
varying vec2 world_position;
void vertex(){
// calculate the world position for use in the fragment shader
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
void fragment() {
float mix_amount = floor(COLOR.r);
// sample the overlay_tex using worldPos
vec4 red_overlay_color = texture(red_overlay_tex, world_position * scale);
vec4 green_overlay_color = texture(green_overlay_tex, world_position * scale);
vec4 blue_overlay_color = texture(blue_overlay_tex, world_position * scale);
float origin_alpha = COLOR.a;
// combine original color and overlay color together
COLOR = mix(COLOR, red_overlay_color, floor(COLOR.r));
COLOR = mix(COLOR, green_overlay_color, floor(COLOR.g));
COLOR = mix(COLOR, blue_overlay_color, floor(COLOR.b));
COLOR.a = origin_alpha;
}

View File

@@ -1,21 +0,0 @@
shader_type canvas_item;
uniform sampler2D overlay_tex: repeat_enable, filter_nearest;
uniform float scale = 0.006944444; // calculated by 1/texture size e.g. 1/144
varying vec2 world_position;
void vertex(){
// calculate the world position for use in the fragment shader
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
void fragment() {
// only apply overlay_tex on the fully red parts of the original tiles
float mix_amount = floor(COLOR.r);
// sample the overlay_tex using worldPos
vec4 overlay_color = texture(overlay_tex, world_position * scale);
// combine original color and overlay color together
COLOR = mix(COLOR, overlay_color, mix_amount);
}