{"id":13884,"date":"2024-06-17T19:02:22","date_gmt":"2024-06-17T17:02:22","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=13884"},"modified":"2024-06-17T19:53:37","modified_gmt":"2024-06-17T17:53:37","slug":"simple-game","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/simple-game\/","title":{"rendered":"Simple game"},"content":{"rendered":"\n<figure class=\"wp-block-video\"><video height=\"646\" style=\"aspect-ratio: 816 \/ 646;\" width=\"816\" controls src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/video3.mp4\"><\/video><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Version 1<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"654\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image.png\" alt=\"\" class=\"wp-image-13887\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image.png 817w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-320x256.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-768x615.png 768w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In this first version you have to get the object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Catch the Falling Objects Game<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Overview<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In this game, the player controls a basket that can move left and right at the bottom of the screen. Objects fall from the top of the screen, and the player&#8217;s goal is to catch as many of these objects as possible using the basket. Each object caught increases the player&#8217;s score. If an object hits the ground, the player loses a life. The game continues until the player runs out of lives.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Key Features<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Player Control:<\/strong> The player moves the basket left and right using the arrow keys.<\/li>\n\n\n\n<li><strong>Falling Objects:<\/strong> Multiple objects fall from the top of the screen at a constant speed.<\/li>\n\n\n\n<li><strong>Collision Detection:<\/strong> The game detects when the basket catches an object.<\/li>\n\n\n\n<li><strong>Score Tracking:<\/strong> The score increases each time the basket catches an object.<\/li>\n\n\n\n<li><strong>Life System:<\/strong> The player starts with a set number of lives, and each object that hits the ground reduces the player&#8217;s lives.<\/li>\n\n\n\n<li><strong>Game Over Condition:<\/strong> The game ends when the player loses all their lives.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Code Description<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Importing Libraries and Initialization<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The game starts by importing the necessary libraries and initializing Pygame.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\n\n# Initialize Pygame\npygame.init()<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Constants and Colors<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the screen dimensions, frame rate, and some colors for drawing objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\nRED = (255, 0, 0)<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Setting Up the Display<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We set up the game window and the clock to control the frame rate.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Catch the Falling Objects\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Basket Properties<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the properties of the basket, including its size, position, and speed.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 10<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Object Properties<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the properties of the falling objects and create a list to hold multiple objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Object properties\nobject_width = 30\nobject_height = 30\nobject_speed = 5\n\n# Create multiple objects\nnum_objects = 5\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - object_width), 'y': -object_height} for _ in range(num_objects)]<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Basket Movement Function<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A function to handle the basket&#8217;s movement based on keyboard input.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Collision Detection Function<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A function to check if the basket catches an object.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + object_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + object_height > basket_y):\n        return True\n    return False<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Main Game Loop<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The main loop of the game handles the movement of the basket and objects, checks for collisions, updates the score and lives, and renders the game elements.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Main game loop\nrunning = True\nscore = 0\nlives = 3\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    for obj in objects:\n        obj['y'] += object_speed\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n            lives -= 1\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            score += 1\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        pygame.draw.rect(screen, RED, (obj['x'], obj['y'], object_width, object_height))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Summary<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This version of the game challenges the player to catch falling objects with a basket. It includes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A movable basket controlled by the arrow keys.<\/li>\n\n\n\n<li>Multiple falling objects.<\/li>\n\n\n\n<li>Collision detection to check if the basket catches an object.<\/li>\n\n\n\n<li>Score tracking for each object caught.<\/li>\n\n\n\n<li>A life system that decreases when an object reaches the bottom of the screen.<\/li>\n\n\n\n<li>The game ends when the player runs out of lives.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"><\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\n\n# Initialize Pygame\npygame.init()\n\n# Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\nRED = (255, 0, 0)\n\n# Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Catch the Falling Objects\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()\n\n# Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 20\n\n# Object properties\nobject_width = 30\nobject_height = 30\nobject_speed = 2\n\n# Create multiple objects\nnum_objects = 3\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - object_width), 'y': -object_height} for _ in range(num_objects)]\n\n# Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x\n\n# Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + object_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + object_height > basket_y):\n        return True\n    return False\n\n# Main game loop\nrunning = True\nscore = 0\nlives = 3\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    for obj in objects:\n        obj['y'] += object_speed\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n            lives -= 1\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            score += 1\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        pygame.draw.rect(screen, RED, (obj['x'], obj['y'], object_width, object_height))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Second version<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the second version of the game where the player must avoid the falling objects instead of catching them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Avoid the Falling Objects Game<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Overview<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In this game, the player controls a basket that can move left and right at the bottom of the screen. Objects fall from the top of the screen, and the player&#8217;s goal is to avoid these objects. If the basket collides with a falling object, the player loses a life. The game continues until the player runs out of lives. The objective is to survive as long as possible without colliding with any falling objects.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Key Features<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Player Control:<\/strong> The player moves the basket left and right using the arrow keys.<\/li>\n\n\n\n<li><strong>Falling Objects:<\/strong> Multiple objects fall from the top of the screen at a constant speed.<\/li>\n\n\n\n<li><strong>Collision Detection:<\/strong> The game detects when the basket collides with a falling object.<\/li>\n\n\n\n<li><strong>Score Tracking:<\/strong> The score increases each time an object safely passes the bottom of the screen without a collision.<\/li>\n\n\n\n<li><strong>Life System:<\/strong> The player starts with a set number of lives, and each collision with a falling object reduces the player&#8217;s lives.<\/li>\n\n\n\n<li><strong>Game Over Condition:<\/strong> The game ends when the player loses all their lives.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Code Description<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Importing Libraries and Initialization<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The game starts by importing the necessary libraries and initializing Pygame.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\n\n# Initialize Pygame\npygame.init()<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Constants and Colors<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the screen dimensions, frame rate, and some colors for drawing objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\nRED = (255, 0, 0)<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Setting Up the Display<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We set up the game window and the clock to control the frame rate.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Avoid the Falling Objects\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Basket Properties<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the properties of the basket, including its size, position, and speed.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 10<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Object Properties<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">We define the properties of the falling objects and create a list to hold multiple objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Object properties\nobject_width = 30\nobject_height = 30\nobject_speed = 5\n\n# Create multiple objects\nnum_objects = 5\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - object_width), 'y': -object_height} for _ in range(num_objects)]<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Basket Movement Function<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A function to handle the basket&#8217;s movement based on keyboard input.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Collision Detection Function<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A function to check if the basket collides with a falling object.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + object_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + object_height > basket_y):\n        return True\n    return False<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Main Game Loop<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The main loop of the game handles the movement of the basket and objects, checks for collisions, updates the score and lives, and renders the game elements.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Main game loop\nrunning = True\nscore = 0\nlives = 3\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    for obj in objects:\n        obj['y'] += object_speed\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n            score += 1  # Increase score when the object safely passes\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            lives -= 1\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        pygame.draw.rect(screen, RED, (obj['x'], obj['y'], object_width, object_height))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Summary<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This version of the game challenges the player to avoid falling objects with a basket. It includes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>A movable basket<\/strong> controlled by the arrow keys.<\/li>\n\n\n\n<li><strong>Multiple falling objects<\/strong> that the player must avoid.<\/li>\n\n\n\n<li><strong>Collision detection<\/strong> to check if the basket collides with an object.<\/li>\n\n\n\n<li><strong>Score tracking<\/strong> that increases each time an object safely passes the bottom of the screen without collision.<\/li>\n\n\n\n<li><strong>A life system<\/strong> that decreases when the basket collides with a falling object.<\/li>\n\n\n\n<li><strong>The game ends<\/strong> when the player loses all their lives.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\n\n# Initialize Pygame\npygame.init()\n\n# Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\nRED = (255, 0, 0)\n\n# Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Avoid the Falling Objects\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()\n\n# Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 10\n\n# Object properties\nobject_width = 30\nobject_height = 30\nobject_speed = 5\n\n# Create multiple objects\nnum_objects = 5\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - object_width), 'y': -object_height} for _ in range(num_objects)]\n\n# Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x\n\n# Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + object_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + object_height > basket_y):\n        return True\n    return False\n\n# Main game loop\nrunning = True\nscore = 0\nlives = 3\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    for obj in objects:\n        obj['y'] += object_speed\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n            score += 1  # Increase score when the object safely passes\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            lives -= 1\n            obj['y'] = -object_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - object_width)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        pygame.draw.rect(screen, RED, (obj['x'], obj['y'], object_width, object_height))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Version 3 &#8211; With Aliens<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s add some graphic<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/formazione\/game_falling_aliens\" data-type=\"link\" data-id=\"https:\/\/github.com\/formazione\/game_falling_aliens\">Github repository<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"824\" height=\"656\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-1.png\" alt=\"\" class=\"wp-image-13890\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-1.png 824w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-1-320x255.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-1-768x611.png 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The code<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\nimport time\n\n# Initialize Pygame\npygame.init()\n\n# Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\n\n# Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Avoid the Falling Aliens\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()\n\n# Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 10\n\n# Load alien images\nalien_images = [pygame.image.load(f'alien{i}.png') for i in range(1, 4)]\nalien_width = alien_images[0].get_width()\nalien_height = alien_images[0].get_height()\n\n# Object properties\nobject_speed = 5\n\n# Create multiple objects\nnum_objects = 5\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - alien_width), \n            'y': -alien_height, \n            'image': random.choice(alien_images), \n            'speed': random.randint(3, 6)} for _ in range(num_objects)]\n\n# Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x\n\n# Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + alien_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + alien_height > basket_y):\n        return True\n    return False\n\n# Main game loop\nrunning = True\nscore = 0\nlives = 3\nstart_time = time.time()\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    current_time = time.time()\n    for obj in objects:\n        obj['y'] += obj['speed']\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -alien_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - alien_width)\n            obj['image'] = random.choice(alien_images)\n            obj['speed'] = random.randint(3, 6) + int((current_time - start_time) \/ 10)\n            score += 1  # Increase score when the object safely passes\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            lives -= 1\n            obj['y'] = -alien_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - alien_width)\n            obj['image'] = random.choice(alien_images)\n            obj['speed'] = random.randint(3, 6) + int((current_time - start_time) \/ 10)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        screen.blit(obj['image'], (obj['x'], obj['y']))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Loading from a spreadsheet<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\nimport random\nimport time\n\n# Initialize Pygame\npygame.init()\n\n# Constants\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 600\nFPS = 60\n\n# Colors\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\n\n# Set up the display\nscreen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\npygame.display.set_caption(\"Avoid the Falling Aliens\")\n\n# Clock for controlling the frame rate\nclock = pygame.time.Clock()\n\n# Basket properties\nbasket_width = 100\nbasket_height = 20\nbasket_x = (SCREEN_WIDTH - basket_width) \/\/ 2\nbasket_y = SCREEN_HEIGHT - basket_height - 10\nbasket_speed = 10\n\n# Load sprite sheet and split into individual images\ndef load_spritesheet(filename, sprite_width, sprite_height, num_sprites):\n    sheet = pygame.image.load(filename).convert_alpha()\n    sprites = []\n    for i in range(num_sprites):\n        rect = pygame.Rect(i * sprite_width, 0, sprite_width, sprite_height)\n        image = sheet.subsurface(rect)\n        sprites.append(image)\n    return sprites\n\n# Load alien images from sprite sheet\nalien_images = load_spritesheet('aliens_spritesheet2.png', 30, 30, 3)\nalien_width = alien_images[0].get_width()\nalien_height = alien_images[0].get_height()\n\n# Object properties\nobject_speed = 5\n\n# Create multiple objects\nnum_objects = 5\nobjects = [{'x': random.randint(0, SCREEN_WIDTH - alien_width), \n            'y': -alien_height, \n            'image': random.choice(alien_images), \n            'speed': random.randint(3, 6)} for _ in range(num_objects)]\n\n# Basket movement\ndef move_basket(keys, basket_x):\n    if keys[pygame.K_LEFT] and basket_x > 0:\n        basket_x -= basket_speed\n    if keys[pygame.K_RIGHT] and basket_x &lt; SCREEN_WIDTH - basket_width:\n        basket_x += basket_speed\n    return basket_x\n\n# Check for collision\ndef check_collision(basket_x, basket_y, object_x, object_y):\n    if (object_x &lt; basket_x + basket_width and\n        object_x + alien_width > basket_x and\n        object_y &lt; basket_y + basket_height and\n        object_y + alien_height > basket_y):\n        return True\n    return False\n\n# Main game loop\nrunning = True\nscore = 0\nlives = 3\nstart_time = time.time()\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    keys = pygame.key.get_pressed()\n    basket_x = move_basket(keys, basket_x)\n\n    # Move the objects\n    current_time = time.time()\n    for obj in objects:\n        obj['y'] += obj['speed']\n        if obj['y'] > SCREEN_HEIGHT:\n            obj['y'] = -alien_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - alien_width)\n            obj['image'] = random.choice(alien_images)\n            obj['speed'] = random.randint(3, 6) + int((current_time - start_time) \/ 10)\n            score += 1  # Increase score when the object safely passes\n\n        # Check for collision\n        if check_collision(basket_x, basket_y, obj['x'], obj['y']):\n            lives -= 1\n            obj['y'] = -alien_height\n            obj['x'] = random.randint(0, SCREEN_WIDTH - alien_width)\n            obj['image'] = random.choice(alien_images)\n            obj['speed'] = random.randint(3, 6) + int((current_time - start_time) \/ 10)\n\n    if lives &lt;= 0:\n        running = False\n\n    # Fill the screen with a color\n    screen.fill(WHITE)\n\n    # Draw the basket\n    pygame.draw.rect(screen, BLACK, (basket_x, basket_y, basket_width, basket_height))\n\n    # Draw the objects\n    for obj in objects:\n        screen.blit(obj['image'], (obj['x'], obj['y']))\n\n    # Display the score and lives\n    font = pygame.font.Font(None, 36)\n    score_text = font.render(f\"Score: {score}\", True, BLACK)\n    lives_text = font.render(f\"Lives: {lives}\", True, BLACK)\n    screen.blit(score_text, (10, 10))\n    screen.blit(lives_text, (10, 50))\n\n    # Update the display\n    pygame.display.flip()\n\n    # Control the frame rate\n    clock.tick(FPS)\n\npygame.quit()\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><!-- se vuoi mettere un testo scorrevole\r\n[hoops name=\"typeWriterGen\"]\r\n\r\npoi metti un id diverso per ogni testo nella stessa pagina\r\n\r\n<div id=\"div01\">\r\n<script>\r\n\r\ntypeWriterGen(\"div01\",\"Esempio di testo scorrevole\");\r\n<\/script>\r\n\r\n-->\r\n<style>\r\n.avatar {\r\n  vertical-align: middle;\r\n  width: 100px;\r\n  height: 100px;\r\n  border-radius: 50%;\r\n}\r\n<\/style>\r\n\r\n<hr>\r\n\r\n<!-- NEWSLETTER LINK -->\r\n<a href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSf7TniIPCWHDzCSGh2dYZaCwDvi9yLKS5ovFdKuK1sdfOvwEg\/viewform\">\r\n<img decoding=\"async\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-13.png\" class=\"avatar\">\r\nSubscribe to the <b>newsletter<\/b> for updates<\/a><br>\r\n\r\n<!-- TKINTER TEMPLATE LINK -->\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/tkinter-templates\/\">\r\n<img decoding=\"async\" src=\"https:\/\/i0.wp.com\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/07\/image-26.png\" class=\"avatar\">\r\nTkinter templates<\/a><br>\r\n\r\n<!-- MY AVATAR PUT A LINK TO YOUTUBE CHANNEL-->\r\n<iframe loading=\"lazy\" frameborder=\"0\" src=\"https:\/\/itch.io\/embed\/711828\" width=\"552\" height=\"167\"><a href=\"https:\/\/pythonprogrammi.itch.io\/pysnake\">PySnake by PythonProgrammi<\/a><\/iframe>\r\n<br>\r\n<style>\r\n.avatar {\r\n  vertical-align: middle;\r\n  width: 100px;\r\n  height: 100px;\r\n  border-radius: 50%;\r\n}\r\n<\/style>\r\n\r\n\r\n<a href=\"https:\/\/www.youtube.com\/channel\/UCzbxq5e9gLiY-je2-br1rvg\">\r\n\t<img decoding=\"async\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/10\/avatar64x64.png\" alt=\"Avatar\" class=\"avatar\">\r\n\t My youtube channel<\/a><br>\r\n\r\n<br>\r\n\r\nTwitter: <a href=\"https:\/\/twitter.com\/pythonprogrammi\">@pythonprogrammi - python_pygame<\/a>\r\n<h3>Claude's Games<\/h3>\r\n<p><a href=\"https:\/\/pythonprogramming.altervista.org\/random-daily-game-1-arkanoid\/\">Arkanoid<\/a><br>\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/platform-2d-with-pygame-made-with-claude\/\">Platform 2d<\/a><\/p> <!-- videogames made with claude -->\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/artifacts-games-day-1-memory-game\/\">1. Memory game<\/a>\r\n<h4>Videos<\/h4>\r\n<a href=\"https:\/\/youtu.be\/ciLjWWw5pLY\">Speech recognition game<\/a>\r\n<h3>Pygame's Platform Game<\/h3>\r\n\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\"><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/climbercover.png?w=557&ssl=1\"\/ width=\"50%\"><\/a>\r\n<script>\r\nvar title = \"Platform Pygame\";\r\n\t\tvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animation-of-a-sprite-v-1-3\/\",\"Animation 1.3\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-v-2-better-coding-test-it-checking-fps-on-the-screen\/\",\"Animation 1.2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-how-to-display-the-frame-rate-fps-on-the-screen\/\",\"Display Frame rate\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-update\/\",\"Animation 1.1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Pygame Platform Game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-platform-game-2\/\",\"Pygame Platform 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-3-recap-cheatsheet\/\",\"Pygame PLatform 3 - recap and some Cheat Sheet\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-4-background-and-stuffs\/\",\"Pygame Platform 4 - Background & organizing code\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\",\"Pygame Platform 5 - Sounds\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/platform-game-in-detail-part-1\/\",\"Game in detail part 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/map-maker-1-2\/\", \"Map maker 1.2\"]\r\n\t\t];\r\n\t\t<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\r\n\r\n<h3>Other Pygame's posts<\/h3>\r\n\r\n<script>\r\nvar title = \"Pygame's Posts\"\r\nvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Platform game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/make-a-platform-game-with-pygame-dafluffypotato\/\",\"DaFluffyPotato Platform Tutorials\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-and-classic-arcade-games-pong\/\",\"Pong Game Full\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-draws-in-colors-app-to-draw-with-pygame\/\",\"PyGameGIF 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-draw-app-with-animation\/\",\"PyGameGIF 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pydraw-2-0-app-to-draw-gif\/\",\"PyDraw 2.0\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-drawing-2\/\",\"Draw with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-with-pygame\",\"Sprite animation 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-on-pygame-2-free-characters-and-more-actions\/\",\"Sprite animation 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/starting-with-pygame\/\",\"Starting movements with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-3-move-sprite\/\", \"Move a Sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-4-fonts\/\",\"Text and Fonts\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animate-a-sprite\/\", \"Animate a sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-and-mouse-events\/\",\"Mouse events\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pgp-aka-pygamepresentation-project\/\",\"Pygame presentation\"],\r\n\t[\"https:\/\/pythonprogramming.altervista.org\/moving-the-player-in-pygame-with-key-get_pressed\/\",\"How to use key.get_pressed()\"]\r\n]\r\n<\/script>\r\n\r\n\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"a game in 2 versions\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/simple-game\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":13885,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[191],"tags":[194,4],"class_list":["post-13884","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pygame","tag-pygame","tag-python"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":true,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=13884"}],"version-history":[{"count":6,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13884\/revisions"}],"predecessor-version":[{"id":13906,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13884\/revisions\/13906"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/13885"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=13884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=13884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=13884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}