Use a line for unit move instead of moving the sprite
This commit is contained in:
parent
ee2b9d4dac
commit
751dc87e40
|
@ -12,13 +12,13 @@ export var base_hull_points = 0 setget set_base_hull_points
|
||||||
export var base_shield_points = 0 setget set_base_shield_points
|
export var base_shield_points = 0 setget set_base_shield_points
|
||||||
export var base_damage_points = 0 setget set_base_damage_points
|
export var base_damage_points = 0 setget set_base_damage_points
|
||||||
|
|
||||||
var dragged = false
|
|
||||||
var base_position
|
|
||||||
var selected_anchor
|
var selected_anchor
|
||||||
|
var dragged
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
$move_hint.visible = false
|
||||||
|
|
||||||
set_sprite(sprite)
|
set_sprite(sprite)
|
||||||
base_position = rect_position
|
|
||||||
|
|
||||||
set_base_damage_points(base_damage_points)
|
set_base_damage_points(base_damage_points)
|
||||||
set_base_move_points(base_move_points)
|
set_base_move_points(base_move_points)
|
||||||
|
@ -66,8 +66,8 @@ func can_be_used_on_anchor(anchor):
|
||||||
return anchor is Anchor and anchor.is_connected_to(get_parent()) and (anchor.is_empty() or can_target(anchor.get_content()))
|
return anchor is Anchor and anchor.is_connected_to(get_parent()) and (anchor.is_empty() or can_target(anchor.get_content()))
|
||||||
|
|
||||||
func update_anchors():
|
func update_anchors():
|
||||||
var position = rect_global_position + rect_size / 2 if dragged else null
|
var cursor = rect_global_position + dragged if dragged else null
|
||||||
selected_anchor = BattleHelper.update_anchors(get_tree(), position, funcref(self, "can_be_used_on_anchor"))
|
selected_anchor = BattleHelper.update_anchors(get_tree(), cursor, funcref(self, "can_be_used_on_anchor"))
|
||||||
|
|
||||||
func play(anchor):
|
func play(anchor):
|
||||||
if anchor.is_empty():
|
if anchor.is_empty():
|
||||||
|
@ -85,7 +85,6 @@ func play(anchor):
|
||||||
|
|
||||||
func move_to(anchor):
|
func move_to(anchor):
|
||||||
anchor.set_content(self)
|
anchor.set_content(self)
|
||||||
rect_position = base_position
|
|
||||||
|
|
||||||
func get_points() -> UnitPoints:
|
func get_points() -> UnitPoints:
|
||||||
if $points is UnitPoints:
|
if $points is UnitPoints:
|
||||||
|
@ -121,23 +120,27 @@ func attack(other) -> bool:
|
||||||
return selfpoints.hull > 0 && otherpoints.hull == 0
|
return selfpoints.hull > 0 && otherpoints.hull == 0
|
||||||
|
|
||||||
func return_to_base():
|
func return_to_base():
|
||||||
AnimHelper.linear_goto(self, base_position, 0.3)
|
dragged = null
|
||||||
|
$move_hint.visible = false
|
||||||
|
$move_hint.set_point_position(1, Vector2(0, 0))
|
||||||
|
|
||||||
func _gui_input(event):
|
func _gui_input(event):
|
||||||
if event is InputEventMouseButton and event.button_index == 1:
|
if event is InputEventMouseButton and event.button_index == 1:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
dragged = true
|
dragged = event.position
|
||||||
modulate = Color(1, 1, 1, 0.5)
|
$move_hint.visible = true
|
||||||
elif dragged:
|
elif dragged:
|
||||||
dragged = false
|
dragged = null
|
||||||
modulate = Color(1, 1, 1, 1)
|
$move_hint.visible = false
|
||||||
if selected_anchor:
|
if selected_anchor:
|
||||||
play(selected_anchor)
|
play(selected_anchor)
|
||||||
else:
|
else:
|
||||||
return_to_base()
|
return_to_base()
|
||||||
|
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion and event.button_mask == BUTTON_LEFT:
|
||||||
if event.button_mask == BUTTON_LEFT:
|
dragged = event.position
|
||||||
set_position(rect_position + event.relative)
|
|
||||||
|
|
||||||
update_anchors()
|
update_anchors()
|
||||||
|
|
||||||
|
if dragged:
|
||||||
|
$move_hint.set_point_position(1, selected_anchor.global_position - rect_global_position if selected_anchor else dragged)
|
||||||
|
|
|
@ -29,3 +29,7 @@ anchor_right = 0.5
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 0.5
|
||||||
margin_top = 70.0
|
margin_top = 70.0
|
||||||
margin_bottom = 115.0
|
margin_bottom = 115.0
|
||||||
|
|
||||||
|
[node name="move_hint" type="Line2D" parent="."]
|
||||||
|
points = PoolVector2Array( 50, 50, 0, 0 )
|
||||||
|
antialiased = true
|
||||||
|
|
Loading…
Reference in a new issue