online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/Pawn.gd')
-rw-r--r--pieces/Pawn.gd34
1 files changed, 25 insertions, 9 deletions
diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd
index e6deb56..5a2d36b 100644
--- a/pieces/Pawn.gd
+++ b/pieces/Pawn.gd
@@ -64,11 +64,11 @@ func get_attacks():
continue
if at_pos(point) != null and at_pos(point).white != white:
moves.append(point)
- moves.append_array(en_passant("attacks"))
+ en_passant()
return moves
-func en_passant(type: String = "moves"): # in passing
+func en_passant(turncheck = true): # in passing
var passants = [pos_around(Vector2.LEFT), pos_around(Vector2.RIGHT)]
var moves = []
for i in passants:
@@ -81,19 +81,35 @@ func en_passant(type: String = "moves"): # in passing
continue
if !Utils.is_pawn(spot):
continue
+ if turncheck and white != Globals.turn:
+ continue
if !spot.twostepfirstmove:
continue
if check_spots_check and checkcheck(i):
continue
- if type == "moves":
- var position = i + (Vector2.UP * whiteint)
- if !at_pos(position):
- moves.append(position)
- elif type == "attacks":
- enpassant.append([i + (Vector2.UP * whiteint), spot])
+ var position = i + (Vector2.UP * whiteint)
+ if !at_pos(position):
+ moves.append(position)
+ enpassant.append([position, spot])
return moves
+func _just_before_turn_over():
+ var had_a_enpassant = len(enpassant) > 0
+ enpassant.clear()
+ if !had_a_enpassant: # scuffed method to check if enpassant is possible
+ en_passant(false)
+ var temporary = []
+ for i in enpassant:
+ temporary.append(i[0])
+ if !temporary:
+ return
+ if white:
+ Globals.grid.matrix[8].wcep.append_array(temporary)
+ else:
+ Globals.grid.matrix[8].bcep.append_array(temporary)
+
+
func _ready():
Events.connect("turn_over", self, "_on_turn_over")
- ._ready()
+ Events.connect("just_before_turn_over", self, "_just_before_turn_over")