{"id":51,"date":"2025-11-07T15:39:29","date_gmt":"2025-11-07T15:39:29","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/c_menhart\/?p=51"},"modified":"2025-11-07T15:39:29","modified_gmt":"2025-11-07T15:39:29","slug":"free-friday-11-7-25","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/c_menhart\/2025\/11\/07\/free-friday-11-7-25\/","title":{"rendered":"free friday 11\/7\/25"},"content":{"rendered":"\n<p>I am doing a Tetris game and i will finish on the next friday <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nfrom copy import deepcopy\nfrom random import choice, randrange\nW, H = 10, 20 \nTILE = 45\nGAME_RES = W * TILE, H * TILE\nFPS = 60\npygame.init()\ngame_sc = pygame.display.set_mode(GAME_RES)\nclock = pygame. time. Clock ()\ngrid = &#91;pygame. Rect(x * TILE, y * TILE, TILE, TILE) for x in range(W) for y in range(H)]\nfigures_pos = &#91;&#91;(-1, 0), (-2, 0), (0, 0), (1, 0)],\n              &#91;(0, -1), (-1, -1), (-1, 0), (0, 0)],\n              &#91;(-1, 0), (-1, 1), (0, 0), (0, -1)],\n              &#91;(0, 0), (-1, 0), (0, 1), (-1, -1)],\n              &#91;(0, 0), (0, -1), (0, 1), (-1, -1)],\n              &#91;(0, 0), (0, -1), (0, 1), (1, -1)],\n              &#91;(0, 0), (0, -1), (0, 1), (-1, 0)]]\nfigures = &#91;&#91;pygame. Rect(x + W \/\/ 2, y + 1, 1, 1) for x, y in fig_pos] for fig_pos in figures_pos]\nfigure_rect = pygame. Rect(0, 0, TILE - 2, TILE - 2)\nfield = &#91;&#91;0 for i in range(W)] for j in range(H)]\nanim_count, anim_speed, anim_limit = 0, 60, 2000\n\nfigure = deepcopy(choice(figures))\ndef check_borders():\n    if figure&#91;i]. x &lt; 0 or figure&#91;i].x > W - 1:\n        return False\n    return True\n    \nwhile True:\n    dx = 0\n    game_sc.fill(pygame.Color('black'))\n    # control \n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            exit()\n        if event.type == pygame.KEYDOWN:\n            if event.key == pygame.K_LEFT:\n                dx = -1\n            elif event.key == pygame.K_RIGHT:\n                dx = 1\n            elif event.key == pygame.K_DOWN:\n                anim_limit = 100\n    for event in pygame. event. get():\n        if event.type == pygame. QUIT :\n            exit()\n    # move x\n    figure_old = deepcopy(figure)\n    for i in range(4):\n        figure&#91;i].x += dx\n        if not check_borders():\n            figure = deepcopy(figure_old)\n            break\n    # move y \n    anim_count += anim_speed\n    if anim_count > anim_limit:\n        anim_count = 0\n        for i in range(len(figure)):\n            figure&#91;i].y += 1\n        if not check_borders():\n            figure = deepcopy(figure_old)\n            break\n    # draw grid\n    &#91;pygame.draw.rect(game_sc, (40, 40, 40), i_rect, 1) for i_rect in grid]\n    # draw figure \n    for i in range(4):\n        figure_rect.x = figure&#91;i].x * TILE\n        figure_rect.y = figure&#91;i].y * TILE\n\n        pygame.draw.rect(game_sc, pygame.Color('white'), figure_rect)\n\n    pygame.display.flip()\n    clock.tick(FPS)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container \" style=\"height: 100%;\"><iframe loading=\"lazy\" title=\"Let&#039;s code Tetris Game in Python\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/7kGNs5R-AM8?start=213&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<p>that&#8217;s the video i am doing it for <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am doing a Tetris game and i will finish on the next friday that&#8217;s the video i am doing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/posts\/51\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/c_menhart\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}