#57 rework des inputs et actions

This commit is contained in:
2025-09-05 15:11:29 +02:00
parent 3d0104ed4a
commit 2dc365736f
21 changed files with 490 additions and 358 deletions

View File

@@ -67,10 +67,16 @@ func get_contamination(point : Vector2) -> float:
Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
- Vector2.ONE / 2
)
return contamination.get_pixel(
int(round(pixel_point.x)),
int(round(pixel_point.y))
).r
if (
pixel_point.x > 0
and pixel_point.y > 0
and pixel_point.x < contamination.get_width()
and pixel_point.y < contamination.get_height()):
return contamination.get_pixel(
int(round(pixel_point.x)),
int(round(pixel_point.y))
).r
return 0
func get_decontamination_coverage() -> float:
return ImageTools.get_color_coverage(contamination)

View File

@@ -5,7 +5,9 @@
[resource]
script = ExtResource("2_mgcdi")
plant_type = ""
name = "Boule"
description = ""
icon = ExtResource("1_dy25s")
use_zone_radius = 5
use_energy = 1
metadata/_custom_type_script = "uid://bypjcvlc15gsm"

View File

@@ -5,9 +5,9 @@
[resource]
script = ExtResource("1_28h2r")
area_width = 50.0
area_distance = 50.0
name = "Shovel"
description = "Can dig burried seed, and transform mature plants to seeds."
icon = ExtResource("1_7g3xd")
use_zone_radius = 50
use_energy = 1
metadata/_custom_type_script = "uid://dya38x1h1uiyg"

View File

@@ -45,6 +45,13 @@ func get_item(ind: int = 0) -> Item:
return null;
return items[ind]
func has_item(item : Item) -> bool:
return item in items
func remove_item(item : Item):
items.erase(item)
emit_signal("inventory_changed", self)
func pop_item(ind: int = 0) -> Item:
var item_removed: Item = items.pop_at(ind)
emit_signal("inventory_changed", self)
@@ -55,3 +62,4 @@ func swap_items(item_to_add: Item, ind_to_get: int = 0) -> Item:
items[ind_to_get] = item_to_add
emit_signal("inventory_changed", self)
return item_to_get

View File

@@ -4,21 +4,20 @@ class_name Item
@export var name: String
@export_multiline var description: String
@export var icon: Texture2D
@export var use_zone_radius: int = 5
@export var use_energy: int = 1
func is_one_time_use():
return false
func can_use(_player : Player) -> bool:
func can_use(_player : Player, zone: Area2D) -> bool:
return false
func use_text(_player) -> String:
func use_text() -> String:
return ""
func use_requirement_text() -> String:
return ""
func use(_player : Player):
func use(_player : Player, zone: Area2D):
return false
func generate_action_area(_player) -> ActionArea:
return null

View File

@@ -13,23 +13,15 @@ class_name Seed
func _init(_plant_type : PlantType = null):
plant_type = _plant_type
func generate_action_area(player : Player) -> ActionArea:
return ActionArea.new(
player,
10
)
func use_text(_player) -> String:
func use_text() -> String:
return "Plant " + plant_type.name
func is_one_time_use():
return true
func can_use(player : Player) -> bool:
return not player.planet.is_there_contamination(player.action_area.global_position)
func can_use(player : Player, zone : Area2D) -> bool:
return not player.planet.is_there_contamination(zone.global_position)
func use(player : Player) -> bool:
if not can_use(player):
return false
func use(player : Player, zone : Area2D) -> bool:
player.play_sfx("dig")
return player.planet.plant(plant_type, player.action_area.global_position)
return player.planet.plant(plant_type, zone.global_position)

View File

@@ -1,35 +1,32 @@
extends ToolItem
extends Item
class_name Shovel
const USE_INTERVAL = 0.15
func use_text(_player) -> String:
return "Dig"
func use_text() -> String:
return "Dig"
func can_use(player : Player) -> bool:
var areas = player.action_area.get_overlapping_areas()
for area in areas :
if area is Plant or area is UndergroundLoot:
return true
return false
func can_use(_player : Player, zone : Area2D) -> bool:
var areas = zone.get_overlapping_areas()
for area in areas :
if area is Plant or area is UndergroundLoot:
return true
return false
func use(player : Player) -> bool:
if not can_use(player):
return false
dig(
player.action_area.get_overlapping_areas(),
player
)
return true
func use(player : Player, zone : Area2D) -> bool:
dig(
zone.get_overlapping_areas(),
player
)
return true
func dig(areas: Array[Area2D], player: Player):
for area in areas :
if area is Plant:
player.play_sfx("harvest")
area.harvest()
if area is UndergroundLoot:
player.play_sfx("dig")
area.dig()
await player.get_tree().create_timer(USE_INTERVAL).timeout
for area in areas :
if area is Plant:
player.play_sfx("harvest")
area.harvest()
if area is UndergroundLoot:
player.play_sfx("dig")
area.dig()
await player.get_tree().create_timer(USE_INTERVAL).timeout

View File

@@ -1,10 +0,0 @@
extends Item
class_name ToolItem
@export var area_width: float = 50
func generate_action_area(player : Player) -> ActionArea:
return ActionArea.new(
player,
area_width
)

View File

@@ -1 +0,0 @@
uid://jom8ulyopso