crabs-game/scripts/oil_tanker.gd

74 lines
2.1 KiB
GDScript

extends Node2D
#0
onready var oil_tanker = $OilTanker
#1
onready var oil_tanker_inside_1 = $InsideOilTanker
onready var player_1 = $InsideOilTanker/Player
onready var next_trigger_1 = $InsideOilTanker/NextTrigger
#2
onready var oil_tanker_inside_2 = $InsideOilTanker2
onready var camera_2 = $InsideOilTanker2/Camera2D
onready var player_2 = $InsideOilTanker2/Player
onready var prop1 = $InsideOilTanker2/Parallax/Prop1
onready var prop2 = $InsideOilTanker2/Parallax/Prop2
onready var next_trigger_2 = $InsideOilTanker2/NextTrigger
#3
onready var herbert_must_go_3 = $HerbertMustGo
func _ready():
oil_tanker.connect('animation_finished', self, 'end_step_0')
next_trigger_1.connect("body_entered", self, 'end_step_1')
next_trigger_2.connect("body_entered", self, 'end_step_2')
# oil_tanker.frame = 12
# end_step_0()
# end_step_1(player_1)
func end_step_0():
print('end_step_0')
if oil_tanker.frame > 1:
oil_tanker.queue_free()
player_1.sleep = false
func end_step_1(body : Node):
print('end_step_1')
if body.name == "Player":
oil_tanker_inside_1.queue_free()
player_2.sleep = false
camera_2.current = true
func end_step_2(body : Node):
print('end_step_2')
if body.name == "Player":
oil_tanker_inside_2.queue_free()
herbert_must_go_3.play('default')
yield(get_tree().create_timer(5), "timeout")
get_tree().change_scene("res://scenes/campfire2.tscn")
func _input(event):
if oil_tanker != null:
if event.is_action_pressed('right'):
if !oil_tanker.is_playing():
oil_tanker.play('default')
if event.is_action_released('right'):
oil_tanker.stop()
if event.is_action_pressed('left'):
if !oil_tanker.is_playing() && oil_tanker.frame > 0:
oil_tanker.play('default', true)
if event.is_action_released('left'):
oil_tanker.stop()
func _process(delta):
if player_2 != null && !player_2.sleep:
var screen_width = ProjectSettings.get_setting("display/window/size/width")
camera_2.position.x = floor(clamp(player_2.position.x - screen_width / 2.0, 0, oil_tanker_inside_2.texture.get_width() - screen_width))
prop2.position.x = floor((260 - camera_2.position.x) * 0.5)
prop1.position.x = floor((300 - camera_2.position.x) * 0.75)