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/Lightbulb/Lightbulb.gd

47 lines
1016 B
GDScript

tool
extends Area2D
enum Direction { LEFT, RIGHT, UP, DOWN }
export(Direction) var direction = Direction.DOWN setget set_direction
export var lit = true setget set_lit
func _ready():
$Light2D.set_meta("_edit_lock_", true)
func set_direction(dir):
direction = dir
refresh_sprite()
func set_lit(val):
lit = val
$Light2D.enabled = val
refresh_sprite()
func refresh_sprite():
var lit_offset = 0
if not lit:
lit_offset = 32
match direction:
Direction.DOWN:
$light.region_rect.position = Vector2(32, lit_offset)
$Light2D.rotation = 0
Direction.UP:
$light.region_rect.position = Vector2(0, lit_offset)
$Light2D.rotation = PI
Direction.LEFT:
$light.region_rect.position = Vector2(96, lit_offset)
$Light2D.rotation = -PI/2
Direction.RIGHT:
$light.region_rect.position = Vector2(64, lit_offset)
$Light2D.rotation = PI/2
func _input_event(viewport, event, shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
set_lit(!lit)