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)
|
||||
|
||||
@@ -8,14 +8,14 @@ const BORDER_WIDTH = 100
|
||||
var terrain_size = Vector2.ONE * 1000 :
|
||||
set(v):
|
||||
terrain_size = v
|
||||
if borderLimit:
|
||||
borderLimit.queue_free()
|
||||
borderLimit = create_border_limit()
|
||||
if border_limit:
|
||||
border_limit.queue_free()
|
||||
border_limit = create_border_limit()
|
||||
|
||||
@onready var borderLimit : StaticBody2D = create_border_limit()
|
||||
@onready var entityContainer : Node2D = create_entity_container()
|
||||
@onready var border_limit : StaticBody2D = create_border_limit()
|
||||
@onready var entity_container : Node2D = create_entity_container()
|
||||
|
||||
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)
|
||||
|
||||
@@ -52,14 +52,14 @@ func drop_item(item: Item, item_position : Vector2, random_displacement_factor =
|
||||
return item_object
|
||||
|
||||
func create_border_limit() -> StaticBody2D:
|
||||
var staticBody = StaticBody2D.new()
|
||||
var staticBodyCollision = CollisionPolygon2D.new()
|
||||
var static_body = StaticBody2D.new()
|
||||
var static_body_collision = CollisionPolygon2D.new()
|
||||
|
||||
add_child(staticBody)
|
||||
staticBody.add_child(staticBodyCollision)
|
||||
add_child(static_body)
|
||||
static_body.add_child(static_body_collision)
|
||||
|
||||
var size = terrain_size
|
||||
staticBodyCollision.polygon = PackedVector2Array([
|
||||
static_body_collision.polygon = PackedVector2Array([
|
||||
Vector2(0,0),
|
||||
Vector2(0, size.y),
|
||||
Vector2(size.x, size.y),
|
||||
@@ -72,4 +72,4 @@ func create_border_limit() -> StaticBody2D:
|
||||
Vector2(-BORDER_WIDTH, -BORDER_WIDTH)
|
||||
])
|
||||
|
||||
return staticBody
|
||||
return static_body
|
||||
|
||||
Reference in New Issue
Block a user