The thing i worked on today was something new i worked on tetris the game doesn’t fully load but I’ll get it to work but for now i wrote a good amount of code i really like this game because its relaxing in my opinion
import pygame
W, H = 10, 20
TILE = 45
GAME = W * TILE, H * TILE
FPS = 60
pygame.init()
game_sc = pygame.display.set_mode(GAME_RES)
clock = pygame.time.clock()
grid = [pygame.Rect(X * TILE, Y * TILE) for x in range (W) for y in range(H)]
figures_pos = [[(-1, 0), (-2, 0), (0, 0), (1, 0)],
[(0, -1), (-1, -1), (-1, 0), (0, 0)],
[(-1, 0), (-1, 1), (0, 0), (0, -1)],
[(0, 0), (-1, 0), (0, 1), (-1, -1)],
[(0, 0), (0, -1), (0, 1), (-1, -1)],
[(0, 0), (0, -1), (0, 1), (-1, -1)],
[(0, 0), (0, -1), (0, 1), (-1, 0)]]
figures = [[pygame. Rect(x + W // 2, y + 1, 1, 1) for x, y in fig_pos] for fig_pos in figures_pos]
figure_rect = pygame. Rect(0, 0, TILE - 2, TILE - 2)
anim_count, anim_speed, anim_limit = 0, 60, 2000
figure = deepcopy(figures[3])
def check_borders():
if figure[i].x < 0 or figure[i].x > W - 1:
return False
return True
while True:
dx = 0
game_sc.fill(pygame. Color('black'))
# control
for event in pygame. event.get():
if event. type == pygame . QUIT :
exit()
if event. type == pygame . KEYDOWN:
if event. key == pygame. K_LEFT:
dx = -1
elif event. key == pygame. K_RIGHT:
dx = 1
elif event. key == pygame. K_DOWN:
anim_limit + 100
# move x
figure_old = deepcopy(figure)
for i in range(4):
figure [i] . x += dx
if not check_borders():
figure = deepcopy(figure_old)
break
i will try my best for it to work next time im close to it though