online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/Piece.gd')
-rw-r--r--pieces/Piece.gd25
1 files changed, 16 insertions, 9 deletions
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index 6cb3185..6c7721b 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -9,6 +9,7 @@ var sprite
var frameon
var team = "w"
var check_spots_check = true
+var no_enemys = false
onready var tween = $Tween
onready var anim = $AnimationPlayer
@@ -76,7 +77,7 @@ func all_dirs():
]
-func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]): # TODO: get this system to work with taking pieces
+func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]):
var circle_array = []
for i in arr:
var pos = real_position
@@ -84,11 +85,12 @@ func traverse(arr = [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT]): #
pos += i
if !is_on_board(pos):
break
- if at_pos(pos) != null: # only one black
+ if at_pos(pos) != null: # only one enemy
+ if no_enemys: # or none
+ break
circle_array.append(pos)
break
if check_spots_check and checkcheck(pos):
- print(checkcheck(pos))
continue
circle_array.append(pos)
return circle_array
@@ -103,12 +105,16 @@ func get_moves(): # @Override
func get_attacks(): # @Override
+ no_enemys = false
var moves = get_moves() # assumes the attacks are same as moves
var final = []
for i in moves:
if at_pos(i) != null:
if at_pos(i).white != white: # attack ze enemie
+ if check_spots_check and checkcheck(i):
+ continue
final.append(i)
+ no_enemys = true
return final
@@ -127,15 +133,16 @@ func create_move_circles(pos):
func create_take_circles(spot): # create take circles
- spot.set_frame(true) # turn on the little take frame on the piece, to show its takeable
+ spot.set_frame() # turn on the little take frame on the piece, to show its takeable
func set_circle(positions: Array, type := "move"):
for pos in positions:
var spot = at_pos(pos) # get the piece at the position
- if type == "move": # if the type is move
+ if type == "move":
+ print(shortname, " can move to ", pos)
create_move_circles(pos) # create the move circle
- elif type == "take": # if the type is take
+ elif type == "take":
create_take_circles(spot) # if the king is in check, return true
@@ -145,12 +152,12 @@ func checkcheck(pos): # moves to position, then checks if your king is in check
if Globals.grid.check_in_check(): # if you are still in check
Globals.grid.matrix = mat # revert changes on the matrix
return true
- Globals.grid.matrix = mat # revert changes on the matrix
+ Globals.grid.matrix = mat
return false
func is_on_board(vector: Vector2):
- if vector.y < 0 or vector.y > 7 or vector.x < 0 or vector.x > 7:
+ if vector.y < 0 or vector.y > 7 or vector.x < 0 or vector.x > 7: # limit the vector to the board
return false
return true
@@ -165,6 +172,6 @@ func took(): # called when piece is taken
anim.play("Take")
-func set_frame(value):
+func set_frame(value = true):
frameon = value
frame.visible = value