42 lines
998 B
GDScript
42 lines
998 B
GDScript
extends Area2D
|
|
class_name ActionArea
|
|
|
|
const OPACITY = 0.4
|
|
const ACTIVATED_COLOR = Color.TURQUOISE
|
|
const DEACTIVATED_COLOR = Color.REBECCA_PURPLE
|
|
|
|
var collision_shape : CollisionShape2D = null
|
|
var area_width : float
|
|
var area_max_distance : float
|
|
var player : Player
|
|
|
|
var activated : bool = false
|
|
|
|
func _init(
|
|
_player: Player,
|
|
_area_width : float = 40,
|
|
):
|
|
player = _player
|
|
area_width = _area_width
|
|
|
|
func _ready():
|
|
collision_shape = CollisionShape2D.new()
|
|
collision_shape.shape = CircleShape2D.new()
|
|
collision_shape.shape.radius = area_width
|
|
add_child(collision_shape)
|
|
|
|
func _process(_delta):
|
|
var target_position = get_global_mouse_position() - player.global_position
|
|
if Vector2.ONE.distance_to(target_position) > player.max_reach:
|
|
target_position = Vector2.ZERO.direction_to(target_position)*player.max_reach
|
|
|
|
position = target_position
|
|
queue_redraw()
|
|
|
|
func _draw():
|
|
draw_circle(
|
|
Vector2.ZERO,
|
|
area_width,
|
|
Color((ACTIVATED_COLOR if activated else DEACTIVATED_COLOR), OPACITY)
|
|
)
|