knight animation is done in 2 steps

This commit is contained in:
2ManyProjects 2025-02-08 16:50:49 -06:00
parent da29b64e49
commit fc9768d622
6 changed files with 38 additions and 8 deletions

View file

@ -41,12 +41,11 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
var tile_y = int(tile_name.split("-")[1]) var tile_y = int(tile_name.split("-")[1])
final_y = tile_y - y_direction final_y = tile_y - y_direction
break break
print("CHECKING TILES ", tiles_to_check)
# Process pieces in path # Process pieces in path
for tile_name in tiles_to_check: for tile_name in tiles_to_check:
var tile_y = int(tile_name.split("-")[1]) var tile_y = int(tile_name.split("-")[1])
# Only process tiles up to where we're stopping # Only process tiles up to where we're stopping
if (y_direction > 0 && tile_y > final_y) || (y_direction < 0 && tile_y < final_y):
break
var container = board_flow.get_node(tile_name) as PieceContainer var container = board_flow.get_node(tile_name) as PieceContainer
if container.has_piece(): if container.has_piece():
@ -54,7 +53,9 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
game_state.updatePointsAndCapture(piece_to_capture) game_state.updatePointsAndCapture(piece_to_capture)
# Move piece to final position # Move piece to final position
print("FINAL TILES ", str(current_x) + "-" + str(final_y))
var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer
print("FINAL TILES ", final_container.get_piece().Item_Color)
# Important: Need to remove the piece from its current container first # Important: Need to remove the piece from its current container first
# AND keep a reference to it # AND keep a reference to it

View file

@ -164,7 +164,6 @@ func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void:
else: else:
p2Points += capturedPiece.Points p2Points += capturedPiece.Points
p2String.text = str(p2Points) p2String.text = str(p2Points)
if animate: if animate:
animatePieceCapture(capturedPiece) animatePieceCapture(capturedPiece)

View file

@ -9,7 +9,6 @@ func _ready() -> void:
func enter(_previous: String, _data := {}) -> void: func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.MOVEMENT) print("ENTERING STATE ", Constants.MOVEMENT)
if !game.boardContainer.is_connected("tile_pressed", handleMovement): if !game.boardContainer.is_connected("tile_pressed", handleMovement):
print("Connecting tile_pressed signal")
game.boardContainer.connect("tile_pressed", handleMovement) game.boardContainer.connect("tile_pressed", handleMovement)
if game.selectedNode != "": if game.selectedNode != "":
game.getMovableAreas() game.getMovableAreas()
@ -41,7 +40,7 @@ func handleMovement(location: String) -> void:
# we need to prevent swapping of focus between peices after the double move process has started # we need to prevent swapping of focus between peices after the double move process has started
# maybe once u start nmoving a peice global stat var is set # maybe once u start nmoving a peice global stat var is set
# and any moving peice needs ot match that # and any moving peice needs ot match that
print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode) # print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode)
var node = game.get_node("Flow/" + location) as PieceContainer var node = game.get_node("Flow/" + location) as PieceContainer
# Only try to get piece if we have a selected node # Only try to get piece if we have a selected node

View file

@ -13,8 +13,6 @@ func apply_effect(piece: Pawn = null) -> void:
if piece && is_effect_active(): if piece && is_effect_active():
# Only affect enemy pieces based on tile owner # Only affect enemy pieces based on tile owner
var is_enemy = false var is_enemy = false
print("--------___CHECKING FIREWALL")
print(tile_owner, " ", piece.Item_Color)
match tile_owner: match tile_owner:
TileOwner.PLAYER: # White TileOwner.PLAYER: # White
print("PLAYER OWNER") print("PLAYER OWNER")

View file

@ -87,3 +87,36 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
return moves return moves
func animate_movement(target_position: Vector2, duration: float = 0.5) -> void:
z_index = 1
var tween = create_tween()
tween.set_trans(Tween.TRANS_LINEAR)
tween.set_ease(Tween.EASE_IN_OUT)
var start_pos = global_position
var total_delta = target_position - start_pos
var mid_pos: Vector2
var cell_delta_x = int(total_delta.x / 50)
var cell_delta_y = int(total_delta.y / 50)
if abs(cell_delta_x) > abs(cell_delta_y):
# Moving more horizontally ([-2, ±1])
mid_pos = Vector2(
start_pos.x + (cell_delta_x * 50),
start_pos.y
)
else:
# Moving more vertically ([±1, -2])
mid_pos = Vector2(
start_pos.x,
start_pos.y + (cell_delta_y * 50)
)
# First move (longer distance)
tween.tween_property(self, "global_position", mid_pos, duration/2)
# Second move (shorter distance)
tween.tween_property(self, "global_position", target_position, duration/2)
await tween.finished
z_index = 0

View file

@ -138,7 +138,7 @@ func can_move_to_cell(board_flow, location: String, is_capture: bool = false) ->
return piece != null && piece.Item_Color != self.Item_Color return piece != null && piece.Item_Color != self.Item_Color
return !container.has_piece() return !container.has_piece()
func animate_movement(target_position: Vector2, duration: float = 1) -> void: func animate_movement(target_position: Vector2, duration: float = 0.5) -> void:
# print("--------------STARTING ANIM--------------", position, " ", target_position) # print("--------------STARTING ANIM--------------", position, " ", target_position)
z_index = 1 z_index = 1
var tween = create_tween() var tween = create_tween()