75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
import pygame
|
|
import settings as s
|
|
|
|
|
|
class Hand_screen(pygame.sprite.Sprite):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.type = "hand_screen"
|
|
self.w = s.SCREEN_WIDTH
|
|
self.h = s.DOMINO_H * 1.5
|
|
self.color = (141, 111, 100)
|
|
self.surf = pygame.Surface((self.w, self.h))
|
|
self.surf.fill(self.color)
|
|
self.pos = (0, s.SCREEN_HEIGHT - self.h)
|
|
self.rect = self.surf.get_rect(center=(self.pos[0] + s.SCREEN_WIDTH / 2, self.pos[1] + self.h / 2))
|
|
|
|
|
|
class Empty_domino(pygame.sprite.Sprite):
|
|
def __init__(self, x, y, pos):
|
|
super().__init__()
|
|
self.type = "domino"
|
|
self.w = s.DOMINO_W * 1.1
|
|
self.h = s.DOMINO_H * 1.1
|
|
self.surf = pygame.Surface((self.w, self.h))
|
|
self.color = (100, 10, 10)
|
|
self.surf.fill(self.color)
|
|
self.rect = self.surf.get_rect(center=(x + self.w / 2, y + self.h / 2))
|
|
self.pos = pos
|
|
|
|
|
|
class Game_screen(pygame.sprite.Sprite):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.type = "game_screen"
|
|
self.w = s.SCREEN_WIDTH * 10
|
|
self.h = s.SCREEN_HEIGHT * 10
|
|
self.color = (230, 0, 230)
|
|
self.surf = pygame.Surface((self.w, self.h))
|
|
self.surf.fill(self.color)
|
|
self.rect = self.surf.get_rect(center=(0, 0))
|
|
|
|
self.group = pygame.sprite.Group()
|
|
self.group.add(self)
|
|
self.empty_group = pygame.sprite.Group()
|
|
|
|
empty_up = Empty_domino(s.SCREEN_WIDTH / 2, s.SCREEN_HEIGHT / 2 - (s.DOMINO_W * 1.1 * 2 + 10), "up")
|
|
empty_down = Empty_domino(s.SCREEN_WIDTH / 2, s.SCREEN_HEIGHT / 2 + (s.DOMINO_W * 1.1 * 2 + 10), "down")
|
|
empty_both = Empty_domino(s.SCREEN_WIDTH / 2, s.SCREEN_HEIGHT / 2, "both")
|
|
self.emptys = [empty_up, empty_down, empty_both]
|
|
|
|
self.group.add(empty_both)
|
|
self.empty_group.add(empty_both)
|
|
|
|
|
|
|
|
self.value_up = None
|
|
self.value_down = None
|
|
|
|
self.empty_up = empty_both
|
|
self.empty_down = empty_both
|
|
|
|
def blit_g_screen(self, screen):
|
|
# add_empty()
|
|
|
|
for entity in self.group:
|
|
screen.blit(entity.surf, entity.rect)
|
|
|
|
def update_pos(self, mouse_x, mouse_y, mouse_new_x, mouse_new_y):
|
|
# check if mouse colide with domino
|
|
if self.rect.x <= mouse_new_x <= self.rect.x + self.w and self.rect.y <= mouse_new_y <= self.rect.y + self.h:
|
|
|
|
for entity in self.group:
|
|
entity.rect.x -= mouse_x
|
|
entity.rect.y -= mouse_y
|