{"id":46,"date":"2026-05-01T14:02:13","date_gmt":"2026-05-01T14:02:13","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/m_vicander\/?p=46"},"modified":"2026-05-01T14:02:13","modified_gmt":"2026-05-01T14:02:13","slug":"my-free-friday","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/m_vicander\/2026\/05\/01\/my-free-friday\/","title":{"rendered":"my free friday"},"content":{"rendered":"\n<p>what i did today was make snake<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nimport random\nimport sys\n\n# Initialize pygame\npygame.init()\n\n# Game settings\nWIDTH, HEIGHT = 600, 400\nBLOCK_SIZE = 20\nFPS = 10\n\n# Colors\nBLACK = (0, 0, 0)\nWHITE = (255, 255, 255)\nGREEN = (0, 200, 0)\nRED = (200, 0, 0)\n\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\npygame.display.set_caption(\"Snake\")\nclock = pygame.time.Clock()\nfont = pygame.font.SysFont(\"arial\", 24)\n\n\ndef draw_text(text, color, x, y):\n    surface = font.render(text, True, color)\n    rect = surface.get_rect(center=(x, y))\n    screen.blit(surface, rect)\n\n\ndef main():\n    # Snake initial state\n    snake = &#91;(WIDTH \/\/ 2, HEIGHT \/\/ 2)]\n    direction = (BLOCK_SIZE, 0)  # moving right\n    score = 0\n\n    # Food\n    def random_food():\n        return (\n            random.randrange(0, WIDTH, BLOCK_SIZE),\n            random.randrange(0, HEIGHT, BLOCK_SIZE),\n        )\n\n    food = random_food()\n\n    running = True\n    while running:\n        clock.tick(FPS)\n\n        # Handle events\n        for event in pygame.event.get():\n            if event.type == pygame.QUIT:\n                pygame.quit()\n                sys.exit()\n            elif event.type == pygame.KEYDOWN:\n                if event.key == pygame.K_UP and direction&#91;1] == 0:\n                    direction = (0, -BLOCK_SIZE)\n                elif event.key == pygame.K_DOWN and direction&#91;1] == 0:\n                    direction = (0, BLOCK_SIZE)\n                elif event.key == pygame.K_LEFT and direction&#91;0] == 0:\n                    direction = (-BLOCK_SIZE, 0)\n                elif event.key == pygame.K_RIGHT and direction&#91;0] == 0:\n                    direction = (BLOCK_SIZE, 0)\n\n        # Move snake\n        head_x, head_y = snake&#91;0]\n        new_head = (head_x + direction&#91;0], head_y + direction&#91;1])\n\n        # Check collisions with walls\n        if (\n            new_head&#91;0] &lt; 0\n            or new_head&#91;0] >= WIDTH\n            or new_head&#91;1] &lt; 0\n            or new_head&#91;1] >= HEIGHT\n        ):\n            running = False\n\n        # Check collisions with self\n        if new_head in snake:\n            running = False\n\n        snake.insert(0, new_head)\n\n        # Check food\n        if new_head == food:\n            score += 1\n            food = random_food()\n        else:\n            snake.pop()\n\n        # Draw\n        screen.fill(BLACK)\n\n        # Draw snake\n        for x, y in snake:\n            pygame.draw.rect(screen, GREEN, (x, y, BLOCK_SIZE, BLOCK_SIZE))\n\n        # Draw food\n        pygame.draw.rect(screen, RED, (food&#91;0], food&#91;1], BLOCK_SIZE, BLOCK_SIZE))\n\n        # Draw score\n        draw_text(f\"Score: {score}\", WHITE, WIDTH \/\/ 2, 20)\n\n        pygame.display.flip()\n\n    # Game over screen\n    screen.fill(BLACK)\n    draw_text(\"Game Over\", RED, WIDTH \/\/ 2, HEIGHT \/\/ 2 - 20)\n    draw_text(f\"Final Score: {score}\", WHITE, WIDTH \/\/ 2, HEIGHT \/\/ 2 + 20)\n    pygame.display.flip()\n    pygame.time.wait(2000)\n\n\nif __name__ == \"__main__\":\n    main()\n<\/code><\/pre>\n\n\n\n<p>you will have to pip install pygame for it to work but its pretty fun <\/p>\n","protected":false},"excerpt":{"rendered":"<p>what i did today was make snake you will have to pip install pygame for it to work but its pretty fun<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/46\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}