{"id":84,"date":"2025-09-19T14:02:59","date_gmt":"2025-09-19T14:02:59","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/d_eanes\/?p=84"},"modified":"2025-09-19T14:04:53","modified_gmt":"2025-09-19T14:04:53","slug":"free-friday-avoidance-game","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/d_eanes\/2025\/09\/19\/free-friday-avoidance-game\/","title":{"rendered":"Free Friday: Avoidance game"},"content":{"rendered":"\n<p>Today, I watched <a href=\"https:\/\/www.youtube.com\/watch?v=waY3LfJhQLY\" data-type=\"link\" data-id=\"https:\/\/www.youtube.com\/watch?v=waY3LfJhQLY\">this video<\/a>, and made a object avoidance game. You control a rectangle, and you have to avoid projectiles that fall from the sky.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def draw(player, elapsed_time, stars):\n    WIN.blit(BG, (0, 0))\n\n    time_text = FONT.render(f\"Time: {round(elapsed_time)}s\", 1, \"white\")\n    WIN.blit(time_text, (10, 10))\n\n    pygame.draw.rect(WIN, \"red\", player)\n\n    for star in stars:\n        pygame.draw.rect(WIN, \"white\", star)\n\n    pygame.display.update()<\/code><\/pre>\n\n\n\n<p>^This function handles all the visual aspects of the game. It renders the background image, the player character, the falling stars, and the time counter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def main():\n    run = True\n\n    player = pygame.Rect(200, HEIGHT - PLAYER_HEIGHT,\n                         PLAYER_WIDTH, PLAYER_HEIGHT)\n    clock = pygame.time.Clock()\n    start_time = time.time()\n    elapsed_time = 0\n\n    star_add_increment = 2000\n    star_count = 0\n\n    stars = &#91;]\n    hit = False<\/code><\/pre>\n\n\n\n<p>^This function contains the primary game loop. It manages the game logic, like player movement, star spawning, collision detection, and handling the &#8220;game over&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"994\" height=\"827\" src=\"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-19-100150.png\" alt=\"\" class=\"wp-image-85\" srcset=\"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-19-100150.png 994w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-19-100150-300x250.png 300w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-19-100150-768x639.png 768w\" sizes=\"auto, (max-width: 994px) 100vw, 994px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Today, I watched this video, and made a object avoidance game. You control a rectangle, and you have to avoid projectiles that fall from the sky. ^This function handles all the visual aspects of the game. It renders the background image, the player character, the falling stars, and the time counter. ^This function contains the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-free-friday"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/84\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}