120 lines
2.7 KiB
GDScript
120 lines
2.7 KiB
GDScript
extends Node2D
|
|
|
|
class_name GroundItem
|
|
|
|
@export var itemClass:Resource
|
|
@export var keyItem:bool = false
|
|
var item:Item
|
|
|
|
var interactingTerrains = []
|
|
|
|
var inWater = false
|
|
var sinking = false
|
|
var sinkingSpeed = 0.35
|
|
var bobbingDelay = 0.8
|
|
|
|
var noTerrainCheckDelay = 0
|
|
|
|
var visibleDelay = 0.05
|
|
|
|
func _ready():
|
|
visible = false
|
|
if itemClass != null:
|
|
set_item(itemClass.new())
|
|
|
|
func assume_water_start(water):
|
|
$Waves.visible = true
|
|
$Waves.self_modulate = water.liquidColor
|
|
$WhiteCircle.visible = false
|
|
|
|
if water.viscosity < item.get_hardness():
|
|
$Waves.visible = false
|
|
|
|
noTerrainCheckDelay = 0.5
|
|
|
|
func set_item(newItem:Item):
|
|
item = newItem
|
|
$ItemSprite.texture = item.get_sprite()
|
|
|
|
func _process(delta):
|
|
if visibleDelay > 0:
|
|
visibleDelay -= delta
|
|
if visibleDelay <= 0:
|
|
visible = true
|
|
|
|
if "Balloon" in item.get_name():
|
|
var outside = LocationManager.currentLocation.outside
|
|
if outside == null or outside == false:
|
|
pass
|
|
else:
|
|
self.translate(Vector2(5, -120)*delta)
|
|
if position.y < LocationManager.currentLocation.upperCameraLimit:
|
|
AchievementManager.complete_achievement("Into the Clouds")
|
|
queue_free()
|
|
else:
|
|
handle_terrain(delta)
|
|
|
|
func handle_terrain(delta):
|
|
var mainTerrain = null
|
|
for terrain in interactingTerrains:
|
|
if mainTerrain == null or terrain.viscosity > mainTerrain.viscosity:
|
|
mainTerrain = terrain
|
|
|
|
if noTerrainCheckDelay > 0:
|
|
noTerrainCheckDelay -= delta
|
|
|
|
if mainTerrain == null:
|
|
if noTerrainCheckDelay <= 0:
|
|
if sinking:
|
|
stop_sinking()
|
|
$Waves.visible = false
|
|
$WhiteCircle.visible = true
|
|
return
|
|
|
|
if mainTerrain is SwimmingZone:
|
|
$Waves.visible = true
|
|
$Waves.self_modulate = mainTerrain.liquidColor
|
|
|
|
$WhiteCircle.visible = false
|
|
|
|
if !(Item.modifications.Wet in item.itemModifications):
|
|
item.set_modification(Item.modifications.Wet)
|
|
$ItemSprite.texture = item.get_sprite()
|
|
|
|
bobbingDelay -= delta
|
|
if bobbingDelay <= 0:
|
|
bobbingDelay = 0.8
|
|
if $ItemSprite.position.y == -16:
|
|
$ItemSprite.position.y = -18
|
|
else:
|
|
$ItemSprite.position.y = -16
|
|
else:
|
|
$Waves.visible = false
|
|
$WhiteCircle.visible = true
|
|
|
|
if sinking:
|
|
$Waves.visible = false
|
|
if mainTerrain.viscosity >= item.get_hardness():
|
|
stop_sinking()
|
|
else:
|
|
modulate.a = modulate.a - (delta * sinkingSpeed)
|
|
if modulate.a <= 0:
|
|
remove_self()
|
|
else:
|
|
if mainTerrain.viscosity < item.get_hardness():
|
|
if item.get_name(false) != "Worm on a String" and item.get_name(false) != "Basket on a String":
|
|
start_sinking()
|
|
|
|
func stop_sinking():
|
|
self_modulate.a = 1
|
|
sinking = false
|
|
|
|
func start_sinking():
|
|
sinking = true
|
|
|
|
func remove_self():
|
|
if GameVariables.player.currentInteractingGroundItem == self:
|
|
GameVariables.player.change_state("Idle")
|
|
|
|
queue_free()
|