forked from AlejoG10/python-chess-ai-yt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dragger.py
42 lines (34 loc) · 1.02 KB
/
dragger.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
import pygame
from constants import *
class Dragger:
def __init__(self):
self.piece = None
self.dragging = False
self.mouseX = 0
self.mouseY = 0
self.initial_row = 0
self.initial_col = 0
# blit method
def update_blit(self, surface):
# texture
self.piece.set_texture(size=128)
texture = self.piece.texture
# img
img = pygame.image.load(texture)
# rect
img_center = (self.mouseX, self.mouseY)
self.piece.texture_rect = img.get_rect(center=img_center)
# blit
surface.blit(img, self.piece.texture_rect)
# other methods
def update_mouse(self, pos):
self.mouseX, self.mouseY = pos # (xcor, ycor)
def save_initial(self, pos):
self.initial_row = pos[1] // SQSIZE
self.initial_col = pos[0] // SQSIZE
def drag_piece(self, piece):
self.piece = piece
self.dragging = True
def undrag_piece(self):
self.piece = None
self.dragging = False