ajout des mutation et refonte de l'inspecteur
* ajout des mutations #86 * changement de l'objectif #85 * refonte de l'inspecteur #71 * changement léger de la plantation * les plantes ne donnent que des graines de leurs espèces * refonte partielle du code, refacto
This commit is contained in:
@@ -31,6 +31,7 @@ const OBJECTIVE_MIN_ANGLE_DIFF = PI/2
|
||||
var background_sprite : Polygon2D
|
||||
var contamination_sprite : Polygon2D
|
||||
var decontamination_surface : float
|
||||
var garden_score : int
|
||||
|
||||
@onready var objective_scene : PackedScene = preload("res://entities/objectives/objective.tscn")
|
||||
|
||||
@@ -48,11 +49,18 @@ func _ready():
|
||||
planet_data = GameInfo.game_data.current_planet_data if GameInfo.game_data.current_planet_data else PlanetData.new()
|
||||
|
||||
terrain_size = planet_data.base_size
|
||||
entityContainer.position = terrain_size/2
|
||||
entity_container.position = terrain_size/2
|
||||
|
||||
background_sprite = generate_background_sprite()
|
||||
contamination_sprite = generate_contamination_terrain_sprite()
|
||||
decontamination_surface = planet_data.get_decontamination_surface()
|
||||
decontamination_surface = planet_data.get_decontamination_surface()
|
||||
GameInfo.game_data.current_planet_data_updated.connect(
|
||||
func (surface):
|
||||
if surface:
|
||||
decontamination_surface = surface
|
||||
)
|
||||
|
||||
garden_score = get_garden_score()
|
||||
|
||||
next_quota = planet_data.get_quota()
|
||||
days_on_last_quota = day
|
||||
@@ -95,7 +103,7 @@ func instantiate_machine(m_type : MachineType, level, machine_position : Vector2
|
||||
|
||||
machine.global_position = machine_position
|
||||
|
||||
func add_entity(e : Node2D, container : Node2D = entityContainer):
|
||||
func add_entity(e : Node2D, container : Node2D = entity_container):
|
||||
if e.get_parent():
|
||||
e.get_parent().remove_child(e)
|
||||
|
||||
@@ -155,16 +163,19 @@ func generate_contamination_terrain_sprite() -> Polygon2D:
|
||||
func plant(
|
||||
type : PlantType,
|
||||
plant_position : Vector2,
|
||||
plant_mutations : Array[PlantMutation] = []
|
||||
) -> bool:
|
||||
if is_there_contamination(plant_position):
|
||||
return false
|
||||
|
||||
var new_plant = Plant.new(
|
||||
type,
|
||||
self
|
||||
self,
|
||||
plant_mutations
|
||||
)
|
||||
add_entity(new_plant)
|
||||
new_plant.global_position = plant_position
|
||||
garden_score = get_garden_score()
|
||||
return true
|
||||
|
||||
func impact_contamination(impact_position : Vector2, impact_radius : int, contamination : bool = false):
|
||||
@@ -180,7 +191,7 @@ func is_there_contamination(point : Vector2) -> bool:
|
||||
return planet_data.get_contamination(point) < 0.5
|
||||
|
||||
func pass_day():
|
||||
for e : Node2D in entityContainer.get_children():
|
||||
for e : Node2D in entity_container.get_children():
|
||||
if e.has_method("_start_pass_day"):
|
||||
e._start_pass_day()
|
||||
pass_day_started.emit(self)
|
||||
@@ -189,18 +200,18 @@ func pass_day():
|
||||
generate_loot()
|
||||
pass_day_proceeded.emit(self)
|
||||
day += 1
|
||||
for e : Node2D in entityContainer.get_children():
|
||||
for e : Node2D in entity_container.get_children():
|
||||
if e.has_method("_pass_day"):
|
||||
e._pass_day()
|
||||
|
||||
pass_day_ended.emit(self)
|
||||
await get_tree().create_timer(PASS_DAY_ANIMATION_TIME/2.).timeout
|
||||
for e : Node2D in entityContainer.get_children():
|
||||
for e : Node2D in entity_container.get_children():
|
||||
if e.has_method("_end_pass_day"):
|
||||
e._end_pass_day()
|
||||
|
||||
decontamination_surface = planet_data.get_decontamination_surface()
|
||||
if decontamination_surface >= next_quota:
|
||||
garden_score = get_garden_score()
|
||||
if garden_score >= next_quota:
|
||||
reach_quota()
|
||||
|
||||
if get_quota_remaining_days() <= 0:
|
||||
@@ -274,6 +285,12 @@ func generate_quota_reward() -> Item:
|
||||
var random_machine_type = GameInfo.game_data.unlocked_machines.pick_random()
|
||||
return Blueprint.new(random_machine_type, random_level)
|
||||
|
||||
func get_garden_score():
|
||||
var score = 0
|
||||
for e in entity_container.get_children():
|
||||
if e is Plant:
|
||||
score += e.calculate_plant_score()
|
||||
return score
|
||||
|
||||
func choose_quota_reward(item : Item):
|
||||
drop_item(item, player.global_position, 100)
|
||||
|
||||
Reference in New Issue
Block a user