149 lines
5.1 KiB
GDScript
149 lines
5.1 KiB
GDScript
extends Node2D
|
|
|
|
#enum { PLAYING, GOING_IN, INSIDE, COMING_OUT}
|
|
#var status = PLAYING
|
|
|
|
enum Phase { START, CLEAN, KNIFE, HEATER, POISON, POISON_MUTATE, SQUID, ANGLER, NEXT }
|
|
var phase = Phase.START
|
|
|
|
|
|
func _ready() -> void:
|
|
randomize()
|
|
modulate = Color(0,0,0,1)
|
|
blackout()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
# if event.is_action_pressed("skip"):
|
|
# blackout() #glitchy af, don't use unless I refactor code entirely
|
|
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
|
|
if $Fish.dash_mutation:
|
|
$Fish.dash()
|
|
elif $Fish.poison_mutation:
|
|
$Fish.fire_pellet() # Fire a pellet if appropriate and able
|
|
|
|
|
|
static func random_position(area: CollisionShape2D) -> Vector2:
|
|
var _topleft : Vector2 = area.global_position - area.shape.extents
|
|
var _botright : Vector2 = area.global_position + area.shape.extents
|
|
var _x = rand_range(_topleft.x, _botright.x)
|
|
var _y = rand_range(_topleft.y, _botright.y)
|
|
return Vector2(_x, _y)
|
|
|
|
|
|
func _on_HazardTimer_timeout() -> void:
|
|
if phase == Phase.CLEAN or phase == Phase.POISON or phase == Phase.SQUID:
|
|
var poison_scene = load("res://Hazards/Poison/Poison.tscn")
|
|
var poison = poison_scene.instance()
|
|
if phase == Phase.CLEAN:
|
|
poison.modulate = Color(1,1,1,1)
|
|
add_child(poison)
|
|
poison.position = random_position($HazardSpawner)
|
|
|
|
|
|
func blackout() -> void:
|
|
$Fish/ThoughtBubble.visible = false
|
|
if not phase == Phase.START:
|
|
yield($Fish.go_inside(), "completed")
|
|
if not modulate == Color(0,0,0,1):
|
|
$TweenBlackout.interpolate_property(self, "modulate", modulate, Color(0,0,0,1), 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
|
$TweenBlackout.start()
|
|
yield($TweenBlackout, "tween_completed")
|
|
next_phase()
|
|
$House/HouseEyes.visible = false
|
|
$House/HouseRight.z_index = $House/HouseLeft.z_index
|
|
if phase == Phase.SQUID:
|
|
var squid_scene = load("res://Hazards/Squid/Squid.tscn")
|
|
var squid = squid_scene.instance()
|
|
add_child(squid)
|
|
$Fish.poison_mutation = true
|
|
print("Squid phase starting.")
|
|
if phase == Phase.POISON_MUTATE:
|
|
$Fish.poison_mutating = true
|
|
var poison_scene = load("res://Hazards/Poison/Poison.tscn")
|
|
var poison = poison_scene.instance()
|
|
add_child(poison)
|
|
poison.position = $House/LeftEntrance.get_global_position()
|
|
print("Poison mutation starting.")
|
|
if phase == Phase.POISON:
|
|
for piranha in get_tree().get_nodes_in_group("Piranha"):
|
|
piranha.queue_free()
|
|
$SurviveTimer.start()
|
|
print("Poison phase starting.")
|
|
if phase == Phase.HEATER:
|
|
var heater_scene = load("res://Hazards/Heater/Heater.tscn")
|
|
var heater = heater_scene.instance()
|
|
add_child(heater)
|
|
if phase == Phase.KNIFE:
|
|
var fork_scene = load("res://Hazards/Fork/Fork.tscn")
|
|
var fork = fork_scene.instance()
|
|
add_child(fork)
|
|
if not phase == Phase.CLEAN:
|
|
$Fish.position = $House/RightEntrance.get_global_position() + Vector2(0,-100)
|
|
$Fish.global_rotation_degrees = 180
|
|
$Fish/AnimatedSprite.flip_v = true
|
|
$Fish.visible = true
|
|
$Fish.destination = $House/LeftEntrance.get_global_position()+Vector2(0,-100)
|
|
$Fish/TweenSwim.interpolate_property($Fish, "position", $Fish.get_global_position(), $House/LeftEntrance.get_global_position()+Vector2(0,-100), 2, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
$Fish/TweenSwim.start()
|
|
$TweenBlackout.interpolate_property(self, "modulate", modulate, Color(1,1,1,1), 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
|
$TweenBlackout.start()
|
|
yield($TweenBlackout, "tween_completed")
|
|
|
|
if not phase == Phase.KNIFE:
|
|
$Fish.invincible = false
|
|
|
|
_think()
|
|
|
|
|
|
func next_phase() -> void:
|
|
if phase == Phase.CLEAN: # Clean tank of pellets before poison phase
|
|
for pellet in get_tree().get_nodes_in_group("Pellets"):
|
|
pellet.queue_free()
|
|
if phase == Phase.KNIFE: # Clean tank of poison before fork phase
|
|
for pellet in get_tree().get_nodes_in_group("Pellets"):
|
|
pellet.queue_free()
|
|
if phase == Phase.HEATER: #
|
|
for knife in get_tree().get_nodes_in_group("Knife"):
|
|
knife.queue_free()
|
|
for fork in get_tree().get_nodes_in_group("Fork"):
|
|
fork.queue_free()
|
|
phase += 1
|
|
|
|
|
|
func _think() -> void:
|
|
var thought = $Fish/ThoughtBubble/Thought
|
|
$Fish/ThoughtBubble/ThoughtTimer.start()
|
|
if phase == Phase.CLEAN:
|
|
$Fish/ThoughtBubble.visible = true
|
|
thought.bbcode_text = \
|
|
"\n[center][tornado]ooOOoo! " + \
|
|
"Does it really rain yummy treats in here? :D"
|
|
elif phase == Phase.KNIFE:
|
|
$Fish/ThoughtBubble.visible = true
|
|
thought.bbcode_text = \
|
|
"[center]WTF?! That was close!! Let's turn this tragedy into " + \
|
|
"a travesty!\n([rainbow]DASH[/rainbow] unlocked!)"
|
|
elif phase == Phase.POISON:
|
|
$Fish/ThoughtBubble.visible = true
|
|
thought.bbcode_text = \
|
|
"\n[center]Wait, something's wrong with these flakes!\n" + \
|
|
"[shake]Must... resist... eating...!"
|
|
elif phase == Phase.POISON_MUTATE:
|
|
$Fish/ThoughtBubble.visible = true
|
|
thought.bbcode_text = \
|
|
"[center]Actually... if I, erm, 'process' these fast enough...\n" + \
|
|
"Tragedy begets travesty once again!\n" + \
|
|
"([rainbow]TAIL CANNON[/rainbow] unlocked!)"
|
|
elif phase == Phase.SQUID:
|
|
$Fish/ThoughtBubble.visible = true
|
|
thought.bbcode_text = \
|
|
"[center]HOLY F--! Well I hope it likes poison!"
|
|
|
|
# Tween the $Thought.bbcode_text's percent_visible property
|
|
|
|
|
|
func _on_SurviveTimer_timeout() -> void:
|
|
print("Time's up! Moving to next phase.")
|
|
blackout()
|