45 lines
940 B
GDScript
45 lines
940 B
GDScript
extends Area2D
|
|
class_name ActionArea
|
|
|
|
const OPACITY = 0.3
|
|
const ACTIVATED_COLOR = Color.TURQUOISE
|
|
const DEACTIVATED_COLOR = Color.REBECCA_PURPLE
|
|
|
|
var collision_shape : CollisionShape2D = null
|
|
var area_width : float = 40
|
|
var area_distance : float = 80
|
|
|
|
var activated : bool = false :
|
|
set(v):
|
|
var old = activated
|
|
activated = v
|
|
if old != activated:
|
|
queue_redraw()
|
|
|
|
func _init(
|
|
_area_width : float = 40,
|
|
_area_distance : float = 80
|
|
):
|
|
area_width = _area_width
|
|
area_distance = _area_distance
|
|
|
|
func _ready():
|
|
collision_shape = CollisionShape2D.new()
|
|
collision_shape.position.x = area_distance
|
|
collision_shape.shape = CircleShape2D.new()
|
|
collision_shape.shape.radius = area_width
|
|
add_child(collision_shape)
|
|
|
|
func _process(_delta):
|
|
look_at(get_global_mouse_position())
|
|
|
|
func _draw():
|
|
draw_circle(
|
|
Vector2(
|
|
area_distance,
|
|
0
|
|
),
|
|
area_width,
|
|
Color((ACTIVATED_COLOR if activated else DEACTIVATED_COLOR), OPACITY)
|
|
)
|