online multiplayer chess game (note server currently down)
Diffstat (limited to 'pieces/Pawn.gd')
| -rw-r--r-- | pieces/Pawn.gd | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/pieces/Pawn.gd b/pieces/Pawn.gd index a183eb4..5a2d36b 100644 --- a/pieces/Pawn.gd +++ b/pieces/Pawn.gd @@ -8,7 +8,7 @@ var just_set = false var enpassant = [] -func moveto(position, real = true): +func moveto(position, real = true, take = false): # check if 2 step if real and !twostepfirstmove and !has_moved: if white and real_position.y - position.y == 2: @@ -17,7 +17,7 @@ func moveto(position, real = true): if !white and position.y - real_position.y == 2: twostepfirstmove = true just_set = true - .moveto(position, real) + .moveto(position, real, take) func _on_turn_over(): @@ -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,20 +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() - shortname = "p" + team + Events.connect("just_before_turn_over", self, "_just_before_turn_over") |