{"id":13992,"date":"2024-06-25T13:35:26","date_gmt":"2024-06-25T11:35:26","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=13992"},"modified":"2024-06-25T13:47:42","modified_gmt":"2024-06-25T11:47:42","slug":"mr-do-with-pygame","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/mr-do-with-pygame\/","title":{"rendered":"Mr. Do! with pygame"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Remaking 2d games with Claude and Chat GPT\" width=\"747\" height=\"560\" src=\"https:\/\/www.youtube.com\/embed\/zIVoyPbFGN8?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n<\/div><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">make a game like mr. do!<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"644\" style=\"aspect-ratio: 810 \/ 644;\" width=\"810\" controls src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/001.mp4\"><\/video><\/figure>\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# Set up the display\nWIDTH, HEIGHT = 800, 600\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\npygame.display.set_caption(\"Mr. Do!-like Game\")\n\n# Colors\nBLACK = (0, 0, 0)\nWHITE = (255, 255, 255)\nRED = (255, 0, 0)\nGREEN = (0, 255, 0)\n\n# Player\nplayer_size = 40\nplayer_x = WIDTH \/\/ 2\nplayer_y = HEIGHT \/\/ 2\nplayer_speed = 5\n\n# Cherries\ncherry_size = 20\ncherries = []\n\n# Enemies\nenemy_size = 30\nenemies = []\n\n# Score\nscore = 0\nfont = pygame.font.Font(None, 36)\n\ndef spawn_cherry():\n    x = random.randint(0, WIDTH - cherry_size)\n    y = random.randint(0, HEIGHT - cherry_size)\n    cherries.append(pygame.Rect(x, y, cherry_size, cherry_size))\n\ndef spawn_enemy():\n    x = random.randint(0, WIDTH - enemy_size)\n    y = random.randint(0, HEIGHT - enemy_size)\n    enemies.append(pygame.Rect(x, y, enemy_size, enemy_size))\n\n# Game loop\nrunning = True\nclock = pygame.time.Clock()\n\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n\n    # Move player\n    keys = pygame.key.get_pressed()\n    if keys[pygame.K_LEFT]:\n        player_x -= player_speed\n    if keys[pygame.K_RIGHT]:\n        player_x += player_speed\n    if keys[pygame.K_UP]:\n        player_y -= player_speed\n    if keys[pygame.K_DOWN]:\n        player_y += player_speed\n\n    # Keep player on screen\n    player_x = max(0, min(player_x, WIDTH - player_size))\n    player_y = max(0, min(player_y, HEIGHT - player_size))\n\n    # Spawn cherries\n    if random.randint(1, 60) == 1:\n        spawn_cherry()\n\n    # Spawn enemies\n    if random.randint(1, 180) == 1:\n        spawn_enemy()\n\n    # Check collisions\n    player_rect = pygame.Rect(player_x, player_y, player_size, player_size)\n    for cherry in cherries[:]:\n        if player_rect.colliderect(cherry):\n            cherries.remove(cherry)\n            score += 10\n\n    for enemy in enemies[:]:\n        if player_rect.colliderect(enemy):\n            running = False\n\n    # Draw everything\n    screen.fill(BLACK)\n    pygame.draw.rect(screen, WHITE, (player_x, player_y, player_size, player_size))\n    for cherry in cherries:\n        pygame.draw.rect(screen, RED, cherry)\n    for enemy in enemies:\n        pygame.draw.rect(screen, GREEN, enemy)\n\n    # Draw score\n    score_text = font.render(f\"Score: {score}\", True, WHITE)\n    screen.blit(score_text, (10, 10))\n\n    pygame.display.flip()\n    clock.tick(60)\n\npygame.quit()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. The labyrinth<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>first attempt<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">put the player and the enemies into a labyrinth and make the enemies chace the player<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>second attempt<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">draw the labyrint and if the game is over, make it possible to start again. Add score for every cherry eaten<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Now we got the labyrinth, not bad if it wasn&#8217;t for the fact that we cannot escape the enemies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s ask to be able to dig and destroy walls with a key and fire a ball with another that bounces on the wall and kill enemies the enemies. We got one ball and we get touch it after we throu it we can launch it again.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-23.png\"><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"646\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-23.png\" alt=\"\" class=\"wp-image-13994\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-23.png 814w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-23-320x254.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-23-768x609.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/a><\/figure>\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# Set up the display\nWIDTH, HEIGHT = 800, 600\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\npygame.display.set_caption(\"Mr. Do!-like Game\")\n\n# Colors\nBLACK = (0, 0, 0)\nWHITE = (255, 255, 255)\nRED = (255, 0, 0)\nGREEN = (0, 255, 0)\nBLUE = (0, 0, 255)\nWALL_COLOR = (100, 50, 0)  # Brown color for walls\n\n# Grid settings\nGRID_SIZE = 40\nGRID_WIDTH = WIDTH \/\/ GRID_SIZE\nGRID_HEIGHT = HEIGHT \/\/ GRID_SIZE\n\n# Font\nfont = pygame.font.Font(None, 36)\n\n# Game variables\nplayer_x = player_y = 1\nenemies = []\ncherries = []\nscore = 0\ngame_over = False\n\ndef create_labyrinth():\n    labyrinth = [[1 for _ in range(GRID_WIDTH)] for _ in range(GRID_HEIGHT)]\n\n    def create_path(x, y):\n        labyrinth[y][x] = 0\n        directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n        random.shuffle(directions)\n        for dx, dy in directions:\n            nx, ny = x + dx*2, y + dy*2\n            if 0 &lt;= nx &lt; GRID_WIDTH and 0 &lt;= ny &lt; GRID_HEIGHT and labyrinth[ny][nx] == 1:\n                labyrinth[y + dy][x + dx] = 0\n                create_path(nx, ny)\n\n    create_path(1, 1)\n    return labyrinth\n\ndef place_cherries():\n    cherries = []\n    for _ in range(20):\n        x, y = random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1)\n        if labyrinth[y][x] == 0:\n            cherries.append((x, y))\n    return cherries\n\ndef place_enemies():\n    enemies = []\n    for _ in range(3):\n        while True:\n            x, y = random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1)\n            if labyrinth[y][x] == 0 and (x, y) != (player_x, player_y):\n                enemies.append([x, y])\n                break\n    return enemies\n\ndef move_towards(enemy, target_x, target_y):\n    dx = target_x - enemy[0]\n    dy = target_y - enemy[1]\n    if abs(dx) > abs(dy):\n        return (enemy[0] + (1 if dx > 0 else -1), enemy[1])\n    else:\n        return (enemy[0], enemy[1] + (1 if dy > 0 else -1))\n\ndef draw_game():\n    screen.fill(BLACK)\n    \n    # Draw labyrinth\n    for y in range(GRID_HEIGHT):\n        for x in range(GRID_WIDTH):\n            if labyrinth[y][x] == 1:\n                pygame.draw.rect(screen, WALL_COLOR, (x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE, GRID_SIZE))\n                pygame.draw.rect(screen, BLACK, (x * GRID_SIZE + 2, y * GRID_SIZE + 2, GRID_SIZE - 4, GRID_SIZE - 4))\n\n    # Draw player\n    pygame.draw.circle(screen, WHITE, (player_x * GRID_SIZE + GRID_SIZE \/\/ 2, player_y * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 2 - 2)\n\n    # Draw cherries\n    for cherry in cherries:\n        pygame.draw.circle(screen, RED, (cherry[0] * GRID_SIZE + GRID_SIZE \/\/ 2, cherry[1] * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 4)\n\n    # Draw enemies\n    for enemy in enemies:\n        pygame.draw.rect(screen, GREEN, (enemy[0] * GRID_SIZE + 2, enemy[1] * GRID_SIZE + 2, GRID_SIZE - 4, GRID_SIZE - 4))\n\n    # Draw score\n    score_text = font.render(f\"Score: {score}\", True, WHITE)\n    screen.blit(score_text, (10, 10))\n\n    if game_over:\n        game_over_text = font.render(\"Game Over! Press R to Restart\", True, WHITE)\n        screen.blit(game_over_text, (WIDTH \/\/ 2 - game_over_text.get_width() \/\/ 2, HEIGHT \/\/ 2 - game_over_text.get_height() \/\/ 2))\n\n    pygame.display.flip()\n\ndef reset_game():\n    global player_x, player_y, enemies, cherries, score, game_over, labyrinth\n    player_x = player_y = 1\n    labyrinth = create_labyrinth()\n    cherries = place_cherries()\n    enemies = place_enemies()\n    score = 0\n    game_over = False\n\n# Initial game setup\nreset_game()\n\n# Game loop\nrunning = True\nclock = pygame.time.Clock()\n\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n        elif event.type == pygame.KEYDOWN:\n            if game_over:\n                if event.key == pygame.K_r:\n                    reset_game()\n            else:\n                new_x, new_y = player_x, player_y\n                if event.key == pygame.K_LEFT:\n                    new_x -= 1\n                elif event.key == pygame.K_RIGHT:\n                    new_x += 1\n                elif event.key == pygame.K_UP:\n                    new_y -= 1\n                elif event.key == pygame.K_DOWN:\n                    new_y += 1\n                \n                if 0 &lt;= new_x &lt; GRID_WIDTH and 0 &lt;= new_y &lt; GRID_HEIGHT and labyrinth[new_y][new_x] == 0:\n                    player_x, player_y = new_x, new_y\n\n    if not game_over:\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_towards(enemy, player_x, player_y)\n            if labyrinth[new_pos[1]][new_pos[0]] == 0:\n                enemy[0], enemy[1] = new_pos\n\n        # Check collisions\n        if (player_x, player_y) in cherries:\n            cherries.remove((player_x, player_y))\n            score += 10\n\n        if [player_x, player_y] in enemies:\n            game_over = True\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Ball bouncing<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Make the player able to destroy walls with &#8220;z&#8221; and to launch a ball with &#8220;x&#8221;. The has a diagonal direction and bounces on the walls. If it reaches an enemy, kills the enemy and return to the player that can launch one ball at the time until it returns it back. If the player get into the ball the ball stops to move and the player can launch the ball again.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Claude stopped me for a couple of hour because I exeeded my messages, so I turned to Chat GPT to correct a bug there was in the code and it gave me this<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"646\" style=\"aspect-ratio: 818 \/ 646;\" width=\"818\" controls src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/20240625-1130-03.9578528.mp4\"><\/video><\/figure>\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 math\n\n# Initialize Pygame\npygame.init()\n\n# Set up the display\nWIDTH, HEIGHT = 800, 600\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\npygame.display.set_caption(\"Mr. Do!-like Game\")\n\n# Colors\nBLACK = (0, 0, 0)\nWHITE = (255, 255, 255)\nRED = (255, 0, 0)\nGREEN = (0, 255, 0)\nBLUE = (0, 0, 255)\nWALL_COLOR = (100, 50, 0)\nBALL_COLOR = (255, 165, 0)  # Orange\n\n# Grid settings\nGRID_SIZE = 40\nGRID_WIDTH = WIDTH \/\/ GRID_SIZE\nGRID_HEIGHT = HEIGHT \/\/ GRID_SIZE\n\n# Font\nfont = pygame.font.Font(None, 36)\n\n# Game variables\nplayer_x = player_y = 1\nplayer_direction = 0  # 0: right, 1: down, 2: left, 3: up\nenemies = []\ncherries = []\nscore = 0\ngame_over = False\n\n# Ball variables\nball_x = ball_y = None\nball_direction = None\nball_active = False\n\ndef create_labyrinth():\n    labyrinth = [[1 for _ in range(GRID_WIDTH)] for _ in range(GRID_HEIGHT)]\n\n    def create_path(x, y):\n        labyrinth[y][x] = 0\n        directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n        random.shuffle(directions)\n        for dx, dy in directions:\n            nx, ny = x + dx*2, y + dy*2\n            if 0 &lt;= nx &lt; GRID_WIDTH and 0 &lt;= ny &lt; GRID_HEIGHT and labyrinth[ny][nx] == 1:\n                labyrinth[y + dy][x + dx] = 0\n                create_path(nx, ny)\n\n    create_path(1, 1)\n    return labyrinth\n\ndef place_cherries():\n    return [(x, y) for y in range(GRID_HEIGHT) for x in range(GRID_WIDTH) \n            if labyrinth[y][x] == 0 and random.random() &lt; 0.1]\n\ndef place_enemies():\n    enemy_list = []\n    while len(enemy_list) &lt; 3:\n        x, y = random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1)\n        if labyrinth[y][x] == 0 and (x, y) != (player_x, player_y):\n            enemy_list.append([x, y])\n    return enemy_list\n\ndef move_towards(enemy, target_x, target_y):\n    dx = target_x - enemy[0]\n    dy = target_y - enemy[1]\n    if abs(dx) > abs(dy):\n        return (enemy[0] + (1 if dx > 0 else -1), enemy[1])\n    else:\n        return (enemy[0], enemy[1] + (1 if dy > 0 else -1))\n\ndef launch_ball():\n    global ball_x, ball_y, ball_direction, ball_active\n    if not ball_active:\n        ball_x, ball_y = player_x, player_y\n        ball_direction = player_direction\n        ball_active = True\n\ndef move_ball():\n    global ball_x, ball_y, ball_direction, ball_active, enemies, score\n    if ball_active:\n        directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        dx, dy = directions[ball_direction]\n        new_x, new_y = ball_x + dx, ball_y + dy\n\n        if 0 &lt;= new_x &lt; GRID_WIDTH and 0 &lt;= new_y &lt; GRID_HEIGHT:\n            if labyrinth[new_y][new_x] == 1:\n                if dx != 0 and labyrinth[ball_y][new_x] == 1:\n                    ball_direction = (ball_direction + 2) % 4  # Reverse x direction\n                elif dy != 0 and labyrinth[new_y][ball_x] == 1:\n                    ball_direction = (ball_direction + 2) % 4  # Reverse y direction\n                else:\n                    ball_direction = (ball_direction + 1) % 4  # Change direction\n            else:\n                ball_x, ball_y = new_x, new_y\n\n                # Check for enemy collision\n                for enemy in enemies[:]:\n                    if ball_x == enemy[0] and ball_y == enemy[1]:\n                        enemies.remove(enemy)\n                        score += 50\n                        ball_active = False\n                        return\n\n                # Check for player collision\n                if ball_x == player_x and ball_y == player_y:\n                    ball_active = False\n        else:\n            ball_active = False  # Deactivate ball at screen edge\n\ndef draw_game():\n    screen.fill(BLACK)\n    \n    # Draw labyrinth\n    for y in range(GRID_HEIGHT):\n        for x in range(GRID_WIDTH):\n            if labyrinth[y][x] == 1:\n                pygame.draw.rect(screen, WALL_COLOR, (x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE, GRID_SIZE))\n                pygame.draw.rect(screen, BLACK, (x * GRID_SIZE + 2, y * GRID_SIZE + 2, GRID_SIZE - 4, GRID_SIZE - 4))\n\n    # Draw player\n    pygame.draw.circle(screen, WHITE, (player_x * GRID_SIZE + GRID_SIZE \/\/ 2, player_y * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 2 - 2)\n\n    # Draw cherries\n    for cherry in cherries:\n        pygame.draw.circle(screen, RED, (cherry[0] * GRID_SIZE + GRID_SIZE \/\/ 2, cherry[1] * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 4)\n\n    # Draw enemies\n    for enemy in enemies:\n        pygame.draw.rect(screen, GREEN, (enemy[0] * GRID_SIZE + 2, enemy[1] * GRID_SIZE + 2, GRID_SIZE - 4, GRID_SIZE - 4))\n\n    # Draw ball\n    if ball_active:\n        pygame.draw.circle(screen, BALL_COLOR, (ball_x * GRID_SIZE + GRID_SIZE \/\/ 2, ball_y * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 4)\n\n    # Draw score\n    score_text = font.render(f\"Score: {score}\", True, WHITE)\n    screen.blit(score_text, (10, 10))\n\n    if game_over:\n        game_over_text = font.render(\"Game Over! Press R to Restart\", True, WHITE)\n        screen.blit(game_over_text, (WIDTH \/\/ 2 - game_over_text.get_width() \/\/ 2, HEIGHT \/\/ 2 - game_over_text.get_height() \/\/ 2))\n\n    pygame.display.flip()\n\ndef reset_game():\n    global player_x, player_y, player_direction, enemies, cherries, score, game_over, labyrinth, ball_active\n    player_x = player_y = 1\n    player_direction = 0\n    labyrinth = create_labyrinth()\n    cherries = place_cherries()\n    enemies = place_enemies()\n    score = 0\n    game_over = False\n    ball_active = False\n\n# Initial game setup\nreset_game()\n\n# Game loop\nrunning = True\nclock = pygame.time.Clock()\n\nwhile running:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            running = False\n        elif event.type == pygame.KEYDOWN:\n            if game_over:\n                if event.key == pygame.K_r:\n                    reset_game()\n            else:\n                new_x, new_y = player_x, player_y\n                if event.key == pygame.K_LEFT:\n                    new_x -= 1\n                    player_direction = 2\n                elif event.key == pygame.K_RIGHT:\n                    new_x += 1\n                    player_direction = 0\n                elif event.key == pygame.K_UP:\n                    new_y -= 1\n                    player_direction = 3\n                elif event.key == pygame.K_DOWN:\n                    new_y += 1\n                    player_direction = 1\n                elif event.key == pygame.K_z:\n                    # Destroy wall\n                    dx, dy = [(1, 0), (0, 1), (-1, 0), (0, -1)][player_direction]\n                    wall_x, wall_y = player_x + dx, player_y + dy\n                    if 0 &lt;= wall_x &lt; GRID_WIDTH and 0 &lt;= wall_y &lt; GRID_HEIGHT:\n                        if labyrinth[wall_y][wall_x] == 1:\n                            labyrinth[wall_y][wall_x] = 0\n                            score += 5\n                elif event.key == pygame.K_x:\n                    launch_ball()\n                \n                if 0 &lt;= new_x &lt; GRID_WIDTH and 0 &lt;= new_y &lt; GRID_HEIGHT and labyrinth[new_y][new_x] == 0:\n                    player_x, player_y = new_x, new_y\n\n    if not game_over:\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_towards(enemy, player_x, player_y)\n            if labyrinth[new_pos[1]][new_pos[0]] == 0:\n                enemy[0], enemy[1] = new_pos\n\n        # Move ball\n        move_ball()\n\n        # Check collisions\n        if (player_x, player_y) in cherries:\n            cherries.remove((player_x, player_y))\n            score += 10\n\n        if [player_x, player_y] in enemies:\n            game_over = True\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see the game is getting some sense, even if the tajectory of the ball is not what I intended but it comes back and works well apart for the direction, but that can be fixed in the next post. Bye.<\/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":"make a game like mr. do! 2. The labyrinth first attempt put the player and the enemies into a labyrinth and make the \n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/mr-do-with-pygame\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":13994,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[158,194,4],"class_list":["post-13992","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","tag-games","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\/13992","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=13992"}],"version-history":[{"count":2,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13992\/revisions"}],"predecessor-version":[{"id":13997,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13992\/revisions\/13997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/13994"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=13992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=13992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=13992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}