{"id":7015,"date":"2020-08-16T19:25:03","date_gmt":"2020-08-16T17:25:03","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=7015"},"modified":"2020-08-16T19:25:30","modified_gmt":"2020-08-16T17:25:30","slug":"space-shooter-by-thecodezine","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/space-shooter-by-thecodezine\/","title":{"rendered":"Space shooter by thecodezine"},"content":{"rendered":"<p>At this link you can find a nice shooter made with pygame<\/p>\n<p><a href=\"https:\/\/thecodezine.com\/easy-learn-python-space-shooter-game-building-using-pygame\/\">click here to go to the page of the game<\/a><\/p>\n<div style=\"width: 640px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-7015-1\" width=\"640\" height=\"800\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/08\/Space-Shooter-2020-08-16-19-06-24.mp4?_=1\" \/><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/08\/Space-Shooter-2020-08-16-19-06-24.mp4\">https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/08\/Space-Shooter-2020-08-16-19-06-24.mp4<\/a><\/video><\/div>\n<p>The code (find the assets on the page)<\/p>\n<pre class=\"lang:default decode:true \">from __future__ import division\r\nimport pygame\r\nimport random\r\nfrom os import path\r\n\r\n## assets folder\r\nimg_dir = path.join(path.dirname(__file__), 'assets')\r\nsound_folder = path.join(path.dirname(__file__), 'sounds')\r\n\r\n###############################\r\n## to be placed in \"constant.py\" later\r\nWIDTH = 480\r\nHEIGHT = 600\r\nFPS = 60\r\nPOWERUP_TIME = 5000\r\nBAR_LENGTH = 100\r\nBAR_HEIGHT = 10\r\n\r\n# Define Colors\r\nWHITE = (255, 255, 255)\r\nBLACK = (0, 0, 0)\r\nRED = (255, 0, 0)\r\nGREEN = (0, 255, 0)\r\nBLUE = (0, 0, 255)\r\nYELLOW = (255, 255, 0)\r\n###############################\r\n\r\n###############################\r\n## to placed in \"__init__.py\" later\r\n## initialize pygame and create window\r\npygame.init()\r\npygame.mixer.init()  # For sound\r\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\r\npygame.display.set_caption(\"Space Shooter\")\r\nclock = pygame.time.Clock()  # For syncing the FPS\r\n###############################\r\n\r\nfont_name = pygame.font.match_font('arial')\r\n\r\n\r\ndef main_menu():\r\n    global screen\r\n\r\n    menu_song = pygame.mixer.music.load(path.join(sound_folder, \"menu.ogg\"))\r\n    pygame.mixer.music.play(-1)\r\n\r\n    title = pygame.image.load(path.join(img_dir, \"main.png\")).convert()\r\n    title = pygame.transform.scale(title, (WIDTH, HEIGHT), screen)\r\n\r\n    screen.blit(title, (0, 0))\r\n    pygame.display.update()\r\n\r\n    while True:\r\n        ev = pygame.event.poll()\r\n        if ev.type == pygame.KEYDOWN:\r\n            if ev.key == pygame.K_RETURN:\r\n                break\r\n            elif ev.key == pygame.K_q:\r\n                pygame.quit()\r\n                quit()\r\n        elif ev.type == pygame.QUIT:\r\n                pygame.quit()\r\n                quit()\r\n        else:\r\n            draw_text(screen, \"Press [ENTER] To Begin\", 30, WIDTH\/2, HEIGHT\/2)\r\n            draw_text(screen, \"or [Q] To Quit\", 30, WIDTH\/2, (HEIGHT\/2)+40)\r\n            pygame.display.update()\r\n\r\n    #pygame.mixer.music.stop()\r\n    ready = pygame.mixer.Sound(path.join(sound_folder, 'getready.ogg'))\r\n    ready.play()\r\n    screen.fill(BLACK)\r\n    draw_text(screen, \"GET READY!\", 40, WIDTH\/2, HEIGHT\/2)\r\n    pygame.display.update()\r\n\r\n\r\ndef draw_text(surf, text, size, x, y):\r\n    ## selecting a cross platform font to display the score\r\n    font = pygame.font.Font(font_name, size)\r\n    # True denotes the font to be anti-aliased\r\n    text_surface = font.render(text, True, WHITE)\r\n    text_rect = text_surface.get_rect()\r\n    text_rect.midtop = (x, y)\r\n    surf.blit(text_surface, text_rect)\r\n\r\n\r\ndef draw_shield_bar(surf, x, y, pct):\r\n    # if pct &lt; 0:\r\n    #     pct = 0\r\n    pct = max(pct, 0)\r\n    ## moving them to top\r\n    # BAR_LENGTH = 100\r\n    # BAR_HEIGHT = 10\r\n    fill = (pct \/ 100) * BAR_LENGTH\r\n    outline_rect = pygame.Rect(x, y, BAR_LENGTH, BAR_HEIGHT)\r\n    fill_rect = pygame.Rect(x, y, fill, BAR_HEIGHT)\r\n    pygame.draw.rect(surf, GREEN, fill_rect)\r\n    pygame.draw.rect(surf, WHITE, outline_rect, 2)\r\n\r\n\r\ndef draw_lives(surf, x, y, lives, img):\r\n    for i in range(lives):\r\n        img_rect = img.get_rect()\r\n        img_rect.x = x + 30 * i\r\n        img_rect.y = y\r\n        surf.blit(img, img_rect)\r\n\r\n\r\ndef newmob():\r\n    mob_element = Mob()\r\n    all_sprites.add(mob_element)\r\n    mobs.add(mob_element)\r\n\r\n\r\nclass Explosion(pygame.sprite.Sprite):\r\n    def __init__(self, center, size):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        self.size = size\r\n        self.image = explosion_anim[self.size][0]\r\n        self.rect = self.image.get_rect()\r\n        self.rect.center = center\r\n        self.frame = 0\r\n        self.last_update = pygame.time.get_ticks()\r\n        self.frame_rate = 75\r\n\r\n    def update(self):\r\n        now = pygame.time.get_ticks()\r\n        if now - self.last_update &gt; self.frame_rate:\r\n            self.last_update = now\r\n            self.frame += 1\r\n            if self.frame == len(explosion_anim[self.size]):\r\n                self.kill()\r\n            else:\r\n                center = self.rect.center\r\n                self.image = explosion_anim[self.size][self.frame]\r\n                self.rect = self.image.get_rect()\r\n                self.rect.center = center\r\n\r\n\r\nclass Player(pygame.sprite.Sprite):\r\n    def __init__(self):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        ## scale the player img down\r\n        self.image = pygame.transform.scale(player_img, (50, 38))\r\n        self.image.set_colorkey(BLACK)\r\n        self.rect = self.image.get_rect()\r\n        self.radius = 20\r\n        self.rect.centerx = WIDTH \/ 2\r\n        self.rect.bottom = HEIGHT - 10\r\n        self.speedx = 0\r\n        self.shield = 100\r\n        self.shoot_delay = 250\r\n        self.last_shot = pygame.time.get_ticks()\r\n        self.lives = 3\r\n        self.hidden = False\r\n        self.hide_timer = pygame.time.get_ticks()\r\n        self.power = 1\r\n        self.power_timer = pygame.time.get_ticks()\r\n\r\n    def update(self):\r\n        ## time out for powerups\r\n        if self.power &gt;= 2 and pygame.time.get_ticks() - self.power_time &gt; POWERUP_TIME:\r\n            self.power -= 1\r\n            self.power_time = pygame.time.get_ticks()\r\n\r\n        ## unhide\r\n        if self.hidden and pygame.time.get_ticks() - self.hide_timer &gt; 1000:\r\n            self.hidden = False\r\n            self.rect.centerx = WIDTH \/ 2\r\n            self.rect.bottom = HEIGHT - 30\r\n\r\n        self.speedx = 0  # makes the player static in the screen by default.\r\n        # then we have to check whether there is an event hanlding being done for the arrow keys being\r\n        ## pressed\r\n\r\n        ## will give back a list of the keys which happen to be pressed down at that moment\r\n        keystate = pygame.key.get_pressed()\r\n        if keystate[pygame.K_LEFT]:\r\n            self.speedx = -5\r\n        elif keystate[pygame.K_RIGHT]:\r\n            self.speedx = 5\r\n\r\n        #Fire weapons by holding spacebar\r\n        if keystate[pygame.K_SPACE]:\r\n            self.shoot()\r\n\r\n        ## check for the borders at the left and right\r\n        if self.rect.right &gt; WIDTH:\r\n            self.rect.right = WIDTH\r\n        if self.rect.left &lt; 0:\r\n            self.rect.left = 0\r\n\r\n        self.rect.x += self.speedx\r\n\r\n    def shoot(self):\r\n        ## to tell the bullet where to spawn\r\n        now = pygame.time.get_ticks()\r\n        if now - self.last_shot &gt; self.shoot_delay:\r\n            self.last_shot = now\r\n            if self.power == 1:\r\n                bullet = Bullet(self.rect.centerx, self.rect.top)\r\n                all_sprites.add(bullet)\r\n                bullets.add(bullet)\r\n                shooting_sound.play()\r\n            if self.power == 2:\r\n                bullet1 = Bullet(self.rect.left, self.rect.centery)\r\n                bullet2 = Bullet(self.rect.right, self.rect.centery)\r\n                all_sprites.add(bullet1)\r\n                all_sprites.add(bullet2)\r\n                bullets.add(bullet1)\r\n                bullets.add(bullet2)\r\n                shooting_sound.play()\r\n\r\n            \"\"\" MOAR POWAH \"\"\"\r\n            if self.power &gt;= 3:\r\n                bullet1 = Bullet(self.rect.left, self.rect.centery)\r\n                bullet2 = Bullet(self.rect.right, self.rect.centery)\r\n                # Missile shoots from center of ship\r\n                missile1 = Missile(self.rect.centerx, self.rect.top)\r\n                all_sprites.add(bullet1)\r\n                all_sprites.add(bullet2)\r\n                all_sprites.add(missile1)\r\n                bullets.add(bullet1)\r\n                bullets.add(bullet2)\r\n                bullets.add(missile1)\r\n                shooting_sound.play()\r\n                missile_sound.play()\r\n\r\n    def powerup(self):\r\n        self.power += 1\r\n        self.power_time = pygame.time.get_ticks()\r\n\r\n    def hide(self):\r\n        self.hidden = True\r\n        self.hide_timer = pygame.time.get_ticks()\r\n        self.rect.center = (WIDTH \/ 2, HEIGHT + 200)\r\n\r\n\r\n# defines the enemies\r\nclass Mob(pygame.sprite.Sprite):\r\n    def __init__(self):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        self.image_orig = random.choice(meteor_images)\r\n        self.image_orig.set_colorkey(BLACK)\r\n        self.image = self.image_orig.copy()\r\n        self.rect = self.image.get_rect()\r\n        self.radius = int(self.rect.width * .90 \/ 2)\r\n        self.rect.x = random.randrange(0, WIDTH - self.rect.width)\r\n        self.rect.y = random.randrange(-150, -100)\r\n        # for randomizing the speed of the Mob\r\n        self.speedy = random.randrange(5, 20)\r\n\r\n        ## randomize the movements a little more\r\n        self.speedx = random.randrange(-3, 3)\r\n\r\n        ## adding rotation to the mob element\r\n        self.rotation = 0\r\n        self.rotation_speed = random.randrange(-8, 8)\r\n        # time when the rotation has to happen\r\n        self.last_update = pygame.time.get_ticks()\r\n\r\n    def rotate(self):\r\n        time_now = pygame.time.get_ticks()\r\n        if time_now - self.last_update &gt; 50:  # in milliseconds\r\n            self.last_update = time_now\r\n            self.rotation = (self.rotation + self.rotation_speed) % 360\r\n            new_image = pygame.transform.rotate(self.image_orig, self.rotation)\r\n            old_center = self.rect.center\r\n            self.image = new_image\r\n            self.rect = self.image.get_rect()\r\n            self.rect.center = old_center\r\n\r\n    def update(self):\r\n        self.rotate()\r\n        self.rect.x += self.speedx\r\n        self.rect.y += self.speedy\r\n        ## now what if the mob element goes out of the screen\r\n\r\n        if (self.rect.top &gt; HEIGHT + 10) or (self.rect.left &lt; -25) or (self.rect.right &gt; WIDTH + 20):\r\n            self.rect.x = random.randrange(0, WIDTH - self.rect.width)\r\n            self.rect.y = random.randrange(-100, -40)\r\n            # for randomizing the speed of the Mob\r\n            self.speedy = random.randrange(1, 8)\r\n\r\n## defines the sprite for Powerups\r\n\r\n\r\nclass Pow(pygame.sprite.Sprite):\r\n    def __init__(self, center):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        self.type = random.choice(['shield', 'gun'])\r\n        self.image = powerup_images[self.type]\r\n        self.image.set_colorkey(BLACK)\r\n        self.rect = self.image.get_rect()\r\n        ## place the bullet according to the current position of the player\r\n        self.rect.center = center\r\n        self.speedy = 2\r\n\r\n    def update(self):\r\n        \"\"\"should spawn right in front of the player\"\"\"\r\n        self.rect.y += self.speedy\r\n        ## kill the sprite after it moves over the top border\r\n        if self.rect.top &gt; HEIGHT:\r\n            self.kill()\r\n\r\n\r\n## defines the sprite for bullets\r\nclass Bullet(pygame.sprite.Sprite):\r\n    def __init__(self, x, y):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        self.image = bullet_img\r\n        self.image.set_colorkey(BLACK)\r\n        self.rect = self.image.get_rect()\r\n        ## place the bullet according to the current position of the player\r\n        self.rect.bottom = y\r\n        self.rect.centerx = x\r\n        self.speedy = -10\r\n\r\n    def update(self):\r\n        \"\"\"should spawn right in front of the player\"\"\"\r\n        self.rect.y += self.speedy\r\n        ## kill the sprite after it moves over the top border\r\n        if self.rect.bottom &lt; 0:\r\n            self.kill()\r\n\r\n        ## now we need a way to shoot\r\n        ## lets bind it to \"spacebar\".\r\n        ## adding an event for it in Game loop\r\n\r\n## FIRE ZE MISSILES\r\n\r\n\r\nclass Missile(pygame.sprite.Sprite):\r\n    def __init__(self, x, y):\r\n        pygame.sprite.Sprite.__init__(self)\r\n        self.image = missile_img\r\n        self.image.set_colorkey(BLACK)\r\n        self.rect = self.image.get_rect()\r\n        self.rect.bottom = y\r\n        self.rect.centerx = x\r\n        self.speedy = -10\r\n\r\n    def update(self):\r\n        \"\"\"should spawn right in front of the player\"\"\"\r\n        self.rect.y += self.speedy\r\n        if self.rect.bottom &lt; 0:\r\n            self.kill()\r\n\r\n\r\n###################################################\r\n## Load all game images\r\n\r\nbackground = pygame.image.load(path.join(img_dir, 'starfield.png')).convert()\r\nbackground_rect = background.get_rect()\r\n## ^^ draw this rect first\r\n\r\nplayer_img = pygame.image.load(\r\n    path.join(img_dir, 'playerShip1_orange.png')).convert()\r\nplayer_mini_img = pygame.transform.scale(player_img, (25, 19))\r\nplayer_mini_img.set_colorkey(BLACK)\r\nbullet_img = pygame.image.load(path.join(img_dir, 'laserRed16.png')).convert()\r\nmissile_img = pygame.image.load(\r\n    path.join(img_dir, 'missile.png')).convert_alpha()\r\n# meteor_img = pygame.image.load(path.join(img_dir, 'meteorBrown_med1.png')).convert()\r\nmeteor_images = []\r\nmeteor_list = [\r\n    'meteorBrown_big1.png',\r\n    'meteorBrown_big2.png',\r\n    'meteorBrown_med1.png',\r\n    'meteorBrown_med3.png',\r\n    'meteorBrown_small1.png',\r\n    'meteorBrown_small2.png',\r\n    'meteorBrown_tiny1.png'\r\n]\r\n\r\nfor image in meteor_list:\r\n    meteor_images.append(pygame.image.load(\r\n        path.join(img_dir, image)).convert())\r\n\r\n## meteor explosion\r\nexplosion_anim = {}\r\nexplosion_anim['lg'] = []\r\nexplosion_anim['sm'] = []\r\nexplosion_anim['player'] = []\r\nfor i in range(9):\r\n    filename = 'regularExplosion0{}.png'.format(i)\r\n    img = pygame.image.load(path.join(img_dir, filename)).convert()\r\n    img.set_colorkey(BLACK)\r\n    ## resize the explosion\r\n    img_lg = pygame.transform.scale(img, (75, 75))\r\n    explosion_anim['lg'].append(img_lg)\r\n    img_sm = pygame.transform.scale(img, (32, 32))\r\n    explosion_anim['sm'].append(img_sm)\r\n\r\n    ## player explosion\r\n    filename = 'sonicExplosion0{}.png'.format(i)\r\n    img = pygame.image.load(path.join(img_dir, filename)).convert()\r\n    img.set_colorkey(BLACK)\r\n    explosion_anim['player'].append(img)\r\n\r\n## load power ups\r\npowerup_images = {}\r\npowerup_images['shield'] = pygame.image.load(\r\n    path.join(img_dir, 'shield_gold.png')).convert()\r\npowerup_images['gun'] = pygame.image.load(\r\n    path.join(img_dir, 'bolt_gold.png')).convert()\r\n\r\n\r\n###################################################\r\n\r\n\r\n###################################################\r\n### Load all game sounds\r\nshooting_sound = pygame.mixer.Sound(path.join(sound_folder, 'pew.wav'))\r\nmissile_sound = pygame.mixer.Sound(path.join(sound_folder, 'rocket.ogg'))\r\nexpl_sounds = []\r\nfor sound in ['expl3.wav', 'expl6.wav']:\r\n    expl_sounds.append(pygame.mixer.Sound(path.join(sound_folder, sound)))\r\n## main background music\r\n#pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg'))\r\npygame.mixer.music.set_volume(0.2)  # simmered the sound down a little\r\n\r\nplayer_die_sound = pygame.mixer.Sound(path.join(sound_folder, 'rumble1.ogg'))\r\n###################################################\r\n\r\n## TODO: make the game music loop over again and again. play(loops=-1) is not working\r\n# Error :\r\n# TypeError: play() takes no keyword arguments\r\n#pygame.mixer.music.play()\r\n\r\n#############################\r\n## Game loop\r\nrunning = True\r\nmenu_display = True\r\nwhile running:\r\n    if menu_display:\r\n        main_menu()\r\n        pygame.time.wait(3000)\r\n\r\n        #Stop menu music\r\n        pygame.mixer.music.stop()\r\n        #Play the gameplay music\r\n        pygame.mixer.music.load(\r\n            path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg'))\r\n        # makes the gameplay sound in an endless loop\r\n        pygame.mixer.music.play(-1)\r\n\r\n        menu_display = False\r\n\r\n        ## group all the sprites together for ease of update\r\n        all_sprites = pygame.sprite.Group()\r\n        player = Player()\r\n        all_sprites.add(player)\r\n\r\n        ## spawn a group of mob\r\n        mobs = pygame.sprite.Group()\r\n        for i in range(8):  # 8 mobs\r\n            # mob_element = Mob()\r\n            # all_sprites.add(mob_element)\r\n            # mobs.add(mob_element)\r\n            newmob()\r\n\r\n        ## group for bullets\r\n        bullets = pygame.sprite.Group()\r\n        powerups = pygame.sprite.Group()\r\n\r\n        #### Score board variable\r\n        score = 0\r\n\r\n    #1 Process input\/events\r\n    clock.tick(FPS)  # will make the loop run at the same speed all the time\r\n    # gets all the events which have occured till now and keeps tab of them.\r\n    for event in pygame.event.get():\r\n        ## listening for the the X button at the top\r\n        if event.type == pygame.QUIT:\r\n            running = False\r\n\r\n        ## Press ESC to exit game\r\n        if event.type == pygame.KEYDOWN:\r\n            if event.key == pygame.K_ESCAPE:\r\n                running = False\r\n        # ## event for shooting the bullets\r\n        # elif event.type == pygame.KEYDOWN:\r\n        #     if event.key == pygame.K_SPACE:\r\n        #         player.shoot()      ## we have to define the shoot()  function\r\n\r\n    #2 Update\r\n    all_sprites.update()\r\n\r\n    ## check if a bullet hit a mob\r\n    ## now we have a group of bullets and a group of mob\r\n    hits = pygame.sprite.groupcollide(mobs, bullets, True, True)\r\n    ## now as we delete the mob element when we hit one with a bullet, we need to respawn them again\r\n    ## as there will be no mob_elements left out\r\n    for hit in hits:\r\n        score += 50 - hit.radius  # give different scores for hitting big and small metoers\r\n        random.choice(expl_sounds).play()\r\n        # m = Mob()\r\n        # all_sprites.add(m)\r\n        # mobs.add(m)\r\n        expl = Explosion(hit.rect.center, 'lg')\r\n        all_sprites.add(expl)\r\n        if random.random() &gt; 0.9:\r\n            pow = Pow(hit.rect.center)\r\n            all_sprites.add(pow)\r\n            powerups.add(pow)\r\n        newmob()  # spawn a new mob\r\n\r\n    ## ^^ the above loop will create the amount of mob objects which were killed spawn again\r\n    #########################\r\n\r\n    ## check if the player collides with the mob\r\n    # gives back a list, True makes the mob element disappear\r\n    hits = pygame.sprite.spritecollide(\r\n        player, mobs, True, pygame.sprite.collide_circle)\r\n    for hit in hits:\r\n        player.shield -= hit.radius * 2\r\n        expl = Explosion(hit.rect.center, 'sm')\r\n        all_sprites.add(expl)\r\n        newmob()\r\n        if player.shield &lt;= 0:\r\n            player_die_sound.play()\r\n            death_explosion = Explosion(player.rect.center, 'player')\r\n            all_sprites.add(death_explosion)\r\n            # running = False     ## GAME OVER 3:D\r\n            player.hide()\r\n            player.lives -= 1\r\n            player.shield = 100\r\n\r\n    ## if the player hit a power up\r\n    hits = pygame.sprite.spritecollide(player, powerups, True)\r\n    for hit in hits:\r\n        if hit.type == 'shield':\r\n            player.shield += random.randrange(10, 30)\r\n            if player.shield &gt;= 100:\r\n                player.shield = 100\r\n        if hit.type == 'gun':\r\n            player.powerup()\r\n\r\n    ## if player died and the explosion has finished, end game\r\n    if player.lives == 0 and not death_explosion.alive():\r\n        running = False\r\n        # menu_display = True\r\n        # pygame.display.update()\r\n\r\n    #3 Draw\/render\r\n    screen.fill(BLACK)\r\n    ## draw the stargaze.png image\r\n    screen.blit(background, background_rect)\r\n\r\n    all_sprites.draw(screen)\r\n    # 10px down from the screen\r\n    draw_text(screen, str(score), 18, WIDTH \/ 2, 10)\r\n    draw_shield_bar(screen, 5, 5, player.shield)\r\n\r\n    # Draw lives\r\n    draw_lives(screen, WIDTH - 100, 5, player.lives, player_mini_img)\r\n\r\n    ## Done after drawing everything to the screen\r\n    pygame.display.flip()\r\n\r\npygame.quit()\r\n<\/pre>\n<!-- 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>\n","protected":false},"excerpt":{"rendered":"Space shooter\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/space-shooter-by-thecodezine\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":7017,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[191],"tags":[194,882],"class_list":["post-7015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pygame","tag-pygame","tag-space-shooter"],"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\/7015","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=7015"}],"version-history":[{"count":2,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/7015\/revisions"}],"predecessor-version":[{"id":7019,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/7015\/revisions\/7019"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/7017"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=7015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=7015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=7015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}