objectrees plant count

This commit is contained in:
Victor 2024-09-01 21:06:48 +02:00
parent 7b2aa34ac0
commit fbbb4af708
3 changed files with 25 additions and 6 deletions

View File

@ -10,7 +10,7 @@ radius = 599.083
script = ExtResource("1_bjim0")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.3, 0.3)
scale = Vector2(0.7, 0.7)
texture = ExtResource("2_n8edq")
offset = Vector2(170, -550)

View File

@ -2,17 +2,30 @@ extends Node2D
signal liberated
@export var plant_need: String
var libarated := false
@export var n_plant_needed: int
var is_liberated := false
var current_plants := 0
func _on_area_2d_area_entered(area: Area2D) -> void:
var plant = area.get_parent()
if plant is Plant and not liberated:
if plant_need == plant.parameter.type:
plant.grown.connect(tracked_plant_grew)
plant.grown.connect(tracked_plant_grew)
plant.died.connect()
func tracked_plant_grew():
if liberated:
return
current_plants += 1
if current_plants == n_plant_needed:
liberate()
func tracked_plant_died():
if liberated:
return
current_plants -= 1
func liberate():
is_liberated = true
print("Liberated !!")
liberated.emit()

View File

@ -28,7 +28,7 @@ func map_to_pixel(
)
func is_on_map(pos: Vector2) -> bool:
return pos.x >= 0 and pos.x <= TERRAIN_SIZE.x * MAP_RATIO and pos.y >= 0 and pos.y <= TERRAIN_SIZE.y * MAP_RATIO
return pos.x >= 0 and pos.x < TERRAIN_SIZE.x * MAP_RATIO and pos.y >= 0 and pos.y < TERRAIN_SIZE.y * MAP_RATIO
func color_value_to_level(
color_value : float
@ -84,6 +84,8 @@ func modify_pixel(
stat: Stats,
modification: int,
):
if not is_on_map(pixel_pos):
return
var actual_levels = color_to_levels(image.get_pixelv(pixel_pos))
var modification_levels = modification_to_levels(stat, modification)
var calculated_levels = actual_levels + modification_levels
@ -93,6 +95,8 @@ func set_pixel(
pixel_pos: Vector2i,
level: Vector3i,
):
if not is_on_map(pixel_pos):
return
image.set_pixelv(pixel_pos, levels_to_color(level))
func modify_zone(
@ -142,6 +146,8 @@ func get_stat(
pos: Vector2,
stat : Stats
) -> int:
if not is_on_map(pos):
return 0
var pixel_pos = map_to_pixel(pos)
var levels = color_to_levels(image.get_pixelv(pixel_pos))
match stat: