{"id":4101,"date":"2019-11-03T07:31:59","date_gmt":"2019-11-03T06:31:59","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=4101"},"modified":"2020-07-09T17:54:32","modified_gmt":"2020-07-09T15:54:32","slug":"pong-v-1-0-pygame-example","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/pong-v-1-0-pygame-example\/","title":{"rendered":"Pong v. 1.0 &#8211; Pygame example"},"content":{"rendered":"<h2>Pong 2.0<\/h2>\n<p>The new version of Pong now uses classes, instead of functions only and has a new way to update the page.<\/p>\n<p>You will find the old code below. In this version both the bars are controlled by the mouse.<\/p>\n<p>The github <a href=\"https:\/\/github.com\/formazione\/pong\">repository<\/a> for pong.<\/p>\n<p>This code is done after <a href=\"https:\/\/pythonprogramming.altervista.org\/particles-in-arkapygame-v-10-0\/\">ArkaPyGame<\/a> that is also a <a href=\"https:\/\/github.com\/formazione\/arkapygame\">github repo<\/a> and on itch.<\/p>\n<pre class=\"lang:default decode:true \"># pong!\r\nimport pygame, sys\r\nfrom pygame import gfxdraw\r\n\r\nBLACK = (0, 0, 0)\r\nRED = (255, 0, 0)\r\nGREEN = (0, 255, 0)\r\n\r\nscorep1 = 0\r\nscorep2 = 0\r\n\r\nclock = pygame.time.Clock()\r\nscreen = pygame.display.set_mode((500, 500))\r\n\r\npygame.init()\r\n\r\nclass Bar(pygame.sprite.Sprite):\r\n    \"This is the bar class\"\r\n\r\n    def __init__(self, x, y, w=10, h=60):\r\n        super().__init__()\r\n        self.x = x\r\n        self.y = y\r\n        self.w = w\r\n        self.h = h\r\n        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)\r\n\r\n    def update(self):\r\n        self.y = pygame.mouse.get_pos()[1]\r\n        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)\r\n        pygame.draw.rect(screen, RED, self.rect)\r\n\r\n\r\nbar1 = Bar(0, 0)\r\nbar2 = Bar(490, 0)\r\nclass Ball:\r\n    \"Draw the ball\"\r\n\r\n    def __init__(self, x, y):\r\n        self.dirh = 0\r\n        self.dirv = 0\r\n        self.speed = 5\r\n        self.x = x\r\n        self.y = y\r\n        # self.rect = pygame.Rect(self.x, self.y, 10, 10)\r\n\r\n    def update(self):\r\n        \r\n        if self.dirh == 0:\r\n            self.x -= self.speed\r\n        if self.dirv == 0:\r\n            self.y += self.speed\r\n            if self.y &gt; 490:\r\n                self.dirv = 1\r\n        if self.dirv:\r\n            self.y -= self.speed\r\n            if self.y &lt; self.speed:\r\n                self.dirv = 0\r\n        if self.dirh:\r\n            self.x += self.speed\r\n        gfxdraw.filled_circle(screen, self.x, self.y, 5, (0, 255, 0))\r\n        self.rect = pygame.Rect(self.x, self.y, 10, 10)\r\n\r\nball = Ball(480, 20)\r\n\r\n\r\n\r\ndef collision():\r\n    global scorep1, scorep2\r\n\r\n    pygame.display.set_caption(\r\n        f\"Player 1: {scorep1} - Player 2: {scorep2}\")\r\n\r\n    if ball.rect.colliderect(bar2):\r\n        ball.dirh = 0  \r\n    if ball.rect.colliderect(bar1):\r\n        ball.dirh = 1\r\n    if ball.x &gt; 500:\r\n        ball.x, ball.y = 10, 20\r\n    if ball.x &lt; 0:\r\n        gfxdraw.filled_circle(screen, ball.x, ball.y, 5, (0, 0, 0))\r\n        ball.x, ball.y = 480, 20\r\n\r\n\r\npygame.mouse.set_visible(False)\r\npygame.event.set_grab(True)\r\nloop = 1\r\nwhile loop:\r\n    keys = pygame.key.get_pressed()\r\n    for event in pygame.event.get():\r\n        if event.type == pygame.QUIT:\r\n            loop = 0\r\n        if event.type == pygame.KEYDOWN:\r\n            if event.key == pygame.K_ESCAPE:\r\n                loop = 0\r\n    gfxdraw.filled_circle(screen, ball.x, ball.y, 5, (0, 0, 0))\r\n    ball.update()\r\n    pygame.draw.rect(screen, BLACK, bar1.rect)\r\n    bar1.update()\r\n    pygame.draw.rect(screen, BLACK, bar2.rect)\r\n    bar2.update()\r\n    collision()\r\n    pygame.display.update()\r\n    # screen.fill((0, 0, 0))\r\n    clock.tick(60)\r\n\r\npygame.quit()\r\nsys.exit()<\/pre>\n<p>&nbsp;<\/p>\n<p>Pong game has been updated to v. 1.0 with the players to be controlled via keyboard and mouse.<\/p>\n<p>Go here to see the <a href=\"https:\/\/pythonprogramming.altervista.org\/python-and-classic-arcade-games-pong\/\">previous post with this code from skratch<\/a>.<\/p>\n<p>The code is here:<\/p>\n<pre class=\"lang:default decode:true\"># pong!\r\nimport pygame, sys\r\n\r\n\r\nBLACK = (0, 0, 0)\r\nRED = (255, 0, 0)\r\nGREEN = (0, 255, 0)\r\n# Coordinates p1, p2\r\nx1 = (490)\r\ny1 = 250\r\nx2 = (0)\r\ny2 = 250\r\n# coordinates of the ball\r\nxb = 500\r\nyb = 300\r\nspeedball = 5\r\n# horisontal and vertical direction of the ball\r\ndbo = 0 # left\r\ndbv = 0 # down\r\n# Score of player 1 and 2\r\nscorep1 = 0\r\nscorep2 = 0\r\n\r\nclock = pygame.time.Clock()\r\nscreen = pygame.display.set_mode((500, 500))\r\npygame.display.set_caption(\"My game\" + \"Score player 1: \" + str(scorep1) + \" - Score player 2: \" + str(scorep2))\r\n\r\npygame.init()\r\n\r\ndef ball():\r\n\t\"Draw the ball\"\r\n\tglobal xb, yb\r\n\tpygame.draw.ellipse(screen, GREEN, (xb, yb, 10, 10))\r\n\r\ndef sprite1(y): # x and y are the mouse position\r\n\t\"Draw Player 1\"\r\n\tpygame.draw.rect(screen, RED, (x1, y, 10, 50))\r\n\r\ndef sprite2(y):\r\n\t\"Draw Player 2\"\r\n\tpygame.draw.rect(screen, GREEN, (x2, y, 10, 50))\r\n\r\ndef move_ball(x,y):\r\n\t\"The ball moves\"\r\n\tglobal xb, yb, dbo, dbv, speedball\r\n\tif dbo == 0:\r\n\t\txb -= speedball\r\n\tif dbv == 0:\r\n\t\tyb += speedball\r\n\t\tif yb &gt; 490:\r\n\t\t\tdbv = 1\r\n\tif dbv:\r\n\t\tyb -= speedball\r\n\t\tif yb &lt; speedball:\r\n\t\t\tdbv = 0\r\n\tif dbo:\r\n\t\txb += speedball\r\n\t\r\ndef collision():\r\n\tglobal x1, y1 # the player 1 x and y (on the right)\r\n\tglobal x2, y2 # the player 2 x and y (on the left)\r\n\tglobal xb, yb # the ball x and y\r\n\tglobal x, y\r\n\tglobal dbo\r\n\tglobal scorep1, scorep2\r\n\t\r\n\tdef restart():\r\n\t\tglobal xb, yb, scorep1, scorep2\r\n\t\tglobal x, y\r\n\t\tscorep2 += 10\r\n\t\tpygame.display.set_caption(\"My game\" + \"Score player 1: \" + str(scorep1) + \" - Score player 2: \" + str(scorep2))\r\n\t\r\n\tif dbo:\r\n\t\tif xb &gt; 480:\r\n\t\t\tif yb &gt;= y and  yb &lt; y + 50:\r\n\t\t\t\tdbo = 0\t\t\r\n\t\t\telse:\r\n\t\t\t\txb, yb = 10, 20\r\n\t\t\t\tpygame.display.update()\r\n\t\t\t\tpygame.time.delay(500)\r\n\t\t\t\trestart()\r\n\telse:\r\n\t\tif xb &lt; 10:\r\n\t\t\tif yb &gt;= y2 and  yb &lt; y2 + 50:\r\n\t\t\t\tdbo = 1\r\n\t\t\telse:\r\n\t\t\t\txb, yb = 480, 20\r\n\t\t\t\tpygame.display.update()\r\n\t\t\t\tpygame.time.delay(500)\r\n\t\t\t\trestart()\r\n\r\ndef move2():\r\n\tglobal y2\r\n\tif y2 &lt;= 450:\r\n\t\tif keys[pygame.K_z]:\r\n\t\t\ty2 += 20\r\n\tif y2 &gt; 0:\r\n\t\tif keys[pygame.K_a]:\r\n\t\t\ty2 -= 20\r\n\r\npygame.mouse.set_visible(False)\r\nloop = 1\r\nwhile loop:\r\n\tkeys = pygame.key.get_pressed()\r\n\tfor event in pygame.event.get():\r\n\t\tif event.type == pygame.QUIT:\r\n\t\t\tloop = 0\r\n\tx, y = pygame.mouse.get_pos()\r\n\t# move1()\r\n\tmove2()\r\n\tmove_ball(xb, yb)\r\n\tball()\r\n\tsprite1(y)\r\n\tsprite2(y2)\r\n\tcollision()\r\n\tpygame.display.update()\r\n\tscreen.fill((0, 0, 0))\r\n\tclock.tick(60)\r\n\r\npygame.quit()\r\nsys.exit()<\/pre>\n<h2>The changes<\/h2>\n<p>The changes are in the fact that now the player one is controlled by the mouse<\/p>\n<h2>Mouse coordinates<\/h2>\n<p>We get the coordinates of the mouse here:<\/p>\n<pre class=\"lang:default decode:true \">x, y = pygame.mouse.get_pos()<\/pre>\n<p>This is in the while loop.<\/p>\n<p>Then we send the coordinates to the sprite1 function that draws the bar on the screen. We just need the y coordinate, as the bar need to go up and down.<\/p>\n<pre class=\"lang:default decode:true \">\tsprite1(y)<\/pre>\n<p>So, in sprite1 function, now, we just have to pass y and x1 is a global value that stays fixed.<\/p>\n<pre class=\"lang:default decode:true \">def sprite1(y): # x and y are the mouse position\r\n\t\"Draw Player 1\"\r\n\tpygame.draw.rect(screen, RED, (x1, y, 10, 50))<\/pre>\n<h2>Set the mouse invisible<\/h2>\n<p>To hide the mouse, before the while loop, we put this line of code<\/p>\n<pre class=\"lang:default decode:true \">pygame.mouse.set_visible(False)<\/pre>\n<h2>The video of the mouse controlled bar code<\/h2>\n<p>In this video I am trying to add the movement of the mouse to the game, having some issues to make the ball to restart when it went out of the right part of the screen. At the end the only problem is to make the ball bouce in a more interesting way, otherwise the ball is just bouncing in the same clockwise path.<\/p>\n<p><iframe loading=\"lazy\" title=\"Adding mouse movements to Pong v. 1.0 - Pyhon + Pygame\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/cCKxmrRr7xA?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Arkanoid ???<\/h2>\n<p>In the following code (with a video of the output) I made some changes to the code to transform pong into arkanoid. There is still the clockwise path that need to be fixed, in the next post.<\/p>\n<pre class=\"lang:default decode:true \"># pong!\r\nimport pygame\r\nfrom random import choice\r\n\r\nBLACK = (0, 0, 0)\r\nRED = (255, 0, 0)\r\nGREEN = (0, 255, 0)\r\n# Coordinates p1, p2 and ball\r\nx1 = 490\r\ny1 = 490\r\nx2 = 0\r\ny2 = 250\r\nxb = 500\r\nyb = 300\r\n\r\ndbo = 'left'\r\ndbv = 'down'\r\n\r\nscorep1 = 0\r\nscorep2 = 0\r\n\r\nvel_bal = 2\r\n\r\nclock = pygame.time.Clock()\r\nscreen = pygame.display.set_mode((500, 500))\r\npygame.display.set_caption(\"My game\" + \"Score player 1: \" + str(scorep1) + \" - Score player 2: \" + str(scorep2))\r\n\r\npygame.init()\r\n\r\ndef ball():\r\n\t\"Draw the ball\"\r\n\tglobal xb, yb\r\n\tpygame.draw.ellipse(screen, GREEN, (xb, yb, 10, 10))\r\n\r\ndef sprite1(x,y):\r\n\t\"Draw Player 1\"\r\n\tpygame.draw.rect(screen, RED, (x, y, 50, 10))\r\n\r\ndef sprite2(x,y):\r\n\t\"Draw Player 2\"\r\n\tpygame.draw.rect(screen, GREEN, (x, y, 10, 50))\r\n\r\ndef move_ball(x,y):\r\n\t\"The ball moves\"\r\n\tglobal xb, yb, dbo, dbv\r\n\tif dbo == \"left\":\r\n\t\txb -= vel_bal\r\n\t\tif xb &lt; 10:\r\n\t\t\tdbo = \"right\"\r\n\tif dbv == 'down':\r\n\t\tyb += vel_bal\r\n\tif dbv == 'up':\r\n\t\tyb -= vel_bal\r\n\t\tif yb &lt; 10:\r\n\t\t\tdbv = 'down'\r\n\tif dbo == \"right\":\r\n\t\txb += vel_bal\r\n\t\tif xb &gt; 480:\r\n\t\t\tdbo = \"left\"\r\n\t\r\ndef collision():\r\n\tglobal x1, y1 # the player 1 x and y (on the right)\r\n\tglobal x2, y2 # the player 2 x and y (on the left)\r\n\tglobal xb, yb # the ball x and y\r\n\tglobal x, y\r\n\tglobal dbo, dbv, vel_bal\r\n\tglobal scorep1, scorep2\r\n\tif dbo == \"left\":\r\n\t\tif yb &gt; 480:\r\n\t\t\tif xb &gt;= x and  xb &lt; x + 50:\r\n\t\t\t\tprint(\"Collision detected\")\r\n\t\t\t\tdbv = \"up\"\r\n\t\t\t\tvel_bal = choice([1,2,3])\r\n\t\t\t\tprint(dbv)\r\n\t\t\t\tprint(yb)\r\n\t\t\telse:\r\n\t\t\t\tpygame.draw.ellipse(screen, BLACK, (xb, yb, 10, 10))\r\n\t\t\t\tpygame.display.update()\r\n\t\t\t\txb, yb = 500, 300\r\n\t\t\t\t# scorep1 += 10\r\n\t\t\t\tpygame.display.set_caption(\"My game\" + \"Score player 1: \" + str(scorep1) + \" - Score player 2: \" + str(scorep2))\r\n\r\n\r\n\r\ndef move1():\r\n\tglobal y2\r\n\tif y2 &lt;= 450:\r\n\t\tif keys[pygame.K_z]:\r\n\t\t\ty2 += 20\r\n\tif y2 &gt; 0:\r\n\t\tif keys[pygame.K_a]:\r\n\t\t\ty2 -= 20\r\n\r\ndef move2():\r\n\tglobal y1\r\n\tif y1 &lt;= 450:\r\n\t\tif keys[pygame.K_m]:\r\n\t\t\ty1 += 20\r\n\tif y1 &gt; 0:\r\n\t\tif keys[pygame.K_k]:\r\n\t\t\ty1 -= 20\r\npygame.mouse.set_visible(False)\r\nloop = 1\r\nwhile loop:\r\n\tkeys = pygame.key.get_pressed()\r\n\tfor event in pygame.event.get():\r\n\t\tif event.type == pygame.QUIT:\r\n\t\t\tloop = 0\r\n\tx, y = pygame.mouse.get_pos()\r\n\tmove1()\r\n\tmove2()\r\n\tmove_ball(xb, yb)\r\n\tball()\r\n\tsprite1(x,y1)\r\n\tcollision()\r\n\tpygame.display.update()\r\n\tscreen.fill((0, 0, 0))\r\n\tclock.tick(120)\r\n\r\n\r\n\r\npygame.quit()<\/pre>\n<p><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/arkanoid.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4103\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/arkanoid.png\" alt=\"\" width=\"502\" height=\"532\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/arkanoid.png 502w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/arkanoid-320x339.png 320w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/a><\/p>\n<div style=\"width: 747px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4101-1\" width=\"747\" height=\"420\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/output2.mp4?_=1\" \/><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/output2.mp4\">https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/11\/output2.mp4<\/a><\/video><\/div>\n<p>This is a more recent version of Arkanoid made with pygame.<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"HePFI04E08\"><p><a href=\"https:\/\/pythonprogramming.altervista.org\/particles-in-arkapygame-v-10-0\/\">Particles in Arkapygame v. 10.0e<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Particles in Arkapygame v. 10.0e&#8221; &#8212; python programming\" src=\"https:\/\/pythonprogramming.altervista.org\/particles-in-arkapygame-v-10-0\/embed\/#?secret=6bCPtC87f0#?secret=HePFI04E08\" data-secret=\"HePFI04E08\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p><a href=\"https:\/\/pythonprogramming.altervista.org\/particles-in-arkapygame-v-10-0\/\">ArkaPyGame<\/a> , the new version, has a <a href=\"https:\/\/github.com\/formazione\/arkapygame\">github repo<\/a> and it has an <a href=\"https:\/\/formazione.itch.io\/arkapygame\">executable<\/a> on itch.<\/p>\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":"How to move a sprite with the mouse and the other with the keyboard\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/pong-v-1-0-pygame-example\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":4105,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[527,1,154,191,50,263],"tags":[158,229,620,616,194,4,510],"class_list":["post-4101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-animation","category-examples","category-games","category-pygame","category-video","category-videogames","tag-games","tag-mouse","tag-movements","tag-pong","tag-pygame","tag-python","tag-sprite"],"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\/4101","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=4101"}],"version-history":[{"count":5,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4101\/revisions"}],"predecessor-version":[{"id":11824,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4101\/revisions\/11824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/4105"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=4101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=4101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=4101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}