{"id":13998,"date":"2024-06-27T11:50:54","date_gmt":"2024-06-27T09:50:54","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=13998"},"modified":"2024-06-27T11:50:55","modified_gmt":"2024-06-27T09:50:55","slug":"mr-do-part-ii","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/mr-do-part-ii\/","title":{"rendered":"Mr Do! Part II"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pythonprogramming.altervista.org\/mr-do-with-pygame\/\" data-type=\"post\" data-id=\"13992\">Part I<\/a><\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"650\" style=\"aspect-ratio: 812 \/ 650;\" width=\"812\" controls src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/004.mp4\"><\/video><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Prompt<\/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\">move the enemies in some direction randomly and only if there are no walls between the player and the enemy make the enemy chace the player. make the ball direction to be diagonal up and then bounce in diagonal down and the up and so on. If the player eats all cherry go to level 2 with one more enemy for every new level<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">To address your requirements, we&#8217;ll make the following changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Move Enemies Randomly<\/strong>: Enemies will move in a random direction unless there are no walls between the player and the enemy, in which case they will chase the player.<\/li>\n\n\n\n<li><strong>Ball Direction<\/strong>: The ball will move diagonally and bounce between diagonal up and diagonal down.<\/li>\n\n\n\n<li><strong>Level Up<\/strong>: When all cherries are eaten, the game advances to the next level with one additional enemy.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the updated 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 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\nlevel = 1\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; level + 2:\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 can_chase_player(enemy_x, enemy_y):\n    if enemy_x == player_x:\n        if all(labyrinth[y][enemy_x] == 0 for y in range(min(enemy_y, player_y), max(enemy_y, player_y) + 1)):\n            return True\n    if enemy_y == player_y:\n        if all(labyrinth[enemy_y][x] == 0 for x in range(min(enemy_x, player_x), max(enemy_x, player_x) + 1)):\n            return True\n    return False\n\ndef move_enemy(enemy):\n    if can_chase_player(enemy[0], enemy[1]):\n        return move_towards(enemy, player_x, player_y)\n    else:\n        possible_moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        random.shuffle(possible_moves)\n        for dx, dy in possible_moves:\n            new_x, new_y = enemy[0] + dx, enemy[1] + dy\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                return (new_x, new_y)\n        return (enemy[0], enemy[1])\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 = 0  # Start moving diagonally up\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, -1), (1, 1), (-1, 1), (-1, -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                ball_direction = (ball_direction + 2) % 4  # Bounce diagonally\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_direction = (ball_direction + 2) % 4  # Reverse direction 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, level\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,\n\n 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_enemy(enemy)\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        # Level up\n        if not cherries:\n            level += 1\n            cherries = place_cherries()\n            enemies = place_enemies()\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Changes:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Enemy Movement<\/strong>: Enemies move randomly unless there are no walls between the enemy and the player, in which case they chase the player.<\/li>\n\n\n\n<li><strong>Ball Movement<\/strong>: The ball moves diagonally and bounces between diagonal up and diagonal down directions.<\/li>\n\n\n\n<li><strong>Level Up<\/strong>: When all cherries are eaten, the game advances to the next level with one additional enemy for every new level.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to test the game and make further modifications as needed!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-24.png\"><img loading=\"lazy\" decoding=\"async\" width=\"764\" height=\"594\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-24.png\" alt=\"\" class=\"wp-image-14004\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-24.png 764w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2024\/06\/image-24-320x249.png 320w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. Let&#8217;s move constantly<\/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\">move the player constantly until he reaches a wall or changes direction. Make the ball smaller and make it bounce<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Move the walls<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The walls of the labyrinth is made of blocks, ok? make the player to be able to move a block of the labyrinth with the key &#8220;a&#8221; if there is not another block where the block would be moved to. So if the player moves with &#8220;a&#8221; a block towards right, the block moves only if there are no other blocks on the right of the block. The same for the other directions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To implement the functionality where the player can move blocks of the labyrinth using the &#8220;a&#8221; key, we&#8217;ll need to add logic to handle block pushing in all four directions. The player can push a block only if there&#8217;s no other block in the direction the block is being moved.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how to implement these changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Add Block Pushing Logic<\/strong>: Implement the logic to check if the player can push a block in the given direction and move it if possible.<\/li>\n\n\n\n<li><strong>Handle Pushing Direction<\/strong>: Use the player&#8217;s current direction to determine which direction to push the block.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the updated code with these changes:<\/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 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\nlevel = 1\n\n# Ball variables\nball_x = ball_y = None\nball_direction = None\nball_active = False\nBALL_SIZE = GRID_SIZE \/\/ 6  # Smaller ball size\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; level + 2:\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 can_chase_player(enemy_x, enemy_y):\n    if enemy_x == player_x:\n        if all(labyrinth[y][enemy_x] == 0 for y in range(min(enemy_y, player_y), max(enemy_y, player_y) + 1)):\n            return True\n    if enemy_y == player_y:\n        if all(labyrinth[enemy_y][x] == 0 for x in range(min(enemy_x, player_x), max(enemy_x, player_x) + 1)):\n            return True\n    return False\n\ndef move_enemy(enemy):\n    if can_chase_player(enemy[0], enemy[1]):\n        return move_towards(enemy, player_x, player_y)\n    else:\n        possible_moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        random.shuffle(possible_moves)\n        for dx, dy in possible_moves:\n            new_x, new_y = enemy[0] + dx, enemy[1] + dy\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                return (new_x, new_y)\n        return (enemy[0], enemy[1])\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 = 0  # Start moving diagonally up\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, -1), (1, 1), (-1, 1), (-1, -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                ball_direction = (ball_direction + 2) % 4  # Bounce diagonally\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_direction = (ball_direction + 2) % 4  # Reverse direction at screen edge\n\ndef move_player():\n    global player_x, player_y\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    new_x, new_y = player_x + dx, player_y + dy\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\ndef push_block():\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    block_x, block_y = player_x + dx, player_y + dy\n    new_block_x, new_block_y = block_x + dx, block_y + dy\n\n    if 0 &lt;= block_x &lt; GRID_WIDTH and 0 &lt;= block_y &lt; GRID_HEIGHT:\n        if labyrinth[block_y][block_x] == 1:\n            if 0 &lt;= new_block_x &lt; GRID_WIDTH and 0 &lt;= new_block_y &lt; GRID_HEIGHT and labyrinth[new_block_y][new_block_x] == 0:\n                labyrinth[block_y][block_x] = 0\n                labyrinth[new_block_y][new_block_x] = 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 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), BALL_SIZE)\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()\n\n \/\/ 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, level\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                if event.key == pygame.K_LEFT:\n                    player_direction = 2\n                elif event.key == pygame.K_RIGHT:\n                    player_direction = 0\n                elif event.key == pygame.K_UP:\n                    player_direction = 3\n                elif event.key == pygame.K_DOWN:\n                    player_direction = 1\n                elif event.key == pygame.K_a:\n                    push_block()\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 not game_over:\n        # Move player\n        move_player()\n\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_enemy(enemy)\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        # Level up\n        if not cherries:\n            level += 1\n            cherries = place_cherries()\n            enemies = place_enemies()\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Changes:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Block Pushing Logic<\/strong>: Added the <code>push_block<\/code> function to handle pushing blocks in the player&#8217;s current direction.<\/li>\n\n\n\n<li><strong>Handle Pushing Direction<\/strong>: Integrated block pushing logic with the player&#8217;s current direction when the &#8220;a&#8221; key is pressed.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to test the game and make further modifications as needed!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. The bomb<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\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 that the ball can be left where the player is like a bomb. When the enemy gets in the ball, the enemy explode in pieces and is eliminated. The player has 3 bombs max to leave.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To implement the feature where the player can leave the ball as a bomb and eliminate enemies when they step on it, we&#8217;ll make the following changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bomb Placement<\/strong>: Allow the player to place a bomb where they currently stand using a key (e.g., &#8220;x&#8221;). The player can have a maximum of 3 bombs.<\/li>\n\n\n\n<li><strong>Enemy Explosion<\/strong>: Check if an enemy steps on a bomb and eliminate the enemy if they do.<\/li>\n\n\n\n<li><strong>Bomb Management<\/strong>: Track the number of bombs and their positions.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the updated code with these changes:<\/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 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\nlevel = 1\n\n# Bomb variables\nbombs = []\nmax_bombs = 3\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; level + 2:\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 can_chase_player(enemy_x, enemy_y):\n    if enemy_x == player_x:\n        if all(labyrinth[y][enemy_x] == 0 for y in range(min(enemy_y, player_y), max(enemy_y, player_y) + 1)):\n            return True\n    if enemy_y == player_y:\n        if all(labyrinth[enemy_y][x] == 0 for x in range(min(enemy_x, player_x), max(enemy_x, player_x) + 1)):\n            return True\n    return False\n\ndef move_enemy(enemy):\n    if can_chase_player(enemy[0], enemy[1]):\n        return move_towards(enemy, player_x, player_y)\n    else:\n        possible_moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        random.shuffle(possible_moves)\n        for dx, dy in possible_moves:\n            new_x, new_y = enemy[0] + dx, enemy[1] + dy\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                return (new_x, new_y)\n        return (enemy[0], enemy[1])\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 place_bomb():\n    if len(bombs) &lt; max_bombs:\n        bombs.append((player_x, player_y))\n\ndef move_player():\n    global player_x, player_y\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    new_x, new_y = player_x + dx, player_y + dy\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\ndef push_block():\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    block_x, block_y = player_x + dx, player_y + dy\n    new_block_x, new_block_y = block_x + dx, block_y + dy\n\n    if 0 &lt;= block_x &lt; GRID_WIDTH and 0 &lt;= block_y &lt; GRID_HEIGHT:\n        if labyrinth[block_y][block_x] == 1:\n            if 0 &lt;= new_block_x &lt; GRID_WIDTH and 0 &lt;= new_block_y &lt; GRID_HEIGHT and labyrinth[new_block_y][new_block_x] == 0:\n                labyrinth[block_y][block_x] = 0\n                labyrinth[new_block_y][new_block_x] = 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 bombs\n    for bomb in bombs:\n        pygame.draw.circle(screen, BLUE, (bomb[0] * GRID_SIZE + GRID_SIZE \/\/ 2, bomb[1] * 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, bombs, level\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    bombs = []\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                if event.key == pygame.K_LEFT:\n                    player_direction = 2\n                elif event.key == pygame.K_RIGHT:\n                    player_direction = 0\n                elif event.key == pygame.K_UP:\n                    player_direction = 3\n                elif event.key == pygame.K_DOWN:\n                    player_direction = 1\n                elif event.key == pygame.K_a:\n                    push_block()\n                elif event.key == pygame.K_z:\n                    # Destroy wall\n                    dx, dy = [(1, 0), (0, 1), (-1, 0), (0, -1)][player_direction]\n\n\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                    place_bomb()\n\n    if not game_over:\n        # Move player\n        move_player()\n\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_enemy(enemy)\n            enemy[0], enemy[1] = new_pos\n\n        # Check bomb collisions with enemies\n        for enemy in enemies[:]:\n            if (enemy[0], enemy[1]) in bombs:\n                enemies.remove(enemy)\n                bombs.remove((enemy[0], enemy[1]))\n                score += 50\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        # Level up\n        if not cherries:\n            level += 1\n            cherries = place_cherries()\n            enemies = place_enemies()\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Changes:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bomb Placement<\/strong>: Added the <code>place_bomb<\/code> function to allow the player to place bombs on the current player position if the maximum number of bombs has not been reached.<\/li>\n\n\n\n<li><strong>Bomb Management<\/strong>: Track the positions of bombs and check for collisions between enemies and bombs.<\/li>\n\n\n\n<li><strong>Enemy Explosion<\/strong>: When an enemy steps on a bomb, the enemy is removed, and the bomb is also removed.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to test the game and make further modifications as needed!<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">To enhance the game with a ranking system and sound effects, we&#8217;ll make the following changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Score Saving<\/strong>: Implement a mechanism to save and load scores.<\/li>\n\n\n\n<li><strong>Display Ranking<\/strong>: Show the player&#8217;s current rank on the screen next to the score.<\/li>\n\n\n\n<li><strong>Sound Effects<\/strong>: Add sound effects for various actions (destroying walls, pushing walls, killing enemies, being killed by enemies, and finishing a level).<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the updated code with these changes:<\/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 math\nimport os\nimport json\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\nlevel = 1\n\n# Bomb variables\nbombs = []\nmax_bombs = 3\n\n# Load sounds\ndestroy_wall_sound = pygame.mixer.Sound('sounds\/destroy_wall.wav')\npush_wall_sound = pygame.mixer.Sound('sounds\/push_wall.wav')\nkill_enemy_sound = pygame.mixer.Sound('sounds\/kill_enemy.wav')\nplayer_killed_sound = pygame.mixer.Sound('sounds\/player_killed.wav')\nlevel_complete_sound = pygame.mixer.Sound('sounds\/level_complete.wav')\n\n# Scores\nscores_file = 'scores.json'\nscores = []\n\ndef load_scores():\n    global scores\n    if os.path.exists(scores_file):\n        with open(scores_file, 'r') as f:\n            scores = json.load(f)\n    else:\n        scores = []\n\ndef save_scores():\n    with open(scores_file, 'w') as f:\n        json.dump(scores, f)\n\ndef get_rank():\n    sorted_scores = sorted(scores, reverse=True)\n    rank = sorted_scores.index(score) + 1 if score in sorted_scores else len(sorted_scores) + 1\n    return rank\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; level + 2:\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 can_chase_player(enemy_x, enemy_y):\n    if enemy_x == player_x:\n        if all(labyrinth[y][enemy_x] == 0 for y in range(min(enemy_y, player_y), max(enemy_y, player_y) + 1)):\n            return True\n    if enemy_y == player_y:\n        if all(labyrinth[enemy_y][x] == 0 for x in range(min(enemy_x, player_x), max(enemy_x, player_x) + 1)):\n            return True\n    return False\n\ndef move_enemy(enemy):\n    if can_chase_player(enemy[0], enemy[1]):\n        return move_towards(enemy, player_x, player_y)\n    else:\n        possible_moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        random.shuffle(possible_moves)\n        for dx, dy in possible_moves:\n            new_x, new_y = enemy[0] + dx, enemy[1] + dy\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                return (new_x, new_y)\n        return (enemy[0], enemy[1])\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 place_bomb():\n    if len(bombs) &lt; max_bombs:\n        bombs.append((player_x, player_y))\n\ndef move_player():\n    global player_x, player_y\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    new_x, new_y = player_x + dx, player_y + dy\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\ndef push_block():\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    block_x, block_y = player_x + dx, player_y + dy\n    new_block_x, new_block_y = block_x + dx, block_y + dy\n\n    if 0 &lt;= block_x &lt; GRID_WIDTH and 0 &lt;= block_y &lt; GRID_HEIGHT:\n        if labyrinth[block_y][block_x] == 1:\n            if 0 &lt;= new_block_x &lt; GRID_WIDTH and 0 &lt;= new_block_y &lt; GRID_HEIGHT and labyrinth[new_block_y][new_block_x] == 0:\n                labyrinth[block_y][block_x] = 0\n                labyrinth[new_block_y][new_block_x] = 1\n                push_wall_sound.play()\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 bombs\n    for bomb in bombs:\n        pygame.draw.circle(screen, BLUE, (bomb[0] * GRID_SIZE + GRID_SIZE \/\/ 2, bomb[1] * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 4)\n\n    # Draw score and rank\n    score_text = font.render(f\"Score: {score}\", True, WHITE)\n    screen.blit(score_text, (10, 10))\n\n    rank_text = font.render(f\"Rank: {get_rank()}\", True, WHITE)\n    screen.blit(rank_text, (10, 50))\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, bombs, level\n    player_x = player_y = 1\n    player_direction = 0\n    labyrinth = create_labyrinth()\n    cherries =\n\n place_cherries()\n    enemies = place_enemies()\n    score = 0\n    game_over = False\n    bombs = []\n\n# Initial game setup\nload_scores()\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                if event.key == pygame.K_LEFT:\n                    player_direction = 2\n                elif event.key == pygame.K_RIGHT:\n                    player_direction = 0\n                elif event.key == pygame.K_UP:\n                    player_direction = 3\n                elif event.key == pygame.K_DOWN:\n                    player_direction = 1\n                elif event.key == pygame.K_a:\n                    push_block()\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                            destroy_wall_sound.play()\n                elif event.key == pygame.K_x:\n                    place_bomb()\n\n    if not game_over:\n        # Move player\n        move_player()\n\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_enemy(enemy)\n            enemy[0], enemy[1] = new_pos\n\n        # Check bomb collisions with enemies\n        for enemy in enemies[:]:\n            if (enemy[0], enemy[1]) in bombs:\n                enemies.remove(enemy)\n                bombs.remove((enemy[0], enemy[1]))\n                score += 50\n                kill_enemy_sound.play()\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            player_killed_sound.play()\n            scores.append(score)\n            save_scores()\n\n        # Level up\n        if not cherries:\n            level += 1\n            cherries = place_cherries()\n            enemies = place_enemies()\n            level_complete_sound.play()\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Changes:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Score Saving and Loading<\/strong>: Scores are saved in a JSON file and loaded at the start. The player&#8217;s rank is calculated based on the scores.<\/li>\n\n\n\n<li><strong>Display Ranking<\/strong>: The player&#8217;s rank is displayed next to the score.<\/li>\n\n\n\n<li><strong>Sound Effects<\/strong>: Added sound effects for destroying walls, pushing walls, killing enemies, being killed by enemies, and finishing a level.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Notes:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure you have the sound files (<code>destroy_wall.wav<\/code>, <code>push_wall.wav<\/code>, <code>kill_enemy.wav<\/code>, <code>player_killed.wav<\/code>, and <code>level_complete.wav<\/code>) in a <code>sounds<\/code> directory.<\/li>\n\n\n\n<li>The <code>scores.json<\/code> file is used to store the scores persistently.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to test the game and make further modifications as needed!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To implement the bomb disappearing after 7 seconds and the score diminishing by 1 every 5 seconds, we need to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bomb Timer<\/strong>: Track the time each bomb was placed and remove it after 7 seconds.<\/li>\n\n\n\n<li><strong>Score Timer<\/strong>: Decrease the score by 1 every 5 seconds.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the updated 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 math\nimport os\nimport json\nimport time\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\nlevel = 1\n\n# Bomb variables\nbombs = []\nmax_bombs = 3\nbomb_lifetime = 7  # seconds\n\n# Score decrement timer\nscore_decrement_time = 5  # seconds\nlast_score_decrement = time.time()\n\n# Load sounds\ndestroy_wall_sound = pygame.mixer.Sound('sounds\/destroy_wall.wav')\npush_wall_sound = pygame.mixer.Sound('sounds\/push_wall.wav')\nkill_enemy_sound = pygame.mixer.Sound('sounds\/kill_enemy.wav')\nplayer_killed_sound = pygame.mixer.Sound('sounds\/player_killed.wav')\nlevel_complete_sound = pygame.mixer.Sound('sounds\/level_complete.wav')\n\n# Scores\nscores_file = 'scores.json'\nscores = []\n\ndef load_scores():\n    global scores\n    if os.path.exists(scores_file):\n        with open(scores_file, 'r') as f:\n            scores = json.load(f)\n    else:\n        scores = []\n\ndef save_scores():\n    with open(scores_file, 'w') as f:\n        json.dump(scores, f)\n\ndef get_rank():\n    sorted_scores = sorted(scores, reverse=True)\n    rank = sorted_scores.index(score) + 1 if score in sorted_scores else len(sorted_scores) + 1\n    return rank\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; level + 2:\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 can_chase_player(enemy_x, enemy_y):\n    if enemy_x == player_x:\n        if all(labyrinth[y][enemy_x] == 0 for y in range(min(enemy_y, player_y), max(enemy_y, player_y) + 1)):\n            return True\n    if enemy_y == player_y:\n        if all(labyrinth[enemy_y][x] == 0 for x in range(min(enemy_x, player_x), max(enemy_x, player_x) + 1)):\n            return True\n    return False\n\ndef move_enemy(enemy):\n    if can_chase_player(enemy[0], enemy[1]):\n        return move_towards(enemy, player_x, player_y)\n    else:\n        possible_moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        random.shuffle(possible_moves)\n        for dx, dy in possible_moves:\n            new_x, new_y = enemy[0] + dx, enemy[1] + dy\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                return (new_x, new_y)\n        return (enemy[0], enemy[1])\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 place_bomb():\n    if len(bombs) &lt; max_bombs:\n        bombs.append({'pos': (player_x, player_y), 'time': time.time()})\n\ndef move_player():\n    global player_x, player_y\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    new_x, new_y = player_x + dx, player_y + dy\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\ndef push_block():\n    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n    dx, dy = directions[player_direction]\n    block_x, block_y = player_x + dx, player_y + dy\n    new_block_x, new_block_y = block_x + dx, block_y + dy\n\n    if 0 &lt;= block_x &lt; GRID_WIDTH and 0 &lt;= block_y &lt; GRID_HEIGHT:\n        if labyrinth[block_y][block_x] == 1:\n            if 0 &lt;= new_block_x &lt; GRID_WIDTH and 0 &lt;= new_block_y &lt; GRID_HEIGHT and labyrinth[new_block_y][new_block_x] == 0:\n                labyrinth[block_y][block_x] = 0\n                labyrinth[new_block_y][new_block_x] = 1\n                push_wall_sound.play()\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 bombs\n    for bomb in bombs:\n        pygame.draw.circle(screen, BLUE, (bomb['pos'][0] * GRID_SIZE + GRID_SIZE \/\/ 2, bomb['pos'][1] * GRID_SIZE + GRID_SIZE \/\/ 2), GRID_SIZE \/\/ 4)\n\n    # Draw score and rank\n    score_text = font.render(f\"Score: {score}\", True, WHITE)\n    screen.blit(score_text, (10, 10))\n\n    rank_text = font.render(f\"Rank: {get_rank()}\", True, WHITE)\n    screen.blit(rank_text, (10, 50))\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, bombs, level, last\n\n_score_decrement\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    bombs = []\n    last_score_decrement = time.time()\n\n# Initial game setup\nload_scores()\nreset_game()\n\n# Game loop\nrunning = True\nclock = pygame.time.Clock()\n\nwhile running:\n    current_time = time.time()\n\n    # Check if it's time to decrement the score\n    if current_time - last_score_decrement >= score_decrement_time:\n        if score > 0:\n            score -= 1\n        last_score_decrement = current_time\n\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                if event.key == pygame.K_LEFT:\n                    player_direction = 2\n                elif event.key == pygame.K_RIGHT:\n                    player_direction = 0\n                elif event.key == pygame.K_UP:\n                    player_direction = 3\n                elif event.key == pygame.K_DOWN:\n                    player_direction = 1\n                elif event.key == pygame.K_a:\n                    push_block()\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                            destroy_wall_sound.play()\n                elif event.key == pygame.K_x:\n                    place_bomb()\n\n    if not game_over:\n        # Move player\n        move_player()\n\n        # Move enemies\n        for enemy in enemies:\n            new_pos = move_enemy(enemy)\n            enemy[0], enemy[1] = new_pos\n\n        # Check bomb timers and remove expired bombs\n        bombs = [bomb for bomb in bombs if current_time - bomb['time'] &lt; bomb_lifetime]\n\n        # Check bomb collisions with enemies\n        for enemy in enemies[:]:\n            for bomb in bombs:\n                if (enemy[0], enemy[1]) == bomb['pos']:\n                    enemies.remove(enemy)\n                    bombs.remove(bomb)\n                    score += 50\n                    kill_enemy_sound.play()\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            player_killed_sound.play()\n            scores.append(score)\n            save_scores()\n\n        # Level up\n        if not cherries:\n            level += 1\n            cherries = place_cherries()\n            enemies = place_enemies()\n            level_complete_sound.play()\n\n    draw_game()\n    clock.tick(10)  # Slower speed for grid-based movement\n\npygame.quit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Changes:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bomb Timer<\/strong>: Added a timer to each bomb to track its lifetime and remove it after 7 seconds.<\/li>\n\n\n\n<li><strong>Score Decrement Timer<\/strong>: Added a global timer to decrement the score by 1 every 5 seconds.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Notes:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure you have the sound files (<code>destroy_wall.wav<\/code>, <code>push_wall.wav<\/code>, <code>kill_enemy.wav<\/code>, <code>player_killed.wav<\/code>, and <code>level_complete.wav<\/code>) in a <code>sounds<\/code> directory.<\/li>\n\n\n\n<li>The <code>scores.json<\/code> file is used to store the scores persistently.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to test the game and make further modifications as needed!<\/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":"Part I Prompt move the enemies in some direction randomly and only if there are no walls between the player and the enemy \n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/mr-do-part-ii\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":14004,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-13998","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples"],"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\/13998","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=13998"}],"version-history":[{"count":3,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13998\/revisions"}],"predecessor-version":[{"id":14005,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13998\/revisions\/14005"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/14004"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=13998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=13998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=13998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}