54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import pygame
|
|
from random import randint
|
|
from settings import SCREEN_HEIGHT, SCREEN_WIDTH
|
|
from pygame.locals import (
|
|
K_UP,
|
|
K_DOWN,
|
|
K_LEFT,
|
|
K_RIGHT,
|
|
K_ESCAPE,
|
|
KEYDOWN,
|
|
QUIT,
|
|
|
|
)
|
|
|
|
pygame.font.init()
|
|
my_font = pygame.font.SysFont('Calibri (Body)', 50)
|
|
|
|
# Define a Player object by extending pygame.sprite.Sprite
|
|
# The surface drawn on the screen is now an attribute of 'player'
|
|
class Domino(pygame.sprite.Sprite):
|
|
def __init__(self, x, y):
|
|
super().__init__()
|
|
self.type = "domino"
|
|
self.w = 100
|
|
self.h = 200
|
|
self.surf = pygame.Surface((self.w, self.h))
|
|
self.surf.fill((0, 0, 0))
|
|
self.rect = self.surf.get_rect(center=(x, y))
|
|
|
|
self.values = [randint(0, 6), randint(0, 6)]
|
|
|
|
|
|
def blit_domino(self, screen):
|
|
screen.blit(self.surf, self.rect)
|
|
|
|
v_up = my_font.render(f"{self.values[0]}", True, (255, 255, 255))
|
|
v_down = my_font.render(f"{self.values[1]}", True, (255, 255, 255))
|
|
screen.blit(v_up,
|
|
(self.rect.x + (self.w / 2) - v_up.get_width(), self.rect.y + (self.h / 4) - v_up.get_height()))
|
|
# print(self.rect.x + (self.w / 2) - v_up.get_width(), self.rect.y + (self.h / 4) - v_up.get_height())
|
|
screen.blit(v_down, (
|
|
self.rect.x + (self.w / 2) - v_down.get_width(), self.rect.y + (self.h / 4) * 3 - v_down.get_height()))
|
|
# screen.blit(v_up,
|
|
# (310, 16))
|
|
|
|
|
|
def update(self, mouse_x, mouse_y):
|
|
if self.rect.x <= mouse_x <= self.rect.x + self.w and self.rect.y <= mouse_y <= self.rect.y + self.h:
|
|
self.surf.fill((100, 100, 100))
|
|
else:
|
|
self.surf.fill((0, 0, 0))
|
|
|
|
|