pawn promotion (to queen)
This commit is contained in:
parent
573909c7d7
commit
76b16ada7a
2 changed files with 14 additions and 3 deletions
12
Main.gd
12
Main.gd
|
@ -51,6 +51,7 @@ func _process(_delta):
|
||||||
func new_turn():
|
func new_turn():
|
||||||
update_capture_tables()
|
update_capture_tables()
|
||||||
is_king_checked()
|
is_king_checked()
|
||||||
|
check_for_promotion()
|
||||||
turn += 1
|
turn += 1
|
||||||
print("Turn: %s" % turn)
|
print("Turn: %s" % turn)
|
||||||
|
|
||||||
|
@ -94,8 +95,17 @@ func update_capture_tables():
|
||||||
# move_tile.set_color("red")
|
# move_tile.set_color("red")
|
||||||
# move_tile.position = in_square(Vector2(i * board_cell, k * board_cell))
|
# move_tile.position = in_square(Vector2(i * board_cell, k * board_cell))
|
||||||
|
|
||||||
|
func check_for_promotion():
|
||||||
|
var pieces = get_tree().get_nodes_in_group("piece")
|
||||||
|
for e in pieces:
|
||||||
|
if e.get_piece() == "pawn":
|
||||||
|
var y = position_to_board_cell(e.position)[1]
|
||||||
|
if y == 0 or y == 7:
|
||||||
|
print("pawn is elligable for promotion")
|
||||||
|
# TODO: player option
|
||||||
|
e.set_piece("queen", e.get_piece_color_by_region())
|
||||||
|
|
||||||
func is_king_checked():
|
func is_king_checked():
|
||||||
print(team2_king)
|
|
||||||
if team2_king:
|
if team2_king:
|
||||||
var coords_team2 = position_to_board_cell(team2_king.position)
|
var coords_team2 = position_to_board_cell(team2_king.position)
|
||||||
if team1_capture[coords_team2[0]][coords_team2[1]] >= 1:
|
if team1_capture[coords_team2[0]][coords_team2[1]] >= 1:
|
||||||
|
|
|
@ -51,15 +51,16 @@ func _ready():
|
||||||
|
|
||||||
func init(new_piece, color, new_team = 0):
|
func init(new_piece, color, new_team = 0):
|
||||||
get_texture().set_region(Rect2(new_piece, color, CELL_W, CELL_H))
|
get_texture().set_region(Rect2(new_piece, color, CELL_W, CELL_H))
|
||||||
self.set_piece(self.get_piece_name_by_region())
|
self.set_piece(self.get_piece_name_by_region(), self.get_piece_color_by_region())
|
||||||
self.set_team(new_team)
|
self.set_team(new_team)
|
||||||
|
|
||||||
func _on_Area2D_input_event(_viewport, event, _shape_idx):
|
func _on_Area2D_input_event(_viewport, event, _shape_idx):
|
||||||
if event.is_action_pressed("mouse1"):
|
if event.is_action_pressed("mouse1"):
|
||||||
emit_signal("clicked")
|
emit_signal("clicked")
|
||||||
|
|
||||||
func set_piece(new_piece):
|
func set_piece(new_piece, color):
|
||||||
piece = new_piece
|
piece = new_piece
|
||||||
|
get_texture().set_region(Rect2(self.piece_map.get(new_piece), self.piece_color.get(color), CELL_W, CELL_H))
|
||||||
|
|
||||||
func get_piece():
|
func get_piece():
|
||||||
return piece
|
return piece
|
||||||
|
|
Loading…
Reference in a new issue