{"id":14294,"date":"2024-08-13T19:01:59","date_gmt":"2024-08-13T17:01:59","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=14294"},"modified":"2024-09-07T13:08:17","modified_gmt":"2024-09-07T11:08:17","slug":"arkanoid-for-pythonista-on-the-ipad","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/arkanoid-for-pythonista-on-the-ipad\/","title":{"rendered":"Arkanoid for Pythonista on the ipad"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A game for the Ipad made with pyhton in the app pythonista.<\/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=\"\">\nNessun elemento selezionato\n\nVai ai contenuti\nUtilizzo di Gmail con gli screen reader\n1 di 55.569\nAria def\nPosta in arrivo\n\nGiovanni Gatto &lt;gatto.gio@gmail.com>\nAllegati\n18:29 (32 minuti fa)\na Giovanni, me\n\n Un allegato\n  \u2022  Scansione eseguita da Gmail\nScrivi:\nNuovo messaggio\nRiduci a iconaSeparaChiudi\nDestinatari\nOggetto\n\nimport scene\nimport sound\nimport random\nimport motion\nimport ui\n\nclass Brick(scene.SpriteNode):\n    def __init__(self, position, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.position = position\n        self.size = (80, 40)\n        self.color = random.choice(['#ff8989', '#88eeac', '#9bd8ff', '#fff1bf', '#ff92ae', '#addfff'])\n\nclass Ball(scene.SpriteNode):\n    def __init__(self, position, velocity, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.position = position\n        self.size = (20, 20)\n        self.color = '#fbffa4'\n        self.velocity = velocity\n        # texture = scene.Texture(ui.Image.named('iob:ios7_circle_outline_24'))\n        # self.texture = texture\n\nclass Arkanoid(scene.Scene):\n    def setup(self):\n        self.background_color = '#000000'\n        motion.start_updates()\n       \n        self.paddle = scene.SpriteNode(color='white')\n        self.paddle.size = (100, 20)\n        self.paddle.position = (self.size.w \/ 2, 50)\n        self.add_child(self.paddle)\n       \n        self.balls = []\n        self.create_ball()\n       \n        self.bricks = []\n        self.create_bricks()\n       \n        self.score = 0\n        self.score_label = scene.LabelNode(f'Score: {self.score}', position=(50, self.size.h - 30))\n        self.add_child(self.score_label)\n       \n        self.level = 1\n        self.level_label = scene.LabelNode(f'Level: {self.level}', position=(self.size.w - 50, self.size.h - 30))\n        self.add_child(self.level_label)\n       \n        self.lives = 3\n        self.lives_label = scene.LabelNode(f'Lives: {self.lives}', position=(self.size.w \/ 2, self.size.h - 30))\n        self.add_child(self.lives_label)\n       \n        self.paddle_speed = 0\n        self.max_speed = 10\n   \n    def create_ball(self):\n        if len(self.balls) &lt; 2:\n            ball = Ball(position=(self.size.w \/ 2, 100), velocity=scene.Point(4, 4))\n            self.add_child(ball)\n            self.balls.append(ball)\n   \n    def create_bricks(self):\n        for brick in self.bricks:\n            brick.remove_from_parent()\n        self.bricks.clear()\n       \n        rows = 5\n        cols = int(self.size.w \/\/ 90)\n        for row in range(rows):\n            for col in range(cols):\n                brick = Brick(position=(col * 90 + 45, self.size.h - (row * 50 + 100)))\n                self.add_child(brick)\n                self.bricks.append(brick)\n   \n    def update(self):\n        tilt = motion.get_gravity()[0]\n        self.paddle_speed = -tilt * self.max_speed*6\n       \n        new_x = self.paddle.position.x + self.paddle_speed\n        new_x = max(self.paddle.size.w \/ 2, min(new_x, self.size.w - self.paddle.size.w \/ 2))\n        self.paddle.position = (new_x, 50)\n       \n        for ball in self.balls[:]:\n            ball.position += ball.velocity\n           \n            if ball.position.x &lt;= 10 or ball.position.x >= self.size.w - 10:\n                ball.velocity.x *= -1\n            if ball.position.y >= self.size.h - 10:\n                ball.velocity.y *= -1\n           \n            if ball.frame.intersects(self.paddle.frame):\n                ball.velocity.y *= -1\n                sound.play_effect('game:Woosh_1')\n           \n            for brick in self.bricks[:]:\n                if ball.frame.intersects(brick.frame):\n                    brick.remove_from_parent()\n                    self.bricks.remove(brick)\n                    ball.velocity.y *= -1\n                    self.score += 10\n                    self.score_label.text = f'Score: {self.score}'\n                    sound.play_effect('game:Ding_3')\n           \n            if ball.position.y &lt;= 0:\n                self.balls.remove(ball)\n                ball.remove_from_parent()\n                if not self.balls:\n                    self.lives -= 1\n                    self.lives_label.text = f'Lives: {self.lives}'\n                    if self.lives > 0:\n                        self.create_ball()\n                    else:\n                        self.game_over()\n       \n        if random.random() &lt; 0.001:  # 0.1% chance each frame to spawn a new ball\n            self.create_ball()\n       \n        if not self.bricks:\n            self.level += 1\n            self.level_label.text = f'Level: {self.level}'\n            self.create_bricks()\n            for ball in self.balls:\n                ball.velocity *= 1.1  # Increase velocity by 10%\n   \n    def game_over(self):\n        self.paused = True\n        game_over_label = scene.LabelNode('Game Over', position=(self.size.w\/2, self.size.h\/2 + 50))\n        self.add_child(game_over_label)\n       \n        restart_button = scene.SpriteNode(color='green')\n        restart_button.size = (100, 50)\n        restart_button.position = (self.size.w\/2, self.size.h\/2 - 50)\n        self.add_child(restart_button)\n       \n        restart_label = scene.LabelNode('Restart', position=restart_button.position)\n        self.add_child(restart_label)\n   \n    def touch_began(self, touch):\n        if self.paused:\n            if touch.location in self.children['SpriteNode'].frame:  # Check if restart button is tapped\n                self.restart_game()\n   \n    def restart_game(self):\n        for child in self.children:\n            child.remove_from_parent()\n        self.setup()\n        self.paused = False\n\nif __name__ == '__main__':\n    scene.run(Arkanoid(), show_fps=False)\narkanoid.py\nVisualizzazione di arkanoid.py.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.tiktok.com\/@johnstarfire\/video\/7402662957332679968?is_from_webapp=1&amp;sender_device=pc\">https:\/\/www.tiktok.com\/@johnstarfire\/video\/7402662957332679968?is_from_webapp=1&amp;sender_device=pc<\/a><\/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\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"A game for the Ipad made with pyhton in the app pythonista. https:\/\/www.tiktok.com\/@johnstarfire\/video\/7402662957332679968?is_from_webapp=1&amp;sender_device=pc\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/arkanoid-for-pythonista-on-the-ipad\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":14229,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-14294","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\/14294","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=14294"}],"version-history":[{"count":2,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/14294\/revisions"}],"predecessor-version":[{"id":14296,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/14294\/revisions\/14296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/14229"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=14294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=14294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=14294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}