Compare commits
2 commits
43fe315083
...
681f85a2c4
| Author | SHA1 | Date | |
|---|---|---|---|
| 681f85a2c4 | |||
| 0715911318 |
7 changed files with 74 additions and 46 deletions
|
|
@ -57,12 +57,12 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
|||
# Move piece to final position
|
||||
var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer
|
||||
|
||||
|
||||
# Important: Need to remove the piece from its current container first
|
||||
# AND keep a reference to it
|
||||
target_piece = current_container.get_piece() # Get reference before removing
|
||||
current_container.remove_piece(true) # Remove from current container
|
||||
final_container.set_piece(target_piece) # Set in new container
|
||||
# current_container.remove_piece(true) # Remove from current container
|
||||
# final_container.set_piece(target_piece) # Set in new container
|
||||
final_container.animate_movement(current_container, target_piece)
|
||||
|
||||
game_state.currentlyMovingPiece = target_piece
|
||||
burned = true
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ func _process(delta: float) -> void:
|
|||
|
||||
func initializeGame() -> void:
|
||||
setupStyles()
|
||||
initializeBoard()
|
||||
setupUI()
|
||||
initializeDeckSystem()
|
||||
initializeCardPreview()
|
||||
initializeBoard()
|
||||
|
||||
func initializeCardPreview() -> void:
|
||||
cardPreview = CardPreview.new()
|
||||
|
|
@ -224,8 +224,10 @@ func placePiece(position: String, pieceName: String, color: int) -> void:
|
|||
var piece = summonPiece(pieceName, color)
|
||||
# boardContainer.get_node(position).add_child(piece)
|
||||
|
||||
var container = boardContainer.get_node(position)
|
||||
container.set_piece(piece)
|
||||
var container = boardContainer.get_node(position) as PieceContainer
|
||||
await container.set_piece(piece, false)
|
||||
container.remove_piece(true)
|
||||
container.set_piece(piece, false)
|
||||
|
||||
var coords = position.split("-")
|
||||
board[int(coords[1])][int(coords[0])] = piece
|
||||
|
|
|
|||
|
|
@ -10,12 +10,36 @@ func _init() -> void:
|
|||
effects.name = "Effects"
|
||||
add_child(effects)
|
||||
|
||||
func set_piece(new_piece: Pawn) -> void:
|
||||
|
||||
func animate_movement(source_container: PieceContainer, moving_piece: Pawn) -> void :
|
||||
await set_piece(moving_piece)
|
||||
source_container.remove_piece(true)
|
||||
remove_piece(true)
|
||||
set_piece(moving_piece, false)
|
||||
|
||||
|
||||
func set_piece(new_piece: Pawn, animate: bool = true) -> void:
|
||||
remove_piece() # Clean up any existing piece
|
||||
piece = new_piece
|
||||
if new_piece != null:
|
||||
add_child(new_piece)
|
||||
new_piece.position = Vector2(25, 25)
|
||||
if animate:
|
||||
|
||||
print("POS ", get_global_position())
|
||||
var targetPos = get_global_position() + Vector2(25, 25)
|
||||
|
||||
if new_piece.get_parent():
|
||||
new_piece.reparent(self)
|
||||
else:
|
||||
add_child(new_piece)
|
||||
await new_piece.animate_movement(targetPos)
|
||||
else:
|
||||
|
||||
if new_piece.get_parent():
|
||||
new_piece.reparent(self)
|
||||
else:
|
||||
add_child(new_piece)
|
||||
new_piece.position = Vector2(25, 25)
|
||||
|
||||
|
||||
func get_piece() -> Pawn:
|
||||
return piece
|
||||
|
|
@ -23,7 +47,8 @@ func get_piece() -> Pawn:
|
|||
func remove_piece(keep_piece: bool = false) -> Pawn:
|
||||
var old_piece = piece
|
||||
if piece != null:
|
||||
remove_child(piece)
|
||||
if piece.get_parent() == self:
|
||||
remove_child(piece)
|
||||
if !keep_piece:
|
||||
piece.queue_free()
|
||||
old_piece = null
|
||||
|
|
|
|||
|
|
@ -180,10 +180,16 @@ func handleCastling(node: PieceContainer) -> void:
|
|||
var king = kingContainer.get_piece()
|
||||
var rook = rookContainer.get_piece()
|
||||
|
||||
kingContainer.remove_piece(true)
|
||||
rookContainer.remove_piece(true)
|
||||
kingTargetContainer.set_piece(king)
|
||||
rookTargetContainer.set_piece(rook)
|
||||
# kingContainer.remove_piece(true)
|
||||
# rookContainer.remove_piece(true)
|
||||
# kingTargetContainer.set_piece(king)
|
||||
# rookTargetContainer.set_piece(rook)
|
||||
|
||||
kingTargetContainer.animate_movement(kingContainer, king);
|
||||
|
||||
rookTargetContainer.animate_movement(rookContainer, rook);
|
||||
|
||||
|
||||
|
||||
game.currentlyMovingPiece = king
|
||||
game.resolveMoveEffects()
|
||||
|
|
@ -213,8 +219,14 @@ func handleCapture(node: PieceContainer) -> void:
|
|||
|
||||
if moving_piece && captured_piece:
|
||||
game.updatePoints(captured_piece)
|
||||
source_container.remove_piece(true)
|
||||
node.set_piece(moving_piece)
|
||||
node.animate_movement(source_container, moving_piece);
|
||||
|
||||
|
||||
# await node.set_piece(moving_piece)
|
||||
# source_container.remove_piece(true)
|
||||
# node.remove_piece(true)
|
||||
# node.set_piece(moving_piece, false)
|
||||
|
||||
game.currentlyMovingPiece = moving_piece
|
||||
game.resolveMoveEffects()
|
||||
|
||||
|
|
@ -226,9 +238,7 @@ func handleRegularMove(node: PieceContainer, consume: bool) -> void:
|
|||
var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer
|
||||
var piece = sourceContainer.get_piece()
|
||||
print("Removing Piece 1")
|
||||
sourceContainer.remove_piece(true)
|
||||
node.set_piece(piece)
|
||||
|
||||
node.animate_movement(sourceContainer, piece);
|
||||
game.currentlyMovingPiece = piece
|
||||
if consume:
|
||||
game.resolveMoveEffects()
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ func place_random_game_tiles(num_tiles: int = 6) -> void:
|
|||
var tile_type = rng.randi() % 3
|
||||
|
||||
var tile: Tile
|
||||
return
|
||||
match tile_type:
|
||||
0: # DoubleMovementTile tile
|
||||
tile = WallTile.new(container, is_white, -1)
|
||||
|
|
|
|||
|
|
@ -87,29 +87,3 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
|||
return moves
|
||||
|
||||
|
||||
|
||||
# func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
||||
# var moves = {
|
||||
# "regular_moves": [],
|
||||
# "special_moves": []
|
||||
# }
|
||||
|
||||
# var loc = current_location.split("-")
|
||||
# var x = int(loc[0])
|
||||
# var y = int(loc[1])
|
||||
|
||||
# # All possible L-shaped moves
|
||||
# var knight_moves = [
|
||||
# [-2, -1], [-2, 1],
|
||||
# [-1, -2], [-1, 2],
|
||||
# [1, -2], [1, 2],
|
||||
# [2, -1], [2, 1]
|
||||
# ]
|
||||
|
||||
# for move in knight_moves:
|
||||
# var new_loc = str(x + move[0]) + "-" + str(y + move[1])
|
||||
# if is_valid_cell(board_flow, new_loc):
|
||||
# if can_move_to_cell(board_flow, new_loc) || can_move_to_cell(board_flow, new_loc, true):
|
||||
# moves.regular_moves.append(new_loc)
|
||||
|
||||
# return moves
|
||||
|
|
|
|||
|
|
@ -137,3 +137,19 @@ func can_move_to_cell(board_flow, location: String, is_capture: bool = false) ->
|
|||
var piece = container.get_piece()
|
||||
return piece != null && piece.Item_Color != self.Item_Color
|
||||
return !container.has_piece()
|
||||
|
||||
func animate_movement(target_position: Vector2, duration: float = 1) -> void:
|
||||
# print("--------------STARTING ANIM--------------", position, " ", target_position)
|
||||
z_index = 1
|
||||
var tween = create_tween()
|
||||
# Make sure the tween is configured properly
|
||||
tween.set_trans(Tween.TRANS_LINEAR) # or TRANS_CUBIC for smoother movement
|
||||
tween.set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
var start_pos = position
|
||||
tween.tween_property(self, "global_position", target_position, duration)
|
||||
#.from(start_pos)
|
||||
|
||||
# Wait for animation to complete
|
||||
await tween.finished
|
||||
# print("--------------FINISHED ANIM--------------")
|
||||
Loading…
Reference in a new issue