Dev Démo 1.2
* les plantes se placent désormais sur une grille * ajouts de curseurs relatifs à l'item * ajout de settings sur la sensibilité à la souris * ajout d'un défi en fin de run
This commit is contained in:
@@ -12,8 +12,7 @@ signal player_updated(player: Player)
|
||||
signal upgraded
|
||||
|
||||
var terrain : Terrain
|
||||
var region : Region :
|
||||
get(): return terrain if terrain is Region else null
|
||||
@export var region : Region
|
||||
|
||||
var data : PlayerData
|
||||
var last_action_area_movement_timer : float = 100.
|
||||
@@ -91,11 +90,16 @@ func _process(delta):
|
||||
instruction.do(self)
|
||||
instruction = null
|
||||
|
||||
|
||||
if instruction and instruction.need_movement:
|
||||
if input_direction.length() != 0:
|
||||
instruction = null
|
||||
input_direction = calculate_direction_instruction_direction()
|
||||
|
||||
if instruction == null and action_zone:
|
||||
action_zone.destroy()
|
||||
action_zone = null
|
||||
|
||||
velocity = input_direction * SPEED
|
||||
turn_animate(input_direction)
|
||||
|
||||
@@ -286,8 +290,8 @@ func recharge(amount : int = data.max_energy):
|
||||
func full_recharge():
|
||||
data.energy = max(data.energy, data.max_energy)
|
||||
|
||||
func generate_action_zone(item : Item) -> ActionZone:
|
||||
var zone = ActionZone.new(item)
|
||||
func generate_action_zone(item : Item, preview = true) -> ActionZone:
|
||||
var zone = ActionZone.new(item, region.plant_grid, preview)
|
||||
|
||||
if not get_parent().is_node_ready():
|
||||
await get_parent().ready
|
||||
@@ -303,12 +307,12 @@ func setup_preview_zone(item : Item):
|
||||
preview_zone = null
|
||||
|
||||
if item:
|
||||
preview_zone = await generate_action_zone(item)
|
||||
preview_zone = await generate_action_zone(item, true)
|
||||
|
||||
func setup_action_zone(zone_position : Vector2, item: Item) -> ActionZone:
|
||||
if action_zone:
|
||||
action_zone.destroy()
|
||||
action_zone = await generate_action_zone(item)
|
||||
action_zone = await generate_action_zone(item, false)
|
||||
action_zone.move_to_position(zone_position)
|
||||
last_action_area_movement_timer = 0.
|
||||
return action_zone
|
||||
@@ -316,6 +320,7 @@ func setup_action_zone(zone_position : Vector2, item: Item) -> ActionZone:
|
||||
func move_preview_zone(zone_position : Vector2):
|
||||
if preview_zone:
|
||||
preview_zone.move_to_position(zone_position)
|
||||
preview_zone.update_preview(self)
|
||||
|
||||
class Instruction:
|
||||
|
||||
@@ -414,12 +419,21 @@ class InteractableInstruction extends Instruction:
|
||||
interactable.interact(player)
|
||||
|
||||
class ActionZone:
|
||||
const ZONE_ACTIVATED_COLOR = Color("#96B3DB")
|
||||
const ZONE_DEACTIVATED_COLOR = Color("#FF006E")
|
||||
const ZONE_OPACITY = 0.6
|
||||
|
||||
var item : Item = null
|
||||
var area : Area2D = Area2D.new()
|
||||
var affected_areas : Array[Area2D]= []
|
||||
var plant_grid : PlantGrid
|
||||
var circle : Circle
|
||||
var preview: bool
|
||||
|
||||
func _init(_i : Item):
|
||||
func _init(_i : Item, _grid : PlantGrid, _preview = false):
|
||||
item = _i
|
||||
plant_grid = _grid
|
||||
preview = _preview
|
||||
if item and item.get_usage_zone_radius() > 0:
|
||||
area = Area2D.new()
|
||||
var collision_shape = CollisionShape2D.new()
|
||||
@@ -429,11 +443,25 @@ class ActionZone:
|
||||
collision_shape.shape = circle_shape
|
||||
area.add_child(collision_shape)
|
||||
|
||||
circle = Circle.new(
|
||||
item.get_usage_zone_radius(),
|
||||
)
|
||||
circle.fill = preview
|
||||
circle.modulate.a = ZONE_OPACITY
|
||||
area.add_child(circle)
|
||||
circle.z_index = 100
|
||||
|
||||
func clear_preview_on_affected_area():
|
||||
for a in affected_areas:
|
||||
if a:
|
||||
a.affect_preview(false)
|
||||
|
||||
func update_preview(player : Player):
|
||||
update_preview_on_affected_area()
|
||||
if circle:
|
||||
circle.color = ZONE_ACTIVATED_COLOR if item.can_use(player, self) else ZONE_DEACTIVATED_COLOR
|
||||
|
||||
|
||||
func update_preview_on_affected_area():
|
||||
var detected_areas = get_affected_areas()
|
||||
clear_preview_on_affected_area()
|
||||
@@ -457,9 +485,13 @@ class ActionZone:
|
||||
return Vector2.ZERO if area == null else area.global_position
|
||||
|
||||
func move_to_position(pos : Vector2):
|
||||
if area:
|
||||
update_preview_on_affected_area()
|
||||
area.global_position = pos
|
||||
if area and plant_grid:
|
||||
if item and item.snap_usage_to_grid():
|
||||
area.global_position = plant_grid.get_point_for_tile(
|
||||
Math.get_tile_from_pos(pos)
|
||||
)
|
||||
else:
|
||||
area.global_position = pos
|
||||
|
||||
func get_tiles() -> Array[Vector2i]:
|
||||
return Math.get_tiles_in_circle(
|
||||
|
||||
Reference in New Issue
Block a user