online multiplayer chess game (note server currently down)
skewes
bendn 2022-04-28
parent dd1605d · commit 573225e
-rw-r--r--Grid.gd3
-rw-r--r--pieces/Knight.gd2
-rw-r--r--pieces/Pawn.gd2
-rw-r--r--pieces/Piece.gd8
4 files changed, 8 insertions, 7 deletions
diff --git a/Grid.gd b/Grid.gd
index 6c50d7c..e1660dd 100644
--- a/Grid.gd
+++ b/Grid.gd
@@ -45,9 +45,10 @@ func check_in_check(): # check if in_check
Globals.in_check = true # set in_check
Globals.checking_piece = matrix[i][j] # set checking_piece
print("check by " + spot.shortname) # print the check
- return true # stop at the first check found
+ return true # stop at the first check found
return false
+
func _exit_tree():
Globals.grid = null # reset the globals grid when leaving tree
diff --git a/pieces/Knight.gd b/pieces/Knight.gd
index b973f06..477afec 100644
--- a/pieces/Knight.gd
+++ b/pieces/Knight.gd
@@ -16,7 +16,7 @@ func get_moves():
var final = []
for i in moves:
if is_on_board(i):
- if check_spots_check and Globals.in_check and checkcheck(i):
+ if check_spots_check and checkcheck(i):
continue
final.append(i)
return final
diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd
index 5c232ae..7760913 100644
--- a/pieces/Pawn.gd
+++ b/pieces/Pawn.gd
@@ -13,7 +13,7 @@ func get_moves():
if at_pos(point) == null:
if i == 1 and has_moved or at_pos(pos_around(points[0] * whiteint)) != null:
continue
- if check_spots_check and Globals.in_check and checkcheck(point):
+ if check_spots_check and checkcheck(point):
continue
if is_on_board(point):
moves.append(point)
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index 420253f..6cb3185 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -76,7 +76,7 @@ func all_dirs():
]
-func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]):
+func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]): # TODO: get this system to work with taking pieces
var circle_array = []
for i in arr:
var pos = real_position
@@ -87,7 +87,7 @@ func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]):
if at_pos(pos) != null: # only one black
circle_array.append(pos)
break
- if check_spots_check and Globals.in_check and checkcheck(pos):
+ if check_spots_check and checkcheck(pos):
print(checkcheck(pos))
continue
circle_array.append(pos)
@@ -144,9 +144,9 @@ func checkcheck(pos): # moves to position, then checks if your king is in check
moveto(pos, false) # move to the position
if Globals.grid.check_in_check(): # if you are still in check
Globals.grid.matrix = mat # revert changes on the matrix
- return false
+ return true
Globals.grid.matrix = mat # revert changes on the matrix
- return true
+ return false
func is_on_board(vector: Vector2):