#24 et #21 ajout d'une plante générique, et d'un cycle de recharge du robot avec croissance des plantes
This commit is contained in:
66
entities/plants/scripts/plant.gd
Normal file
66
entities/plants/scripts/plant.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
extends Node2D
|
||||
class_name Plant
|
||||
|
||||
const PLANT_AREA_WIDTH = 10
|
||||
const PLANT_SPRITE_SCALE = 0.15
|
||||
|
||||
enum State {PLANTED, GROWING, MATURE}
|
||||
|
||||
var plant_type : PlantType
|
||||
var planet : Planet
|
||||
|
||||
var state : State = State.PLANTED : set = change_state
|
||||
var day : int = 0
|
||||
|
||||
@onready var plant_sprite : Sprite2D = generate_sprite()
|
||||
@onready var plant_area : Area2D = generate_area()
|
||||
|
||||
func _init(_plant_type, _planet):
|
||||
plant_type = _plant_type
|
||||
planet = _planet
|
||||
|
||||
func generate_sprite() -> Sprite2D:
|
||||
var sprite = Sprite2D.new()
|
||||
|
||||
add_child(sprite)
|
||||
sprite.texture = get_state_texture(state)
|
||||
sprite.scale = Vector2.ONE * PLANT_SPRITE_SCALE
|
||||
sprite.offset
|
||||
|
||||
return sprite
|
||||
|
||||
func generate_area() -> Area2D:
|
||||
var area = Area2D.new()
|
||||
var collision = CollisionShape2D.new()
|
||||
var collision_shape = CircleShape2D.new()
|
||||
collision_shape.radius = PLANT_AREA_WIDTH
|
||||
|
||||
collision.shape = collision_shape
|
||||
area.add_child(collision)
|
||||
add_child(area)
|
||||
|
||||
return area
|
||||
|
||||
func pass_day():
|
||||
day += 1
|
||||
if day > plant_type.growing_time:
|
||||
change_state(State.MATURE)
|
||||
else:
|
||||
change_state(State.GROWING)
|
||||
|
||||
func change_state(_state : State):
|
||||
state = _state
|
||||
plant_sprite.texture = get_state_texture(state)
|
||||
|
||||
if state == State.MATURE and plant_type.mature_effect:
|
||||
plant_type.mature_effect.effect(self)
|
||||
|
||||
func get_state_texture(s : State) -> Texture2D:
|
||||
match s:
|
||||
State.PLANTED:
|
||||
return plant_type.planted_texture
|
||||
State.GROWING:
|
||||
return plant_type.growing_texture
|
||||
State.MATURE:
|
||||
return plant_type.mature_texture
|
||||
return null
|
||||
1
entities/plants/scripts/plant.gd.uid
Normal file
1
entities/plants/scripts/plant.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cega715smavh3
|
||||
7
entities/plants/scripts/plant_effect.gd
Normal file
7
entities/plants/scripts/plant_effect.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
# Classe abstraite permettant de développer divers effets de plantes
|
||||
extends Resource
|
||||
class_name PlantEffect
|
||||
|
||||
func effect(plant):
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
|
||||
1
entities/plants/scripts/plant_effect.gd.uid
Normal file
1
entities/plants/scripts/plant_effect.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bpycohqas4hff
|
||||
@@ -0,0 +1,10 @@
|
||||
extends PlantEffect
|
||||
class_name DecontaminateTerrainEffect
|
||||
|
||||
@export var impact_radius = 50
|
||||
|
||||
func effect(plant):
|
||||
plant.planet.impact_contamination(
|
||||
plant.global_position,
|
||||
impact_radius
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cgscbuxe4dawb
|
||||
11
entities/plants/scripts/plant_type.gd
Normal file
11
entities/plants/scripts/plant_type.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Resource
|
||||
class_name PlantType
|
||||
|
||||
@export var growing_time : int
|
||||
|
||||
@export var seed_texture : Texture
|
||||
@export var planted_texture : Texture
|
||||
@export var growing_texture : Texture
|
||||
@export var mature_texture : Texture
|
||||
|
||||
@export var mature_effect : PlantEffect
|
||||
1
entities/plants/scripts/plant_type.gd.uid
Normal file
1
entities/plants/scripts/plant_type.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jnye5pe1bgqw
|
||||
Reference in New Issue
Block a user