divers changements pour la sortie du second proto
* ajout du panneau solaire #54 * ajout d'un tutoriel #53 * equilibrage du jeu #73 * ajout d'un son pour l'annonce
This commit is contained in:
169
gui/game/tutorial/scripts/tutorial.gd
Normal file
169
gui/game/tutorial/scripts/tutorial.gd
Normal file
@@ -0,0 +1,169 @@
|
||||
extends Control
|
||||
class_name Tutorial
|
||||
|
||||
const INDICATOR_SCENE = preload("res://gui/game/tutorial/in_game_indicator/in_game_indicator.tscn")
|
||||
|
||||
var indicators : Array[InGameIndicator]
|
||||
@export var camera : Camera2D
|
||||
@export var player : Player
|
||||
|
||||
@onready var steps : Array[Step] = [
|
||||
TakeShovelStep.new(),
|
||||
DigLootStep.new(),
|
||||
TakeSeedStep.new(),
|
||||
PlantSeedStep.new(),
|
||||
RechargeStep.new(),
|
||||
WaitMaturePlant.new(),
|
||||
HarvestMaturePlant.new(),
|
||||
]
|
||||
var actual_step : Step = null : set = pass_to_step
|
||||
|
||||
func _process(_d):
|
||||
if not GameInfo.game_data.tutorial_done:
|
||||
if not actual_step and len(steps):
|
||||
destroy_indicators()
|
||||
pass_to_step(steps.pop_front())
|
||||
|
||||
if player and actual_step and actual_step.is_step_over(player):
|
||||
destroy_indicators()
|
||||
if len(steps):
|
||||
pass_to_step(steps.pop_front())
|
||||
else :
|
||||
GameInfo.game_data.tutorial_done = true
|
||||
|
||||
func destroy_indicators():
|
||||
for i in indicators:
|
||||
i.queue_free()
|
||||
indicators = []
|
||||
|
||||
func pass_to_step(new_step : Step):
|
||||
actual_step = new_step
|
||||
indicators = new_step.generate_indicators(camera, player)
|
||||
for i in indicators:
|
||||
add_child(i)
|
||||
|
||||
class Step:
|
||||
func generate_indicator(cam : Camera2D, text : String) -> InGameIndicator:
|
||||
var new_indicator : InGameIndicator = INDICATOR_SCENE.instantiate()
|
||||
new_indicator.setup(
|
||||
cam,
|
||||
text
|
||||
)
|
||||
return new_indicator
|
||||
|
||||
func generate_indicators(_cam : Camera2D, _player : Player) -> Array[InGameIndicator]:
|
||||
return []
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
return true
|
||||
|
||||
class TakeShovelStep extends Step:
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is ItemObject and entity.item is Shovel:
|
||||
var indicator = generate_indicator(cam, "Take the Shovel")
|
||||
indicator.follow_entity(entity)
|
||||
return [
|
||||
indicator
|
||||
]
|
||||
printerr("No Shovel found...")
|
||||
return []
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
return p.inventory.length() > 0
|
||||
|
||||
class DigLootStep extends Step:
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
var indicators : Array[InGameIndicator] = []
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is UndergroundLoot:
|
||||
var indicator = generate_indicator(cam, "Dig Underground Loot")
|
||||
indicator.follow_entity(entity)
|
||||
indicators.append(
|
||||
indicator
|
||||
)
|
||||
return indicators
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is ItemObject and entity.item is Seed:
|
||||
return true
|
||||
return false
|
||||
|
||||
class TakeSeedStep extends Step:
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
var indicators : Array[InGameIndicator] = []
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is ItemObject and entity.item is Seed:
|
||||
var indicator = generate_indicator(cam, "Take a seed")
|
||||
indicator.follow_entity(entity)
|
||||
indicators.append(
|
||||
indicator
|
||||
)
|
||||
return indicators
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
for item in p.inventory.items:
|
||||
if item is Seed:
|
||||
return true
|
||||
return false
|
||||
|
||||
class PlantSeedStep extends Step:
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
var indicator = generate_indicator(cam, "Plant the seed in decontamined zone")
|
||||
indicator.follow_game_position(Vector2(60,60) + p.planet.entityContainer.global_position)
|
||||
return [indicator]
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is Plant:
|
||||
return true
|
||||
return false
|
||||
|
||||
class RechargeStep extends Step:
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
var indicator = generate_indicator(cam, "Recharge to pass days")
|
||||
indicator.follow_entity(entity)
|
||||
if entity is RechargeStation:
|
||||
return [
|
||||
indicator
|
||||
]
|
||||
printerr("No Recharge Station found...")
|
||||
return []
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
return p.planet.day > 1
|
||||
|
||||
class WaitMaturePlant extends Step:
|
||||
func generate_indicators(_cam : Camera2D, _p: Player) -> Array[InGameIndicator]:
|
||||
return []
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is Plant and entity.state == Plant.State.MATURE:
|
||||
return true
|
||||
return false
|
||||
|
||||
class HarvestMaturePlant extends Step:
|
||||
|
||||
var mature_plant_number : int = 0
|
||||
|
||||
func generate_indicators(cam : Camera2D, p: Player) -> Array[InGameIndicator]:
|
||||
var indicators : Array[InGameIndicator] = []
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is Plant and entity.state == Plant.State.MATURE:
|
||||
var indicator = generate_indicator(cam, "Harvest mature plants with shovel")
|
||||
indicator.follow_entity(entity)
|
||||
indicators.append(
|
||||
indicator
|
||||
)
|
||||
mature_plant_number += 1
|
||||
return indicators
|
||||
|
||||
func is_step_over(p : Player) -> bool:
|
||||
var actual_mature_plant_number = 0
|
||||
for entity in p.planet.entityContainer.get_children():
|
||||
if entity is Plant and entity.state == Plant.State.MATURE:
|
||||
actual_mature_plant_number += 1
|
||||
return mature_plant_number != actual_mature_plant_number
|
||||
Reference in New Issue
Block a user