objectrees plant count
This commit is contained in:
parent
7b2aa34ac0
commit
fbbb4af708
@ -10,7 +10,7 @@ radius = 599.083
|
|||||||
script = ExtResource("1_bjim0")
|
script = ExtResource("1_bjim0")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
scale = Vector2(0.3, 0.3)
|
scale = Vector2(0.7, 0.7)
|
||||||
texture = ExtResource("2_n8edq")
|
texture = ExtResource("2_n8edq")
|
||||||
offset = Vector2(170, -550)
|
offset = Vector2(170, -550)
|
||||||
|
|
||||||
|
|||||||
@ -2,17 +2,30 @@ extends Node2D
|
|||||||
|
|
||||||
signal liberated
|
signal liberated
|
||||||
|
|
||||||
@export var plant_need: String
|
@export var n_plant_needed: int
|
||||||
var libarated := false
|
|
||||||
|
var is_liberated := false
|
||||||
|
var current_plants := 0
|
||||||
|
|
||||||
func _on_area_2d_area_entered(area: Area2D) -> void:
|
func _on_area_2d_area_entered(area: Area2D) -> void:
|
||||||
var plant = area.get_parent()
|
var plant = area.get_parent()
|
||||||
if plant is Plant and not liberated:
|
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():
|
func tracked_plant_grew():
|
||||||
if liberated:
|
if liberated:
|
||||||
return
|
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 !!")
|
print("Liberated !!")
|
||||||
liberated.emit()
|
liberated.emit()
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func map_to_pixel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
func is_on_map(pos: Vector2) -> bool:
|
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(
|
func color_value_to_level(
|
||||||
color_value : float
|
color_value : float
|
||||||
@ -84,6 +84,8 @@ func modify_pixel(
|
|||||||
stat: Stats,
|
stat: Stats,
|
||||||
modification: int,
|
modification: int,
|
||||||
):
|
):
|
||||||
|
if not is_on_map(pixel_pos):
|
||||||
|
return
|
||||||
var actual_levels = color_to_levels(image.get_pixelv(pixel_pos))
|
var actual_levels = color_to_levels(image.get_pixelv(pixel_pos))
|
||||||
var modification_levels = modification_to_levels(stat, modification)
|
var modification_levels = modification_to_levels(stat, modification)
|
||||||
var calculated_levels = actual_levels + modification_levels
|
var calculated_levels = actual_levels + modification_levels
|
||||||
@ -93,6 +95,8 @@ func set_pixel(
|
|||||||
pixel_pos: Vector2i,
|
pixel_pos: Vector2i,
|
||||||
level: Vector3i,
|
level: Vector3i,
|
||||||
):
|
):
|
||||||
|
if not is_on_map(pixel_pos):
|
||||||
|
return
|
||||||
image.set_pixelv(pixel_pos, levels_to_color(level))
|
image.set_pixelv(pixel_pos, levels_to_color(level))
|
||||||
|
|
||||||
func modify_zone(
|
func modify_zone(
|
||||||
@ -142,6 +146,8 @@ func get_stat(
|
|||||||
pos: Vector2,
|
pos: Vector2,
|
||||||
stat : Stats
|
stat : Stats
|
||||||
) -> int:
|
) -> int:
|
||||||
|
if not is_on_map(pos):
|
||||||
|
return 0
|
||||||
var pixel_pos = map_to_pixel(pos)
|
var pixel_pos = map_to_pixel(pos)
|
||||||
var levels = color_to_levels(image.get_pixelv(pixel_pos))
|
var levels = color_to_levels(image.get_pixelv(pixel_pos))
|
||||||
match stat:
|
match stat:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user