online multiplayer chess game (note server currently down)
cleaned up env variables
| -rw-r--r-- | Grid.gd | 1 | ||||
| -rw-r--r-- | Utils.gd | 15 | ||||
| -rw-r--r-- | pieces/Bishop.gd | 4 | ||||
| -rw-r--r-- | pieces/King.gd | 6 | ||||
| -rw-r--r-- | pieces/Knight.gd | 2 | ||||
| -rw-r--r-- | pieces/Pawn.gd | 6 | ||||
| -rw-r--r-- | pieces/Piece.gd | 25 | ||||
| -rw-r--r-- | pieces/Queen.gd | 4 | ||||
| -rw-r--r-- | pieces/Rook.gd | 4 |
9 files changed, 28 insertions, 39 deletions
@@ -202,6 +202,7 @@ func check_in_check(prin = false) -> bool: # check if in_check Globals.in_check = true # set in_check Globals.checking_piece = spot # set checking_piece SoundFx.play("Check") + print("check") return true # stop at the first check found return false @@ -13,7 +13,7 @@ func _ready() -> void: Events.connect("turn_over", self, "_on_turn_over") -func is_pawn(inode) -> bool: +static func is_pawn(inode) -> bool: return inode is Pawn @@ -25,7 +25,7 @@ func add_move(move) -> void: emit_signal("newmove", move) -func flip_int(i: int) -> int: +static func flip_int(i: int) -> int: return int(abs(7 - i)) @@ -35,15 +35,15 @@ func reset_vars() -> void: counter = 0 -func to_algebraic(real_position) -> String: +static func to_algebraic(real_position) -> String: return char(65 + (real_position.x)).to_lower() + str(8 - real_position.y) -func from_algebraic(algebraic_position: String) -> Vector2: +static func from_algebraic(algebraic_position: String) -> Vector2: return Vector2(ord(algebraic_position[0]) - ord("a"), 8 - int(algebraic_position[1])) -func get_node_name(node) -> Array: +static func get_node_name(node) -> Array: if is_pawn(node): return ["♙", "p"] if node.white else ["♟", "p"] elif node is King: @@ -64,13 +64,10 @@ func walk_dir(path = "res://assets/pieces") -> PoolStringArray: # walk the dire var folders: PoolStringArray = [] # init the folders var dir := Directory.new() # init the directory if dir.open(path) == OK: # open the directory - dir.list_dir_begin() # list the directory + dir.list_dir_begin(true) # list the directory var file_name := dir.get_next() # get the next file while file_name != "": # while there is a file if dir.current_is_dir(): # if the current is a directory - if file_name == "." or file_name == "..": # if it is a dot or dot dot - file_name = dir.get_next() # get the next file - continue folders.append(file_name) # add the folder file_name = dir.get_next() # get the next file else: diff --git a/pieces/Bishop.gd b/pieces/Bishop.gd index 91b5b7d..ad2a3c8 100644 --- a/pieces/Bishop.gd +++ b/pieces/Bishop.gd @@ -2,5 +2,5 @@ extends Piece class_name Bishop, "res://assets/pieces/california/wB.png" -func get_moves() -> Array: - return traverse(all_dirs().slice(4, 8)) +func get_moves(no_enemys = false, check_spots_check = true) -> Array: + return traverse(all_dirs().slice(4, 8), no_enemys, check_spots_check) diff --git a/pieces/King.gd b/pieces/King.gd index 8e9ba58..aeb1477 100644 --- a/pieces/King.gd +++ b/pieces/King.gd @@ -9,7 +9,7 @@ func _ready() -> void: Events.connect("just_before_turn_over", self, "just_before_over") -func get_moves() -> Array: +func get_moves(no_enemys = false, check_spots_check = true) -> Array: var moves := [] for i in all_dirs(): var spot: Vector2 = pos_around(i) @@ -94,8 +94,8 @@ func can_move() -> bool: # checks if you can legally move return can -func get_attacks() -> Array: +func get_attacks(check_spots_check = true) -> Array: castle_check = false - var final: Array = .get_attacks() + var final: Array = .get_attacks(check_spots_check) castle_check = true return final diff --git a/pieces/Knight.gd b/pieces/Knight.gd index d8c47b6..b9e91e5 100644 --- a/pieces/Knight.gd +++ b/pieces/Knight.gd @@ -2,7 +2,7 @@ extends Piece class_name Knight, "res://assets/pieces/california/wN.png" -func get_moves() -> Array: +func get_moves(no_enemys = false, check_spots_check = true) -> Array: var moves := [ pos_around(Vector2(-2, -1)), pos_around(Vector2(-2, 1)), diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd index 4811abe..43ecc09 100644 --- a/pieces/Pawn.gd +++ b/pieces/Pawn.gd @@ -52,7 +52,7 @@ func moveto(position, real = true, take = false, override_moveto = false) -> voi Globals.reset_halfmove() -func get_moves() -> Array: +func get_moves(_var = false, check_spots_check = true) -> Array: var points := [Vector2.UP, Vector2.UP * 2] var moves := [] for i in range(len(points)): @@ -81,7 +81,7 @@ func passant(position) -> void: moveto(position) -func get_attacks() -> Array: +func get_attacks(check_spots_check = true) -> Array: var points := [Vector2.UP + Vector2.RIGHT, Vector2.UP + Vector2.LEFT] var moves := [] for i in range(len(points)): @@ -98,7 +98,7 @@ func get_attacks() -> Array: return moves -func en_passant(turncheck = true) -> Array: # in passing +func en_passant(turncheck = true, check_spots_check = true) -> Array: # in passing var passants := [pos_around(Vector2.LEFT), pos_around(Vector2.RIGHT)] var moves := [] for i in passants: diff --git a/pieces/Piece.gd b/pieces/Piece.gd index aa8df13..e62b705 100644 --- a/pieces/Piece.gd +++ b/pieces/Piece.gd @@ -8,8 +8,6 @@ var mininame := "♙" var has_moved := false var frameon := false var team := "w" -var check_spots_check := true -var no_enemys := false onready var sprite := $Sprite onready var tween := $Tween @@ -61,11 +59,9 @@ static func to_algebraic(position) -> String: func move(newpos: Vector2) -> void: # dont use directly; use moveto - tween.interpolate_property( - self, "position", position, newpos * Globals.grid.piece_size, 0.3, Tween.TRANS_BACK - ) - anim.play("Move") - tween.start() + tween.interpolate_property(self, "position", position, newpos * Globals.grid.piece_size, 0.3, Tween.TRANS_BACK) + anim.play("Move") + tween.start() func moveto(position, real := true, take := false, override_moveto = false) -> void: @@ -110,7 +106,7 @@ static func all_dirs() -> Array: ] -func traverse(arr := [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]) -> Array: +func traverse(arr := [], no_enemys = false, check_spots_check = true) -> Array: var circle_array := [] for i in arr: var pos := real_position @@ -141,13 +137,12 @@ func can_move() -> bool: # checks if you can legally move return false -func get_moves() -> Array: # @Override +func get_moves(_no_enemys = false, _check_spots_check = true) -> Array: # @Override return [] -func get_attacks() -> Array: # @Override - no_enemys = false - var moves: Array = get_moves() # assumes the attacks are same as moves +func get_attacks(check_spots_check = true) -> Array: # @Override + var moves: Array = get_moves(false, check_spots_check) # assumes the attacks are same as moves var final := [] for i in moves: if at_pos(i) != null: @@ -155,17 +150,13 @@ func get_attacks() -> Array: # @Override if check_spots_check and checkcheck(i): continue final.append(i) - no_enemys = true return final func can_attack_piece(piece) -> bool: - check_spots_check = false - for pos in get_attacks(): + for pos in get_attacks(false): if at_pos(pos) == piece: - check_spots_check = true return true - check_spots_check = true return false diff --git a/pieces/Queen.gd b/pieces/Queen.gd index 77c4da5..0786c96 100644 --- a/pieces/Queen.gd +++ b/pieces/Queen.gd @@ -2,5 +2,5 @@ extends Piece class_name Queen, "res://assets/pieces/california/wQ.png" -func get_moves() -> Array: - return traverse(all_dirs()) +func get_moves(no_enemys = false, check_spots_check = true) -> Array: + return traverse(all_dirs(), no_enemys, check_spots_check) diff --git a/pieces/Rook.gd b/pieces/Rook.gd index 90aaca0..51254b4 100644 --- a/pieces/Rook.gd +++ b/pieces/Rook.gd @@ -2,5 +2,5 @@ extends Piece class_name Rook, "res://assets/pieces/california/wR.png" -func get_moves() -> Array: - return traverse() +func get_moves(no_enemys = false, check_spots_check = true) -> Array: + return traverse([Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT], no_enemys, check_spots_check) |