online multiplayer chess game (note server currently down)
Diffstat (limited to 'Grid.gd')
| -rw-r--r-- | Grid.gd | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -144,24 +144,29 @@ func print_matrix_pretty(mat = matrix): func check_for_circle(position: Vector2): - var circle = background_matrix[position.x][position.y].circle.visible - return circle + return background_matrix[position.x][position.y].circle.visible +func check_for_frame(position:Vector2): + if !matrix[position.y][position.x]: + return false + return matrix[position.y][position.x].frame.visible func square_clicked(position: Vector2): var spot = matrix[position.y][position.x] - if !spot or !spot.white: - if !last_clicked: # its null + if !spot or !spot.white: # spot is not a tile or spot is not white + if !last_clicked: # last clicked is null, so this is pointless return - if check_for_circle(position): - last_clicked.moveto(position) - last_clicked.clear_clicked() - last_clicked = null - elif last_clicked != spot: - if last_clicked: + if check_for_circle(position): # see if theres a circle at the position + last_clicked.moveto(position) # if there is, move there + if check_for_frame(position): # takeable + last_clicked.take(matrix[position.y][position.x]) # eat + last_clicked.clear_clicked() # remove the circles + last_clicked = null # set it to null + elif last_clicked != spot: # we got a new piece (or pawn) clicked + if last_clicked: # remove the circles last_clicked.clear_clicked() - last_clicked = spot - spot.clicked() + last_clicked = spot # set it to the new spot + spot.clicked() # tell the piece shit happeend func clear_circles(): @@ -169,3 +174,10 @@ func clear_circles(): for j in range(8): var square = background_matrix[i][j] square.set_circle(false) + +func clear_frames(): + for i in range(8): + for j in range(8): + var square = matrix[i][j] + if square: + square.set_frame(false) |