This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Actors/Objects/Lightbulb/Lightbulb.gd

54 lines
1.2 KiB
GDScript

tool
extends Area2D
class_name GameObjectLightbulb
enum Direction { LEFT, RIGHT, UP, DOWN }
export(Direction) var direction = Direction.DOWN setget set_direction
export var lit = true setget set_lit
onready var activationRange = $ActivationRange as ActivationRange
func _ready():
if not Engine.editor_hint:
activationRange.visible = true
func set_direction(dir):
direction = dir
refresh_sprite()
func set_lit(val):
lit = val
$Light2D.enabled = val
refresh_sprite()
func refresh_sprite():
var rot = 0
var lit_offset = 0
if not lit:
lit_offset = 32
match direction:
Direction.DOWN:
$light.region_rect.position = Vector2(32, lit_offset)
rot =0
Direction.UP:
$light.region_rect.position = Vector2(0, lit_offset)
rot = PI
Direction.LEFT:
$light.region_rect.position = Vector2(96, lit_offset)
rot = -PI/2
Direction.RIGHT:
$light.region_rect.position = Vector2(64, lit_offset)
rot = PI/2
$Light2D.rotation = rot
$ActivationRange.rotation = rot
func _input_event(_viewport, event, _shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
if activationRange.in_range():
set_lit(!lit)