-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathanalogchessV4.py
143 lines (117 loc) · 3.75 KB
/
analogchessV4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import pygame
from differentfiles.pieces import *
from differentfiles.colors import *
from differentfiles.utils import to_game_coords
from differentfiles.drawing import (
see_through,
see_through2,
draw_line_round_corners_polygon,
draw_checkers,
screen,
)
pygame.init()
# fucking awful global variable that is is changed by the confirm() function of the pieces
whites_turn = True
radius = 0.7
pieces = [
Rook(0.5, 0.5, white),
Rook(7.5, 0.5, white),
Knight(1.5, 0.5, white),
Knight(6.5, 0.5, white),
Bishop(5.5, 0.5, white),
Bishop(2.5, 0.5, white),
King(4.5, 0.5, white),
Queen(3.5, 0.5, white),
Pawn(0.5, 1.5, white),
Pawn(1.5, 1.5, white),
Pawn(2.5, 1.5, white),
Pawn(3.5, 1.5, white),
Pawn(4.5, 1.5, white),
Pawn(5.5, 1.5, white),
Pawn(6.5, 1.5, white),
Pawn(7.5, 1.5, white),
Rook(0.5, 7.5, black),
Rook(7.5, 7.5, black),
Knight(1.5, 7.5, black),
Knight(6.5, 7.5, black),
Bishop(5.5, 7.5, black),
Bishop(2.5, 7.5, black),
King(4.5, 7.5, black),
Queen(3.5, 7.5, black),
Pawn(0.5, 6.5, black),
Pawn(1.5, 6.5, black),
Pawn(2.5, 6.5, black),
Pawn(3.5, 6.5, black),
Pawn(4.5, 6.5, black),
Pawn(5.5, 6.5, black),
Pawn(6.5, 6.5, black),
Pawn(7.5, 6.5, black),
]
done = False
clock = pygame.time.Clock()
confirmed = True
pygame.display.set_caption("Analog Chess")
draw_line_round_corners_polygon(
see_through, (120, 120), (220, 220), RED_HIGHLIGHT, 0.7 * 640 / 8
)
grabbed_piece = None
for piece in pieces:
piece.calc_paths(pieces)
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
for piece in pieces:
piece.try_grab(to_game_coords(pygame.mouse.get_pos()))
"""
if whites_turn:
if piece.color == white:
piece.try_grab(to_game_coords(pygame.mouse.get_pos()))
else:
if piece.color != white:
piece.try_grab(to_game_coords(pygame.mouse.get_pos()))
"""
elif event.type == pygame.MOUSEMOTION:
for piece in pieces:
piece.drag(to_game_coords(pygame.mouse.get_pos()), pieces)
elif event.type == pygame.MOUSEBUTTONUP:
new_pieces = []
for piece in pieces:
piece.ungrab(pieces)
if piece.can_promote():
new_pieces.append(Queen(piece.x, piece.y, piece.color))
else:
new_pieces.append(piece)
pieces = new_pieces
for piece in pieces:
piece.calc_paths(pieces)
"""
if not pygame.mouse.get_focused():
for piece in pieces:
piece.ungrab(pieces)
"""
draw_checkers()
prev_grabbed_piece = grabbed_piece
grabbed_piece = None
for piece in pieces:
if piece.grabbed:
grabbed_piece = piece
if grabbed_piece:
for piece in pieces:
if piece.color != grabbed_piece.color:
piece.draw_paths(pieces)
if grabbed_piece:
grabbed_piece.draw_moves(pieces)
screen.blit(see_through, (0, 0))
screen.blit(see_through2, (0, 0))
for piece in pieces:
piece.draw()
# draw grabbed piece last so it will show up on top
if grabbed_piece:
grabbed_piece.draw()
pygame.display.flip()
clock.tick(30)
see_through.fill((0, 0, 0, 0))
see_through2.fill((0, 0, 0, 0))