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

56 lines
1.2 KiB
GDScript

tool
extends StaticBody2D
class_name GameObjectEngine
const LIGHT_STRENGTH_MULT = 0.002
const MAX_ENERGY = 2
enum Direction { LEFT, RIGHT, UP, DOWN }
export(Direction) var direction = Direction.DOWN setget set_direction
onready var activationRange = $ActivationRange as ActivationRange
export var strength = 1.0 setget set_strength
func _ready():
if not Engine.editor_hint:
activationRange.visible = true
func set_direction(dir):
direction = dir
refresh_sprite()
func set_strength(val):
strength = val
$Light2D.energy = val * LIGHT_STRENGTH_MULT
func refresh_sprite():
var rot = 0
match direction:
Direction.DOWN:
$engine.region_rect.position = Vector2(0, 0)
rot = 0
Direction.UP:
$engine.region_rect.position = Vector2(0, 96)
rot = PI
Direction.LEFT:
$engine.region_rect.position = Vector2(96, 96)
rot = PI/2
Direction.RIGHT:
$engine.region_rect.position = Vector2(96, 0)
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():
# TODO
pass