1st-commit
commit
d734daca9b
|
@ -0,0 +1,53 @@
|
|||
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))
|
||||
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
import pygame
|
||||
import random
|
||||
from domino import Domino
|
||||
|
||||
from pygame.locals import (
|
||||
K_UP,
|
||||
K_DOWN,
|
||||
K_LEFT,
|
||||
K_RIGHT,
|
||||
K_ESCAPE,
|
||||
KEYDOWN,
|
||||
QUIT,
|
||||
MOUSEBUTTONDOWN
|
||||
)
|
||||
|
||||
pygame.init()
|
||||
SCREEN_WIDTH = 800
|
||||
SCREEN_HEIGHT = 600
|
||||
# screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
|
||||
x = 100
|
||||
y = 100
|
||||
all_sprites = pygame.sprite.Group()
|
||||
dominos = pygame.sprite.Group()
|
||||
for i in range(6):
|
||||
|
||||
domino = Domino(x, y)
|
||||
x += 110
|
||||
|
||||
dominos.add(domino)
|
||||
all_sprites.add(domino)
|
||||
|
||||
|
||||
|
||||
pygame.display.flip()
|
||||
run = True
|
||||
while run:
|
||||
|
||||
for event in pygame.event.get():
|
||||
# Did the user hit a key?
|
||||
if event.type == KEYDOWN:
|
||||
# Was it the Escape key? If so, stop the loop.
|
||||
if event.key == K_ESCAPE:
|
||||
run = False
|
||||
|
||||
# elif event.type == MOUSEBUTTONDOWN:
|
||||
|
||||
|
||||
# Did the user click the window close button? If so, stop the loop.
|
||||
elif event.type == QUIT:
|
||||
run = False
|
||||
|
||||
for domino in dominos:
|
||||
domino.update(pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
|
||||
|
||||
|
||||
|
||||
screen.fill((255, 255, 255))
|
||||
|
||||
for entity in all_sprites:
|
||||
if entity.type == "domino":
|
||||
entity.blit_domino(screen)
|
||||
else:
|
||||
screen.blit(entity.surf, entity.rect)
|
||||
|
||||
pygame.display.flip()
|
|
@ -0,0 +1,3 @@
|
|||
# Define constants for the screen width and height
|
||||
SCREEN_WIDTH = 800
|
||||
SCREEN_HEIGHT = 600
|
Loading…
Reference in New Issue